Skip to contentSkip to conversation

add privileged/unprivileged kernel feature indication

PATCH Superseded Jan Beulich 3 participants 5 messages Jul 19, 2011

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 add privileged/unprivileged kernel feature indication

With our switching away from supporting 32-bit Dom0 operation, users complained that attempts (perhaps due to lack of knowledge of that change) to boot the no longer privileged kernel in Dom0 resulted in apparently silent failure. To make the mismatch explicit and visible, add feature flags that the kernel can set to indicate operation in what modes it supports. For backward compatibility, absence of both feature flags is taken to indicate a kernel that may be capable of operating in both modes.

v2: Due to the way elf_xen_parse_features() worked up to now (getting fixed here), adding features indications to the old, string based ELF note would make the respective kernel unusable on older hypervisors. For that reason, a new ELF Note is being introduced that allows specifying supported features as a bit array instead (with features unknown to the hypervisor simply ignored, as now also done by elf_xen_parse_features(), whereas here unknown kernel-required features still keep the kernel [and hence VM] from booting).

tools/libxc/xc_dom_elfloader.c +9 -0
@@ -286,6 +286,15 @@ static int xc_dom_parse_elf_kernel(struc
     if ( (rc = elf_xen_parse(elf, &dom->parms)) != 0 )
         return rc;
 
+    if ( elf_xen_feature_get(XENFEAT_privileged, dom->parms.f_required) ||
+         (elf_xen_feature_get(XENFEAT_privileged, dom->parms.f_supported) &&
+          !elf_xen_feature_get(XENFEAT_unprivileged, dom->parms.f_supported)) )
+    {
+        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: Kernel does not"
+                     " support unprivileged (DomU) operation", __FUNCTION__);
+        return -EINVAL;
+    }
+
     /* find kernel segment */
     dom->kernel_seg.vstart = dom->parms.virt_kstart;
     dom->kernel_seg.vend   = dom->parms.virt_kend;
xen/arch/ia64/xen/domain.c +8 -0
@@ -2164,6 +2164,14 @@ int __init construct_dom0(struct domain 
 		return -1;
 	}
 
+	if (test_bit(XENFEAT_unprivileged, parms.f_required) ||
+	    (test_bit(XENFEAT_unprivileged, parms.f_supported) &&
+	     !test_bit(XENFEAT_privileged, parms.f_supported)))
+	{
+		printk("Kernel does not support Dom0 operation\n");
+		return -1;
+	}
+
 	p_start = parms.virt_base;
 	pkern_start = parms.virt_kstart;
 	pkern_end = parms.virt_kend;
xen/arch/x86/domain_build.c +8 -0
@@ -415,6 +415,14 @@ int __init construct_dom0(
         return -EINVAL;
     }
 
+    if ( test_bit(XENFEAT_unprivileged, parms.f_required) ||
+         (test_bit(XENFEAT_unprivileged, parms.f_supported) &&
+          !test_bit(XENFEAT_privileged, parms.f_supported)) )
+    {
+        printk("Kernel does not support Dom0 operation\n");
+        return -EINVAL;
+    }
+
 #if defined(__x86_64__)
     if ( compat32 )
     {
xen/common/kernel.c +2 -1
@@ -278,7 +278,8 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDL
         switch ( fi.submap_idx )
         {
         case 0:
-            fi.submap = 0;
+            fi.submap = 1U << (IS_PRIV(current->domain) ?
+                               XENFEAT_privileged : XENFEAT_unprivileged);
             if ( VM_ASSIST(d, VMASST_TYPE_pae_extended_cr3) )
                 fi.submap |= (1U << XENFEAT_pae_pgdir_above_4gb);
             if ( paging_mode_translate(current->domain) )
xen/common/libelf/libelf-dominfo.c +14 -2
@@ -26,7 +26,9 @@ static const char *const elf_xen_feature
     [XENFEAT_writable_descriptor_tables] = "writable_descriptor_tables",
     [XENFEAT_auto_translated_physmap] = "auto_translated_physmap",
     [XENFEAT_supervisor_mode_kernel] = "supervisor_mode_kernel",
-    [XENFEAT_pae_pgdir_above_4gb] = "pae_pgdir_above_4gb"
+    [XENFEAT_pae_pgdir_above_4gb] = "pae_pgdir_above_4gb",
+    [XENFEAT_privileged] = "privileged",
+    [XENFEAT_unprivileged] = "unprivileged"
 };
 static const int elf_xen_features =
 sizeof(elf_xen_feature_names) / sizeof(elf_xen_feature_names[0]);
@@ -83,7 +85,7 @@ int elf_xen_parse_features(const char *f
                 }
             }
         }
