WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] allow configuration of limit on machine addresses gi

To: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>, Keir Fraser <Keir.Fraser@xxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH] allow configuration of limit on machine addresses given to a particular guest
From: Ian Campbell <Ian.Campbell@xxxxxxxxxx>
Date: Fri, 11 Jul 2008 12:09:43 +0100
Cc:
Delivery-date: Fri, 11 Jul 2008 04:12:54 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Organization: Citrix Systems, Inc.
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1215774669 -3600
# Node ID c2d11eade2a22c03c21d7555d3e390cddfcc2f4e
# Parent  10afe06cee7d8fb7756144ca8a7c0b8d0ef63955
[PATCH] x86: allow control domain to limit machine addresses given to a 
particular guest

This allows domains which make buggy assumptions about the maximum
possible MFN to be worked around.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r 10afe06cee7d -r c2d11eade2a2 tools/libxc/xc_domain.c
--- a/tools/libxc/xc_domain.c   Fri Jul 11 12:02:14 2008 +0100
+++ b/tools/libxc/xc_domain.c   Fri Jul 11 12:11:09 2008 +0100
@@ -993,6 +993,35 @@
     return do_domctl(xc_handle, &domctl);
 }
 
+int xc_domain_set_machine_address_size(int xc,
+                                       uint32_t domid,
+                                       unsigned int width)
+{
+    DECLARE_DOMCTL;
+
+    memset(&domctl, 0, sizeof(domctl));
+    domctl.domain = domid;
+    domctl.cmd    = XEN_DOMCTL_set_machine_address_size;
+    domctl.u.address_size.size = width;
+
+    return do_domctl(xc, &domctl);
+}
+
+
+int xc_domain_get_machine_address_size(int xc, uint32_t domid)
+{
+    DECLARE_DOMCTL;
+    int rc;
+
+    memset(&domctl, 0, sizeof(domctl));
+    domctl.domain = domid;
+    domctl.cmd    = XEN_DOMCTL_get_machine_address_size;
+
+    rc = do_domctl(xc, &domctl);
+
+    return rc == 0 ? domctl.u.address_size.size : rc;
+}
+
 /*
  * Local variables:
  * mode: C
diff -r 10afe06cee7d -r c2d11eade2a2 tools/libxc/xenctrl.h
--- a/tools/libxc/xenctrl.h     Fri Jul 11 12:02:14 2008 +0100
+++ b/tools/libxc/xenctrl.h     Fri Jul 11 12:11:09 2008 +0100
@@ -1076,6 +1076,12 @@
                               uint32_t domid,
                               uint8_t machine_irq);
 
+int xc_domain_set_machine_address_size(int handle,
+                                      uint32_t domid,
+                                      unsigned int width);
+int xc_domain_get_machine_address_size(int handle,
+                                      uint32_t domid);
+
 /* Set the target domain */
 int xc_domain_set_target(int xc_handle,
                          uint32_t domid,
diff -r 10afe06cee7d -r c2d11eade2a2 tools/python/xen/lowlevel/xc/xc.c
--- a/tools/python/xen/lowlevel/xc/xc.c Fri Jul 11 12:02:14 2008 +0100
+++ b/tools/python/xen/lowlevel/xc/xc.c Fri Jul 11 12:11:09 2008 +0100
@@ -841,6 +841,22 @@
         return pyxc_error_to_exception();
 
     return pyxc_create_cpuid_dict(regs_transform);
+}
+
+static PyObject *pyxc_dom_set_machine_address_size(XcObject *self,
+                                                  PyObject *args,
+                                                  PyObject *kwds)
+{
+    uint32_t dom, width;
+
+    if (!PyArg_ParseTuple(args, "ii", &dom, &width))
+       return NULL;
+
+    if (xc_domain_set_machine_address_size(self->xc_handle, dom, width) != 0)
+       return pyxc_error_to_exception();
+
+    Py_INCREF(zero);
+    return zero;
 }
 
 #endif /* __i386__ || __x86_64__ */
@@ -1889,6 +1905,13 @@
       "Set the default cpuid policy for a domain.\n"
       " dom [int]: Identifier of domain.\n\n"
       "Returns: [int] 0 on success; exception on error.\n" },
