Skip to contentSkip to conversation

x86/hvm: short-circuit HVM shadow guest creation earlier

PATCH In review Roger Pau Monne 3 participants 7 messages Feb 9 – Feb 10

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hvm: short-circuit HVM shadow guest creation earlier

If shadow paging has been compiled out short circuit the creation of HVM guests that attempt to use shadow paging at arch_sanitise_domain_config(). There's no need to further build the domain when creation is doomed to fail later on.

---
 xen/arch/x86/domain.c | 6 ++++++
 1 file changed, 6 insertions(+)
xen/arch/x86/domain.c +6 -0
index 8b2f33f1a06c..8eb1509782ef 100644
@@ -627,6 +627,12 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
         return -EINVAL;
     }
 
+    if ( hvm && !hap && !IS_ENABLED(CONFIG_SHADOW_PAGING) )
+    {
+        dprintk(XENLOG_INFO, "Shadow paging requested but not available\n");
+        return -EINVAL;
+    }
+
     if ( !hvm )
         /*
          * It is only meaningful for XEN_DOMCTL_CDF_oos_off to be clear
Signature · 1 line
2.51.0
#2 lore raw
In reply to Roger Pau Monne
Quoted 15 lines · Roger Pau Monne

If shadow paging has been compiled out short circuit the creation of HVM guests that attempt to use shadow paging at arch_sanitise_domain_config(). There's no need to further build the domain when creation is doomed to fail later on.

---
 xen/arch/x86/domain.c | 6 ++++++
 1 file changed, 6 insertions(+)
xen/arch/x86/domain.c +0 -0
index 8b2f33f1a06c..8eb1509782ef 100644

xen/arch/x86/domain.c int arch_sanitise_domain_config(struct xen_domctl_createdomain *config) · line 632

Quoted 6 lines
xen/arch/x86/domain.c +3 -0
@@ -627,6 +627,12 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
         return -EINVAL;
     }
 
+    if ( hvm && !hap && !IS_ENABLED(CONFIG_SHADOW_PAGING) )
+    {
+        dprintk(XENLOG_INFO, "Shadow paging requested but not available\n");

nit: s/requested/required/, maybe?

Also, with this in place can't we get rid of the panic in create_dom0() that checks an identical condition?

Cheers,
Alejandro

#3 lore raw
Quoted 19 lines · Alejandro Vallejo
Quoted 18 lines · Roger Pau Monne

If shadow paging has been compiled out short circuit the creation of HVM guests that attempt to use shadow paging at arch_sanitise_domain_config(). There's no need to further build the domain when creation is doomed to fail later on.

---
 xen/arch/x86/domain.c | 6 ++++++
 1 file changed, 6 insertions(+)
xen/arch/x86/domain.c +0 -0
index 8b2f33f1a06c..8eb1509782ef 100644
@@ -627,6 +627,12 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
         return -EINVAL;
     }
 
Quoted 5 lines

xen/arch/x86/domain.c int arch_sanitise_domain_config(struct xen_domctl_createdomain *config) · line 632

Quoted 3 lines
xen/arch/x86/domain.c +3 -0
+    if ( hvm && !hap && !IS_ENABLED(CONFIG_SHADOW_PAGING) )
+    {
+        dprintk(XENLOG_INFO, "Shadow paging requested but not available\n");

nit: s/requested/required/, maybe?

The wording matches the rest of the messages in arch_sanitise_domain_config(). I'm not saying that makes it correct, but if we word this differently we should also change the others IMO.

Quoted 2 lines

Also, with this in place can't we get rid of the panic in create_dom0() that checks an identical condition?

Hm, I would possibly leave that one, as I think it's clearer for the dom0 case. Otherwise someone using a build without HAP or shadow and attempting to boot in PVH mode will get a message saying: "Shadow paging requested but not available", which is IMO less clear than getting a "Neither HAP nor Shadow available for PVH domain" error message.

Just my thinking, both checks achieve the same result, but the error message in the create_dom0() instance is more helpful in the context of dom0 creation.

Thanks, Roger.

#4 lore raw
Quoted 26 lines · Roger Pau Monné
Quoted 19 lines · Alejandro Vallejo
Quoted 18 lines · Roger Pau Monne

If shadow paging has been compiled out short circuit the creation of HVM guests that attempt to use shadow paging at arch_sanitise_domain_config(). There's no need to further build the domain when creation is doomed to fail later on.

---
 xen/arch/x86/domain.c | 6 ++++++
 1 file changed, 6 insertions(+)
xen/arch/x86/domain.c +0 -0
index 8b2f33f1a06c..8eb1509782ef 100644
@@ -627,6 +627,12 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
         return -EINVAL;
     }
 
Quoted 5 lines

xen/arch/x86/domain.c int arch_sanitise_domain_config(struct xen_domctl_createdomain *config) · line 632

Quoted 3 lines
xen/arch/x86/domain.c +3 -0
+    if ( hvm && !hap && !IS_ENABLED(CONFIG_SHADOW_PAGING) )
+    {
+        dprintk(XENLOG_INFO, "Shadow paging requested but not available\n");

nit: s/requested/required/, maybe?

Quoted 4 lines

The wording matches the rest of the messages in arch_sanitise_domain_config(). I'm not saying that makes it correct, but if we word this differently we should also change the others IMO.

+1

Quoted 10 lines
Quoted 2 lines

Also, with this in place can't we get rid of the panic in create_dom0() that checks an identical condition?

Hm, I would possibly leave that one, as I think it's clearer for the dom0 case. Otherwise someone using a build without HAP or shadow and attempting to boot in PVH mode will get a message saying: "Shadow paging requested but not available", which is IMO less clear than getting a "Neither HAP nor Shadow available for PVH domain" error message.

Quoted 3 lines

Just my thinking, both checks achieve the same result, but the error message in the create_dom0() instance is more helpful in the context of dom0 creation.

+1

Jan

Reviewed-by
#5 lore raw
In reply to Roger Pau Monné
Quoted 26 lines · Roger Pau Monné
Quoted 19 lines · Alejandro Vallejo
Quoted 18 lines · Roger Pau Monne

If shadow paging has been compiled out short circuit the creation of HVM guests that attempt to use shadow paging at arch_sanitise_domain_config(). There's no need to further build the domain when creation is doomed to fail later on.

---
 xen/arch/x86/domain.c | 6 ++++++
 1 file changed, 6 insertions(+)
xen/arch/x86/domain.c +0 -0
index 8b2f33f1a06c..8eb1509782ef 100644
@@ -627,6 +627,12 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
         return -EINVAL;
     }
 
Quoted 5 lines

xen/arch/x86/domain.c int arch_sanitise_domain_config(struct xen_domctl_createdomain *config) · line 632

Quoted 3 lines
xen/arch/x86/domain.c +3 -0
+    if ( hvm && !hap && !IS_ENABLED(CONFIG_SHADOW_PAGING) )
+    {
+        dprintk(XENLOG_INFO, "Shadow paging requested but not available\n");

nit: s/requested/required/, maybe?

Quoted 4 lines

The wording matches the rest of the messages in arch_sanitise_domain_config(). I'm not saying that makes it correct, but if we word this differently we should also change the others IMO.

My point is rather that HAP, or relaxed MSRs, or other settings are actively requested via createdomain flags. Shadow is instead the consequence of not setting HAP. You don't request shadow, you either requested something else or you hit the error.

It's not terrible wording, just imprecise.

Quoted 10 lines
Quoted 2 lines

Also, with this in place can't we get rid of the panic in create_dom0() that checks an identical condition?

Hm, I would possibly leave that one, as I think it's clearer for the dom0 case. Otherwise someone using a build without HAP or shadow and attempting to boot in PVH mode will get a message saying: "Shadow paging requested but not available", which is IMO less clear than getting a "Neither HAP nor Shadow available for PVH domain" error message.

Quoted 3 lines

Just my thinking, both checks achieve the same result, but the error message in the create_dom0() instance is more helpful in the context of dom0 creation.

Fair enough. It doesn't matter much anyway. With or without the adjusted printk.

Cheers,
Alejandro

#6 lore raw
Quoted 32 lines · Alejandro Vallejo
Quoted 26 lines · Roger Pau Monné
Quoted 19 lines · Alejandro Vallejo
Quoted 18 lines · Roger Pau Monne

If shadow paging has been compiled out short circuit the creation of HVM guests that attempt to use shadow paging at arch_sanitise_domain_config(). There's no need to further build the domain when creation is doomed to fail later on.

---
 xen/arch/x86/domain.c | 6 ++++++
 1 file changed, 6 insertions(+)
xen/arch/x86/domain.c +0 -0
index 8b2f33f1a06c..8eb1509782ef 100644
@@ -627,6 +627,12 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
         return -EINVAL;
     }
 
Quoted 5 lines

xen/arch/x86/domain.c int arch_sanitise_domain_config(struct xen_domctl_createdomain *config) · line 632

Quoted 3 lines
xen/arch/x86/domain.c +3 -0
+    if ( hvm && !hap && !IS_ENABLED(CONFIG_SHADOW_PAGING) )
+    {
+        dprintk(XENLOG_INFO, "Shadow paging requested but not available\n");

nit: s/requested/required/, maybe?

Quoted 4 lines

The wording matches the rest of the messages in arch_sanitise_domain_config(). I'm not saying that makes it correct, but if we word this differently we should also change the others IMO.

Quoted 6 lines

My point is rather that HAP, or relaxed MSRs, or other settings are actively requested via createdomain flags. Shadow is instead the consequence of not setting HAP. You don't request shadow, you either requested something else or you hit the error.

It's not terrible wording, just imprecise.

Hm, I see. I've always considered not requesting HAP equivalent to requesting shadow. IOW: not setting XEN_DOMCTL_CDF_hap doesn't mean "pick any possible option" but rather it's an explicit request to use shadow paging on HVM.

The interface would possibly be cleaner if we had both a HAP and Shadow flags, and lack of any being selected could mean for Xen to pick the default one.

Thanks, Roger.