-        if ( i == elf_xen_features )
+        if ( i == elf_xen_features && required && feature[0] == '!' )
             return -1;
     }
 
@@ -114,6 +116,7 @@ int elf_xen_parse_note(struct elf_binary
         [XEN_ELFNOTE_LOADER] = { "LOADER", 1},
         [XEN_ELFNOTE_PAE_MODE] = { "PAE_MODE", 1},
         [XEN_ELFNOTE_FEATURES] = { "FEATURES", 1},
+        [XEN_ELFNOTE_SUPPORTED_FEATURES] = { "SUPPORTED_FEATURES", 0},
         [XEN_ELFNOTE_BSD_SYMTAB] = { "BSD_SYMTAB", 1},
         [XEN_ELFNOTE_SUSPEND_CANCEL] = { "SUSPEND_CANCEL", 0 },
         [XEN_ELFNOTE_MOD_START_PFN] = { "MOD_START_PFN", 0 },
@@ -122,6 +125,7 @@ int elf_xen_parse_note(struct elf_binary
 
     const char *str = NULL;
     uint64_t val = 0;
+    unsigned int i;
     int type = elf_uval(elf, note, type);
 
     if ( (type >= sizeof(note_desc) / sizeof(note_desc[0])) ||
@@ -200,6 +204,14 @@ int elf_xen_parse_note(struct elf_binary
             return -1;
         break;
 
+    case XEN_ELFNOTE_SUPPORTED_FEATURES:
+        for ( i = 0; i < XENFEAT_NR_SUBMAPS; ++i )
+        {
+            parms->f_supported[i] |= val;
+            val >>= 32;
+        }
+        break;
+
     }
     return 0;
 }
xen/include/public/elfnote.h +14 -1
@@ -179,9 +179,22 @@
 #define XEN_ELFNOTE_MOD_START_PFN 16
 
 /*
+ * The features supported by this kernel (numeric).
+ *
+ * Other than XEN_ELFNOTE_FEATURES on pre-4.2 Xen, this note allows a
+ * kernel to specify support for features that older hypervisors don't
+ * know about. The set of features 4.2 and newer hypervisors will
+ * consider supported by the kernel is the combination of the sets
+ * specified through this and the string note.
+ *
+ * LEGACY: FEATURES
+ */
+#define XEN_ELFNOTE_SUPPORTED_FEATURES 17
+
+/*
  * The number of the highest elfnote defined.
  */
-#define XEN_ELFNOTE_MAX XEN_ELFNOTE_MOD_START_PFN
+#define XEN_ELFNOTE_MAX XEN_ELFNOTE_SUPPORTED_FEATURES
 
 /*
  * System information exported through crash notes.
xen/include/public/features.h +7 -1
@@ -75,7 +75,13 @@
 #define XENFEAT_hvm_safe_pvclock           9
 
 /* x86: pirq can be used by HVM guests */
-#define XENFEAT_hvm_pirqs           10
+#define XENFEAT_hvm_pirqs                 10
+
+/* privileged operation is supported */
+#define XENFEAT_privileged                11
+
+/* un-privileged operation is supported */
+#define XENFEAT_unprivileged              12
 
 #define XENFEAT_NR_SUBMAPS 1
 

With our switching away from supporting 32-bit Dom0 operation, users complained that attempts (perhaps due to lack of knowledge of that change) to boot the no longer privileged kernel in Dom0 resulted in apparently silent failure. To make the mismatch explicit and visible, add feature flags that the kernel can set to indicate operation in what modes it supports. For backward compatibility, absence of both feature flags is taken to indicate a kernel that may be capable of operating in both modes.

v2: Due to the way elf_xen_parse_features() worked up to now (getting fixed here), adding features indications to the old, string based ELF note would make the respective kernel unusable on older hypervisors. For that reason, a new ELF Note is being introduced that allows specifying supported features as a bit array instead (with features unknown to the hypervisor simply ignored, as now also done by elf_xen_parse_features(), whereas here unknown kernel-required features still keep the kernel [and hence VM] from booting).

tools/libxc/xc_dom_elfloader.c +9 -0
@@ -286,6 +286,15 @@ static int xc_dom_parse_elf_kernel(struc
     if ( (rc = elf_xen_parse(elf, &dom->parms)) != 0 )
         return rc;
 
+    if ( elf_xen_feature_get(XENFEAT_privileged, dom->parms.f_required) ||
+         (elf_xen_feature_get(XENFEAT_privileged, dom->parms.f_supported) &&
+          !elf_xen_feature_get(XENFEAT_unprivileged, dom->parms.f_supported)) )
+    {
+        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: Kernel does not"
+                     " support unprivileged (DomU) operation", __FUNCTION__);
+        return -EINVAL;
+    }
+
     /* find kernel segment */
     dom->kernel_seg.vstart = dom->parms.virt_kstart;
     dom->kernel_seg.vend   = dom->parms.virt_kend;
xen/arch/ia64/xen/domain.c +8 -0
@@ -2164,6 +2164,14 @@ int __init construct_dom0(struct domain 
 		return -1;
 	}
 
+	if (test_bit(XENFEAT_unprivileged, parms.f_required) ||
+	    (test_bit(XENFEAT_unprivileged, parms.f_supported) &&
+	     !test_bit(XENFEAT_privileged, parms.f_supported)))
+	{
+		printk("Kernel does not support Dom0 operation\n");
+		return -1;
+	}
+
 	p_start = parms.virt_base;
 	pkern_start = parms.virt_kstart;
 	pkern_end = parms.virt_kend;
xen/arch/x86/domain_build.c +8 -0
@@ -415,6 +415,14 @@ int __init construct_dom0(
         return -EINVAL;
     }
 
+    if ( test_bit(XENFEAT_unprivileged, parms.f_required) ||
+         (test_bit(XENFEAT_unprivileged, parms.f_supported) &&
+          !test_bit(XENFEAT_privileged, parms.f_supported)) )
+    {
+        printk("Kernel does not support Dom0 operation\n");
+        return -EINVAL;
+    }
+
 #if defined(__x86_64__)
     if ( compat32 )
     {
xen/common/kernel.c +2 -1
@@ -278,7 +278,8 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDL
         switch ( fi.submap_idx )
         {
         case 0:
-            fi.submap = 0;
+            fi.submap = 1U << (IS_PRIV(current->domain) ?
+                               XENFEAT_privileged : XENFEAT_unprivileged);
             if ( VM_ASSIST(d, VMASST_TYPE_pae_extended_cr3) )
                 fi.submap |= (1U << XENFEAT_pae_pgdir_above_4gb);
             if ( paging_mode_translate(current->domain) )
xen/common/libelf/libelf-dominfo.c +14 -2
@@ -26,7 +26,9 @@ static const char *const elf_xen_feature
     [XENFEAT_writable_descriptor_tables] = "writable_descriptor_tables",
     [XENFEAT_auto_translated_physmap] = "auto_translated_physmap",
     [XENFEAT_supervisor_mode_kernel] = "supervisor_mode_kernel",
-    [XENFEAT_pae_pgdir_above_4gb] = "pae_pgdir_above_4gb"
+    [XENFEAT_pae_pgdir_above_4gb] = "pae_pgdir_above_4gb",
+    [XENFEAT_privileged] = "privileged",
+    [XENFEAT_unprivileged] = "unprivileged"
 };
 static const int elf_xen_features =
 sizeof(elf_xen_feature_names) / sizeof(elf_xen_feature_names[0]);
@@ -83,7 +85,7 @@ int elf_xen_parse_features(const char *f
                 }
             }
         }
-        if ( i == elf_xen_features )
+        if ( i == elf_xen_features && required && feature[0] == '!' )
             return -1;
     }
 