+
+    { "domain_set_machine_address_size",
+      (PyCFunction)pyxc_dom_set_machine_address_size,
+      METH_VARARGS, "\n"
+      "Set maximum machine address size for this domain.\n"
+      " dom [int]: Identifier of domain.\n"
+      " width [int]: Maximum machine address width.\n" },
 #endif
 
     { NULL, NULL, 0, NULL }
diff -r 10afe06cee7d -r c2d11eade2a2 tools/python/xen/xend/XendConfig.py
--- a/tools/python/xen/xend/XendConfig.py       Fri Jul 11 12:02:14 2008 +0100
+++ b/tools/python/xen/xend/XendConfig.py       Fri Jul 11 12:11:09 2008 +0100
@@ -207,6 +207,7 @@
     'pci': str,
     'cpuid' : dict,
     'cpuid_check' : dict,
+    'machine_address_size': int,
 }
 
 # List of legacy configuration keys that have no equivalent in the
diff -r 10afe06cee7d -r c2d11eade2a2 tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   Fri Jul 11 12:02:14 2008 +0100
+++ b/tools/python/xen/xend/XendDomainInfo.py   Fri Jul 11 12:11:09 2008 +0100
@@ -2223,6 +2223,11 @@
             shadow_cur = xc.shadow_mem_control(self.domid, shadow / 1024)
             self.info['shadow_memory'] = shadow_cur
 
+            # machine address size
+            if self.info.has_key('machine_address_size'):
+                log.debug("_initDomain: setting maximum machine address size 
%d" % self.info['machine_address_size'])
+                xc.domain_set_machine_address_size(self.domid, 
self.info['machine_address_size'])
+                
             self._createChannels()
 
             channel_details = self.image.createImage()
diff -r 10afe06cee7d -r c2d11eade2a2 tools/python/xen/xm/create.py
--- a/tools/python/xen/xm/create.py     Fri Jul 11 12:02:14 2008 +0100
+++ b/tools/python/xen/xm/create.py     Fri Jul 11 12:11:09 2008 +0100
@@ -563,6 +563,10 @@
           fn=append_value, default=[],
           use="""Cpuid check description.""")
 
+gopts.var('machine_address_size', val='BITS',
+          fn=set_int, default=None,
+          use="""Maximum machine address size""")
+
 def err(msg):
     """Print an error to stderr and exit.
     """
@@ -610,6 +614,9 @@
 
     if vals.vhpt != 0:
         config_image.append(['vhpt', vals.vhpt])
+
+    if vals.machine_address_size:
+        config_image.append(['machine_address_size', 
vals.machine_address_size])
 
     return config_image
     
@@ -863,7 +870,7 @@
                    'restart', 'on_poweroff',
                    'on_reboot', 'on_crash', 'vcpus', 'vcpu_avail', 'features',
                    'on_xend_start', 'on_xend_stop', 'target', 'cpuid',
-                   'cpuid_check'])
+                   'cpuid_check', 'machine_address_size'])
 
     if vals.uuid is not None:
         config.append(['uuid', vals.uuid])
diff -r 10afe06cee7d -r c2d11eade2a2 xen/arch/x86/domctl.c
--- a/xen/arch/x86/domctl.c     Fri Jul 11 12:02:14 2008 +0100
+++ b/xen/arch/x86/domctl.c     Fri Jul 11 12:11:09 2008 +0100
@@ -487,6 +487,57 @@
 
         if ( copy_to_guest(u_domctl, domctl, 1) )
             ret = -EFAULT;
+    }
+    break;
+
+    case XEN_DOMCTL_set_machine_address_size:
+    {
+        struct domain *d;
+
+        ret = -ESRCH;
+        if ( (d = rcu_lock_domain_by_id(domctl->domain)) == NULL )
+            break;
+
+        ret = xsm_machine_address_size(d, domctl->cmd);
+        if ( ret )
+            rcu_unlock_domain(d);
+
+        ret = -EBUSY;
+        if ( d->tot_pages > 0 )
+            goto set_machine_address_size_out;
+
+        d->arch.physaddr_bitsize = domctl->u.address_size.size;
+
+        ret = 0;
+    set_machine_address_size_out:
+        rcu_unlock_domain(d);
+    }
+    break;
+
+    case XEN_DOMCTL_get_machine_address_size:
+    {
+        struct domain *d;
+
+        ret = -ESRCH;
+        if ( (d = rcu_lock_domain_by_id(domctl->domain)) == NULL )
+            break;
+
+        ret = xsm_machine_address_size(d, domctl->cmd);
+        if ( ret )
+        {
+            rcu_unlock_domain(d);
+            break;
+        }
+
+        domctl->u.address_size.size = d->arch.physaddr_bitsize;
+
+        ret = 0;
+        rcu_unlock_domain(d);
+
+        if ( copy_to_guest(u_domctl, domctl, 1) )
+            ret = -EFAULT;
+
+
     }
     break;
 
