]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
xen/arm64: check XSM Magic from the second unknown module.
authorFu Wei <fu.wei@linaro.org>
Tue, 5 Apr 2016 16:46:36 +0000 (00:46 +0800)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Fri, 8 Apr 2016 15:58:51 +0000 (11:58 -0400)
This patch adds a has_xsm_magic helper function for detecting XSM
from the second unknown module.

If Xen can't get the kind of module from compatible, we guess the kind of
these unknowns respectively:
    (1) The first unknown must be kernel.
    (2) Detect the XSM Magic from the 2nd unknown:
        a. If it's XSM, set the kind as XSM, and that also means we
won't load ramdisk;
b. if it's not XSM, set the kind as ramdisk.
So if user want to load ramdisk, it must be the 2nd unknown.
We also detect the XSM Magic for the following unknowns, then set its kind
according to the return value of has_xsm_magic.

By this way, arm64 behavior can be compatible to x86 and can simplify
multi-arch bootloader such as GRUB.

Signed-off-by: Fu Wei <fu.wei@linaro.org>
Acked-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Acked-by: Julien Grall <julien.grall@arm.com>
xen/arch/arm/bootfdt.c
xen/include/xsm/xsm.h
xen/xsm/xsm_core.c
xen/xsm/xsm_policy.c

index 8a1401520f735704b4cc05e370480e97c1420066..d13063371ed149a2954809dc1268c06dfebf2f80 100644 (file)
@@ -14,6 +14,7 @@
 #include <xen/init.h>
 #include <xen/device_tree.h>
 #include <xen/libfdt/libfdt.h>
+#include <xsm/xsm.h>
 #include <asm/setup.h>
 
 static bool_t __init device_tree_node_matches(const void *fdt, int node,
@@ -175,6 +176,17 @@ static void __init process_multiboot_node(const void *fdt, int node,
     const char *cmdline;
     int len;
 
+    prop = fdt_get_property(fdt, node, "reg", &len);
+    if ( !prop )
+        panic("node %s missing `reg' property\n", name);
+
+    if ( len < dt_cells_to_size(address_cells + size_cells) )
+        panic("fdt: node `%s': `reg` property length is too short\n",
+                    name);
+
+    cell = (const __be32 *)prop->data;
+    device_tree_get_reg(&cell, address_cells, size_cells, &start, &size);
+
     if ( fdt_node_check_compatible(fdt, node, "xen,linux-zimage") == 0 ||
          fdt_node_check_compatible(fdt, node, "multiboot,kernel") == 0 )
         kind = BOOTMOD_KERNEL;
@@ -186,7 +198,17 @@ static void __init process_multiboot_node(const void *fdt, int node,
     else
         kind = BOOTMOD_UNKNOWN;
 
-    /* Guess that first two unknown are kernel and ramdisk respectively. */
+    /**
+     * Guess the kind of these first two unknowns respectively:
+     * (1) The first unknown must be kernel.
+     * (2) Detect the XSM Magic from the 2nd unknown:
+     *     a. If it's XSM, set the kind as XSM, and that also means we
+     *     won't load ramdisk;
+     *     b. if it's not XSM, set the kind as ramdisk.
+     *     So if user want to load ramdisk, it must be the 2nd unknown.
+     * We also detect the XSM Magic for the following unknowns,
+     * then set its kind according to the return value of has_xsm_magic.
+     */
     if ( kind == BOOTMOD_UNKNOWN )
     {
         switch ( kind_guess++ )
@@ -195,19 +217,10 @@ static void __init process_multiboot_node(const void *fdt, int node,
         case 1: kind = BOOTMOD_RAMDISK; break;
         default: break;
         }
+       if ( kind_guess > 1 && has_xsm_magic(start) )
+            kind = BOOTMOD_XSM;
     }
 
-    prop = fdt_get_property(fdt, node, "reg", &len);
-    if ( !prop )
-        panic("node %s missing `reg' property\n", name);
-
-    if ( len < dt_cells_to_size(address_cells + size_cells) )
-        panic("fdt: node `%s': `reg` property length is too short\n",
-                    name);
-
-    cell = (const __be32 *)prop->data;
-    device_tree_get_reg(&cell, address_cells, size_cells, &start, &size);
-
     prop = fdt_get_property(fdt, node, "bootargs", &len);
     if ( prop )
     {
index a357a1d4f6937877ebc83c5e3ac015df17442d52..3cfd953e0b8ccf17e47d72177a5181d0b607a49f 100644 (file)
@@ -760,6 +760,7 @@ extern int xsm_multiboot_policy_init(unsigned long *module_map,
 #ifdef CONFIG_HAS_DEVICE_TREE
 extern int xsm_dt_init(void);
 extern int xsm_dt_policy_init(void);
+extern bool has_xsm_magic(paddr_t);
 #endif
 
 extern int register_xsm(struct xsm_operations *ops);
@@ -786,7 +787,12 @@ static inline int xsm_dt_init(void)
 {
     return 0;
 }
-#endif
+
+static inline bool has_xsm_magic(paddr_t start)
+{
+    return false;
+}
+#endif /* CONFIG_HAS_DEVICE_TREE */
 
 #endif /* CONFIG_XSM */
 
index 5e432dee71fc48c8cfa55e1d69aa23c2a71f1641..634ec98d8703d10dc6c13d736eef9c4561d65828 100644 (file)
 
 #ifdef CONFIG_XSM
 
+#ifdef CONFIG_HAS_DEVICE_TREE
+#include <asm/setup.h>
+#endif
+
 #define XSM_FRAMEWORK_VERSION    "1.0.0"
 
 struct xsm_operations *xsm_ops;
@@ -109,6 +113,29 @@ int __init xsm_dt_init(void)
 
     return ret;
 }
+
+/**
+ * has_xsm_magic - Check XSM Magic of the module header by phy address
+ * A XSM module has a special header
+ * ------------------------------------------------
+ * uint magic | uint target_len | uchar target[8] |
+ * 0xf97cff8c |        8        |    "XenFlask"   |
+ * ------------------------------------------------
+ * 0xf97cff8c is policy magic number (XSM_MAGIC).
+ * Here we only check the "magic" of the module.
+ */
+bool __init has_xsm_magic(paddr_t start)
+{
+    xsm_magic_t magic;
+
+    if ( XSM_MAGIC )
+    {
+        copy_from_paddr(&magic, start, sizeof(magic) );
+        return ( magic == XSM_MAGIC );
+    }
+
+    return false;
+}
 #endif
 
 int register_xsm(struct xsm_operations *ops)
index b60d822dabb19993aa6092b180a7e7ea6fcd9b47..bde8015dab036898afdaa5aa582fa75409ff3440 100644 (file)
@@ -79,7 +79,6 @@ int __init xsm_dt_policy_init(void)
 {
     struct bootmodule *mod = boot_module_find_by_kind(BOOTMOD_XSM);
     paddr_t paddr, len;
-    xsm_magic_t magic;
 
     if ( !mod || !mod->size )
         return 0;
@@ -87,12 +86,9 @@ int __init xsm_dt_policy_init(void)
     paddr = mod->start;
     len = mod->size;
 
-    copy_from_paddr(&magic, paddr, sizeof(magic));
-
-    if ( magic != XSM_MAGIC )
+    if ( !has_xsm_magic(paddr) )
     {
-        printk(XENLOG_ERR "xsm: Invalid magic for XSM blob got 0x%x "
-               "expected 0x%x\n", magic, XSM_MAGIC);
+        printk(XENLOG_ERR "xsm: Invalid magic for XSM blob\n");
         return -EINVAL;
     }