@@ -114,6 +116,7 @@ int elf_xen_parse_note(struct elf_binary
         [XEN_ELFNOTE_LOADER] = { "LOADER", 1},
         [XEN_ELFNOTE_PAE_MODE] = { "PAE_MODE", 1},
         [XEN_ELFNOTE_FEATURES] = { "FEATURES", 1},
+        [XEN_ELFNOTE_SUPPORTED_FEATURES] = { "SUPPORTED_FEATURES", 0},
         [XEN_ELFNOTE_BSD_SYMTAB] = { "BSD_SYMTAB", 1},
         [XEN_ELFNOTE_SUSPEND_CANCEL] = { "SUSPEND_CANCEL", 0 },
         [XEN_ELFNOTE_MOD_START_PFN] = { "MOD_START_PFN", 0 },
@@ -122,6 +125,7 @@ int elf_xen_parse_note(struct elf_binary
 
     const char *str = NULL;
     uint64_t val = 0;
+    unsigned int i;
     int type = elf_uval(elf, note, type);
 
     if ( (type >= sizeof(note_desc) / sizeof(note_desc[0])) ||
@@ -200,6 +204,14 @@ int elf_xen_parse_note(struct elf_binary
             return -1;
         break;
 
+    case XEN_ELFNOTE_SUPPORTED_FEATURES:
+        for ( i = 0; i < XENFEAT_NR_SUBMAPS; ++i )
+        {
+            parms->f_supported[i] |= val;
+            val >>= 32;
+        }
+        break;
+
     }
     return 0;
 }
xen/include/public/elfnote.h +14 -1
@@ -179,9 +179,22 @@
 #define XEN_ELFNOTE_MOD_START_PFN 16
 
 /*
+ * The features supported by this kernel (numeric).
+ *
+ * Other than XEN_ELFNOTE_FEATURES on pre-4.2 Xen, this note allows a
+ * kernel to specify support for features that older hypervisors don't
+ * know about. The set of features 4.2 and newer hypervisors will
+ * consider supported by the kernel is the combination of the sets
+ * specified through this and the string note.
+ *
+ * LEGACY: FEATURES
+ */
+#define XEN_ELFNOTE_SUPPORTED_FEATURES 17
+
+/*
  * The number of the highest elfnote defined.
  */
-#define XEN_ELFNOTE_MAX XEN_ELFNOTE_MOD_START_PFN
+#define XEN_ELFNOTE_MAX XEN_ELFNOTE_SUPPORTED_FEATURES
 
 /*
  * System information exported through crash notes.
xen/include/public/features.h +7 -1
@@ -75,7 +75,13 @@
 #define XENFEAT_hvm_safe_pvclock           9
 
 /* x86: pirq can be used by HVM guests */
-#define XENFEAT_hvm_pirqs           10
+#define XENFEAT_hvm_pirqs                 10
+
+/* privileged operation is supported */
+#define XENFEAT_privileged                11
+
+/* un-privileged operation is supported */
+#define XENFEAT_unprivileged              12
 
 #define XENFEAT_NR_SUBMAPS 1
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 9 lines · Jan Beulich

With our switching away from supporting 32-bit Dom0 operation, users complained that attempts (perhaps due to lack of knowledge of that change) to boot the no longer privileged kernel in Dom0 resulted in apparently silent failure. To make the mismatch explicit and visible, add feature flags that the kernel can set to indicate operation in what modes it supports. For backward compatibility, absence of both feature flags is taken to indicate a kernel that may be capable of operating in both modes.

Quoted 3 lines

v2: Due to the way elf_xen_parse_features() worked up to now (getting fixed here), adding features indications to the old, string based ELF note would make the respective kernel unusable on older hypervisors.

What was the failure mode? Can we not fix it (with suitable backport recommendations) rather than adding a new duplicated interface?

Review

Quoted 8 lines

For that reason, a new ELF Note is being introduced that allows specifying supported features as a bit array instead (with features unknown to the hypervisor simply ignored, as now also done by elf_xen_parse_features(), whereas here unknown kernel-required features still keep the kernel [and hence VM] from booting).

(quoted diff) +2 -0
+    case XEN_ELFNOTE_SUPPORTED_FEATURES:
+        for ( i = 0; i < XENFEAT_NR_SUBMAPS; ++i )

There needs to be some negotiation of what the kernel thought XENFEAT_NR_SUBMAPS was or else if/when we have enough features to bump the number we risk running off the end of the array on older kernels.

Review

Quoted 2 lines
(quoted diff) +2 -0
+        {
+            parms->f_supported[i] |= val;

val is a uint64_t so we don't support more than two submaps, which is ok for now but the elf note needs to include a way to grow beyond that in a forward and backward compatible way (lest we grow a third interface for this in the future!).

Notes have a length field and we support 1,2 and 4 byte numerical notes but here I think we need to add support for arbitrary length arrays on numerical values.

xen/include/public/features.h line 84

Quoted 9 lines

/* x86: pirq can be used by HVM guests */

xen/include/public/features.h +7 -1
-#define XENFEAT_hvm_pirqs           10
+#define XENFEAT_hvm_pirqs                 10
+
+/* privileged operation is supported */
+#define XENFEAT_privileged                11
+
+/* un-privileged operation is supported */
+#define XENFEAT_unprivileged              12

This still strikes me as odd because unprivileged is a subset of privileged (I understand the backwards compatibility argument for having it this way though). Really XENFEAT_unprivileged is the "XENFEAT_privileged feature bit is supported" meta-feature flag.

Perhaps this should be a separate elf note? If present then it is 0 or 1 to indicate support for running privileged and if absent we assume it is supported. This would also remove the need for:

xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDL · line 282

Quoted 7 lines
xen/common/kernel.c +2 -1
@@ -278,7 +278,8 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDL
         switch ( fi.submap_idx )
         {
         case 0:
-            fi.submap = 0;
+            fi.submap = 1U << (IS_PRIV(current->domain) ?
+                               XENFEAT_privileged : XENFEAT_unprivileged);

Which information which is already exposed to the guest via start_info.

Do we really mean "privileged" here, or do we mean "dom0", I know the two are tied together today but will this be the case as we disaggregate more and more? Does this flag really mean "can drive APICs and run ACPI code etc"? Which is distinct from the ability to drive hardware generally etc.

Ian.

#2 lore raw
Quoted 11 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 9 lines · Jan Beulich

With our switching away from supporting 32-bit Dom0 operation, users complained that attempts (perhaps due to lack of knowledge of that change) to boot the no longer privileged kernel in Dom0 resulted in apparently silent failure. To make the mismatch explicit and visible, add feature flags that the kernel can set to indicate operation in what modes it supports. For backward compatibility, absence of both feature flags is taken to indicate a kernel that may be capable of operating in both modes.

Quoted 6 lines
Quoted 3 lines

v2: Due to the way elf_xen_parse_features() worked up to now (getting fixed here), adding features indications to the old, string based ELF note would make the respective kernel unusable on older hypervisors.

What was the failure mode? Can we not fix it (with suitable backport recommendations) rather than adding a new duplicated interface?

Adding a supported feature Xen doesn't understand leads to a "cannot load Dom0 kernel" without any indication what was actually wrong with the kernel.

The fix is trivial (this patch's change to elf_xen_parse_features()), but expecting everyone to backport this to (perhaps very) old hypervisors didn't seem realistic to me.

Quoted 6 lines
Quoted 5 lines

For that reason, a new ELF Note is being introduced that allows specifying supported features as a bit array instead (with features unknown to the hypervisor simply ignored, as now also done by elf_xen_parse_features(), whereas here unknown kernel-required features still keep the kernel [and hence VM] from booting).

Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+    case XEN_ELFNOTE_SUPPORTED_FEATURES:
+        for ( i = 0; i < XENFEAT_NR_SUBMAPS; ++i )

There needs to be some negotiation of what the kernel thought XENFEAT_NR_SUBMAPS was or else if/when we have enough features to bump the number we risk running off the end of the array on older kernels.

No. The kernel simply specifies what it's (approximate) notion through the note's data size. Xen just reads as much as it understands (and ignores, as written in the description) the rest.

Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+        {
+            parms->f_supported[i] |= val;

val is a uint64_t so we don't support more than two submaps, which is ok for now but the elf note needs to include a way to grow beyond that in a forward and backward compatible way (lest we grow a third interface for this in the future!).

Hmm, indeed - we'd have to improve elf_note_numeric() to be forward compatible.

Quoted 3 lines

Notes have a length field and we support 1,2 and 4 byte numerical notes but here I think we need to add support for arbitrary length arrays on numerical values.

Easiest would seem to be to have the caller (optionally) specify a unit size and index. What do you think?

Quoted 6 lines
Quoted 6 lines

/* x86: pirq can be used by HVM guests */

xen/include/public/features.h +4 -1
-#define XENFEAT_hvm_pirqs           10
+#define XENFEAT_hvm_pirqs                 10
+
+/* privileged operation is supported */
+#define XENFEAT_privileged                11
Quoted 8 lines

xen/include/public/features.h line 84

Quoted 3 lines
xen/include/public/features.h +3 -0
+
+/* un-privileged operation is supported */
+#define XENFEAT_unprivileged              12

This still strikes me as odd because unprivileged is a subset of privileged (I understand the backwards compatibility argument for having it this way though). Really XENFEAT_unprivileged is the "XENFEAT_privileged feature bit is supported" meta-feature flag.

No, I don't view it that way - in the Linux ports, the meaning of the respective config options is such that privileged includes unprivileged, but that's a guest OS decision, not one the interface should dictate.

The only implication done here is that the (otherwise meaningless) absence of both flags gets taken as if both flags were set.

Quoted 4 lines

Perhaps this should be a separate elf note? If present then it is 0 or 1 to indicate support for running privileged and if absent we assume it is supported. This would also remove the need for:

Quoted 9 lines

xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDL · line 282

Quoted 7 lines
xen/common/kernel.c +2 -1
@@ -278,7 +278,8 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDL
         switch ( fi.submap_idx )
         {
         case 0:
-            fi.submap = 0;
+            fi.submap = 1U << (IS_PRIV(current->domain) ?
+                               XENFEAT_privileged : XENFEAT_unprivileged);

Which information which is already exposed to the guest via start_info.

Yeah, I just wanted this for completeness. If it's deemed bad to do so, it could simply be dropped.

Quoted 5 lines

Do we really mean "privileged" here, or do we mean "dom0", I know the two are tied together today but will this be the case as we disaggregate more and more? Does this flag really mean "can drive APICs and run ACPI code etc"? Which is distinct from the ability to drive hardware generally etc.

No, this is really only meaningful as a Dom0-capability indication in today's sense. Splitting this will probably yield the whole privileged/ unprivileged distinction bogus, and hence kernels supporting this would probably be required to just always set both flags.

If the feature naming is a problem, we could certainly rename them into "dom0" and "domU", to distinguish the two ways of getting loaded.

Jan

#3 lore raw
Quoted 18 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 9 lines · Jan Beulich

With our switching away from supporting 32-bit Dom0 operation, users complained that attempts (perhaps due to lack of knowledge of that change) to boot the no longer privileged kernel in Dom0 resulted in apparently silent failure. To make the mismatch explicit and visible, add feature flags that the kernel can set to indicate operation in what modes it supports. For backward compatibility, absence of both feature flags is taken to indicate a kernel that may be capable of operating in both modes.

Quoted 6 lines
Quoted 3 lines

v2: Due to the way elf_xen_parse_features() worked up to now (getting fixed here), adding features indications to the old, string based ELF note would make the respective kernel unusable on older hypervisors.

What was the failure mode? Can we not fix it (with suitable backport recommendations) rather than adding a new duplicated interface?

Quoted 7 lines

Adding a supported feature Xen doesn't understand leads to a "cannot load Dom0 kernel" without any indication what was actually wrong with the kernel.

The fix is trivial (this patch's change to elf_xen_parse_features()), but expecting everyone to backport this to (perhaps very) old hypervisors didn't seem realistic to me.

Backporting a trivial fix like this is pretty easy, especially to this code which has been reasonably static for a long time.

People who need this fix are either building a modern kernel themselves (in which case I expect they can cope with getting a fixed hypervisor too) or they are getting it from their distro and then the packages dependencies will cause the necessary hypervisor fix to get pulled in.

Quoted 11 lines
Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+        {
+            parms->f_supported[i] |= val;

val is a uint64_t so we don't support more than two submaps, which is ok for now but the elf note needs to include a way to grow beyond that in a forward and backward compatible way (lest we grow a third interface for this in the future!).

Hmm, indeed - we'd have to improve elf_note_numeric() to be forward compatible.

Quoted 6 lines
Quoted 3 lines

Notes have a length field and we support 1,2 and 4 byte numerical notes but here I think we need to add support for arbitrary length arrays on numerical values.

Easiest would seem to be to have the caller (optionally) specify a unit size and index. What do you think?

something like

	for (idx = 0; idx<note.len/sizeof(uint32_t); idx++)
		val = elf_note_numeric(sizeof(uint32_t), idx);
                ...use val...

???

I was thinking of making the "int str" in note_desc be an enum with "u32_array" (or whatever) as a new value (allowing for others in the future) but what you suggest works too.

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines

/* x86: pirq can be used by HVM guests */

xen/include/public/features.h +4 -1
-#define XENFEAT_hvm_pirqs           10
+#define XENFEAT_hvm_pirqs                 10
+
+/* privileged operation is supported */
+#define XENFEAT_privileged                11
Quoted 8 lines

xen/include/public/features.h line 84

Quoted 3 lines
xen/include/public/features.h +3 -0
+
+/* un-privileged operation is supported */
+#define XENFEAT_unprivileged              12

This still strikes me as odd because unprivileged is a subset of privileged (I understand the backwards compatibility argument for having it this way though). Really XENFEAT_unprivileged is the "XENFEAT_privileged feature bit is supported" meta-feature flag.

Quoted 4 lines

No, I don't view it that way - in the Linux ports, the meaning of the respective config options is such that privileged includes unprivileged, but that's a guest OS decision, not one the interface should dictate.

Hmm, I suppose. I'm not sure it would be possible to implement a guest which was able to run as a dom0 but didn't by necessity also implement enough stuff to work as a domU (at least not far enough to print something useful).

Which reminds me -- when you boot a non-dom0 (but domU) capable kernel as dom0 does it not get far enough to print something to its console? IOW could we avoid this whole mess by "fixing" it in the guest?

Ian.

Quoted 16 lines
Quoted 5 lines

Do we really mean "privileged" here, or do we mean "dom0", I know the two are tied together today but will this be the case as we disaggregate more and more? Does this flag really mean "can drive APICs and run ACPI code etc"? Which is distinct from the ability to drive hardware generally etc.

No, this is really only meaningful as a Dom0-capability indication in today's sense. Splitting this will probably yield the whole privileged/ unprivileged distinction bogus, and hence kernels supporting this would probably be required to just always set both flags.

If the feature naming is a problem, we could certainly rename them into "dom0" and "domU", to distinguish the two ways of getting loaded.

Jan

#4 lore raw
Quoted 28 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 18 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 9 lines · Jan Beulich

With our switching away from supporting 32-bit Dom0 operation, users complained that attempts (perhaps due to lack of knowledge of that change) to boot the no longer privileged kernel in Dom0 resulted in apparently silent failure. To make the mismatch explicit and visible, add feature flags that the kernel can set to indicate operation in what modes it supports. For backward compatibility, absence of both feature flags is taken to indicate a kernel that may be capable of operating in both modes.

Quoted 6 lines
Quoted 3 lines

v2: Due to the way elf_xen_parse_features() worked up to now (getting fixed here), adding features indications to the old, string based ELF note would make the respective kernel unusable on older hypervisors.

What was the failure mode? Can we not fix it (with suitable backport recommendations) rather than adding a new duplicated interface?

Quoted 7 lines

Adding a supported feature Xen doesn't understand leads to a "cannot load Dom0 kernel" without any indication what was actually wrong with the kernel.

The fix is trivial (this patch's change to elf_xen_parse_features()), but expecting everyone to backport this to (perhaps very) old hypervisors didn't seem realistic to me.

Quoted 7 lines

Backporting a trivial fix like this is pretty easy, especially to this code which has been reasonably static for a long time.

People who need this fix are either building a modern kernel themselves (in which case I expect they can cope with getting a fixed hypervisor too) or they are getting it from their distro and then the packages dependencies will cause the necessary hypervisor fix to get pulled in.

Not really. Just consider virtualization hosters who run on a very old hypervisor, but offer people to use modern kernels. You just can't imply that a modern kernel will only run on half-way modern hypervisors, or that if you have control over the (DomU) kernel, you also have control over the hypervisor.

Quoted 20 lines
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines

/* x86: pirq can be used by HVM guests */

xen/include/public/features.h +4 -1
-#define XENFEAT_hvm_pirqs           10
+#define XENFEAT_hvm_pirqs                 10
+
+/* privileged operation is supported */
+#define XENFEAT_privileged                11
Quoted 8 lines

xen/include/public/features.h line 84

Quoted 3 lines
xen/include/public/features.h +3 -0
+
+/* un-privileged operation is supported */
+#define XENFEAT_unprivileged              12

This still strikes me as odd because unprivileged is a subset of privileged (I understand the backwards compatibility argument for having it this way though). Really XENFEAT_unprivileged is the "XENFEAT_privileged feature bit is supported" meta-feature flag.

Quoted 4 lines

No, I don't view it that way - in the Linux ports, the meaning of the respective config options is such that privileged includes unprivileged, but that's a guest OS decision, not one the interface should dictate.

Quoted 8 lines

Hmm, I suppose. I'm not sure it would be possible to implement a guest which was able to run as a dom0 but didn't by necessity also implement enough stuff to work as a domU (at least not far enough to print something useful).

Which reminds me -- when you boot a non-dom0 (but domU) capable kernel as dom0 does it not get far enough to print something to its console? IOW could we avoid this whole mess by "fixing" it in the guest?

Without "earlyprintk=xen" it likely won't get far enough. And earlyprintk=xen really makes no sense on a DomU-only kernel, so could even be unavailable. Further the guest likely wouldn't know of a VGA or VESA fb (again because of being DomU-only), and hence it may not have a usable console interface at all when booted as Dom0.

Jan