diff -r 10afe06cee7d -r c2d11eade2a2 xen/arch/x86/x86_64/mm.c
--- a/xen/arch/x86/x86_64/mm.c  Fri Jul 11 12:02:14 2008 +0100
+++ b/xen/arch/x86/x86_64/mm.c  Fri Jul 11 12:11:09 2008 +0100
@@ -475,7 +475,8 @@
 void domain_set_alloc_bitsize(struct domain *d)
 {
     if ( !is_pv_32on64_domain(d) ||
-         (MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page) )
+         (MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page) ||
+         d->arch.physaddr_bitsize > 0 )
         return;
     d->arch.physaddr_bitsize =
         /* 2^n entries can be contained in guest's p2m mapping space */
diff -r 10afe06cee7d -r c2d11eade2a2 xen/include/public/domctl.h
--- a/xen/include/public/domctl.h       Fri Jul 11 12:02:14 2008 +0100
+++ b/xen/include/public/domctl.h       Fri Jul 11 12:11:09 2008 +0100
@@ -607,6 +607,14 @@
 typedef struct xen_domctl_subscribe xen_domctl_subscribe_t;
 DEFINE_XEN_GUEST_HANDLE(xen_domctl_subscribe_t);
 
+/*
+ * Define the maximum machine address size which should be allocated
+ * to a guest.
+ */
+#define XEN_DOMCTL_set_machine_address_size  51
+#define XEN_DOMCTL_get_machine_address_size  52
+
+
 struct xen_domctl {
     uint32_t cmd;
     uint32_t interface_version; /* XEN_DOMCTL_INTERFACE_VERSION */
diff -r 10afe06cee7d -r c2d11eade2a2 xen/include/xsm/xsm.h
--- a/xen/include/xsm/xsm.h     Fri Jul 11 12:02:14 2008 +0100
+++ b/xen/include/xsm/xsm.h     Fri Jul 11 12:11:09 2008 +0100
@@ -119,6 +119,7 @@
     int (*hypercall_init) (struct domain *d);
     int (*hvmcontext) (struct domain *d, uint32_t op);
     int (*address_size) (struct domain *d, uint32_t op);
+    int (*machine_address_size) (struct domain *d, uint32_t op);
     int (*hvm_param) (struct domain *d, unsigned long op);
     int (*hvm_set_pci_intx_level) (struct domain *d);
     int (*hvm_set_isa_irq_level) (struct domain *d);
@@ -448,6 +449,11 @@
     return xsm_call(address_size(d, cmd));
 }
 
+static inline int xsm_machine_address_size (struct domain *d, uint32_t cmd)
+{
+    return xsm_call(machine_address_size(d, cmd));
+}
+
 static inline int xsm_hvm_param (struct domain *d, unsigned long op)
 {
     return xsm_call(hvm_param(d, op));
diff -r 10afe06cee7d -r c2d11eade2a2 xen/xsm/dummy.c
--- a/xen/xsm/dummy.c   Fri Jul 11 12:02:14 2008 +0100
+++ b/xen/xsm/dummy.c   Fri Jul 11 12:11:09 2008 +0100
@@ -467,6 +467,7 @@
     set_to_dummy_if_null(ops, hypercall_init);
     set_to_dummy_if_null(ops, hvmcontext);
     set_to_dummy_if_null(ops, address_size);
+    set_to_dummy_if_null(ops, machine_address_size);
     set_to_dummy_if_null(ops, hvm_param);
     set_to_dummy_if_null(ops, hvm_set_pci_intx_level);
     set_to_dummy_if_null(ops, hvm_set_isa_irq_level);



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] allow configuration of limit on machine addresses given to a particular guest, Ian Campbell <=