Discussion:
[Xen-changelog] [xen staging] xen/domain: Move guest type checks into the arch_sanitise_domain_config() path
p***@xen.org
2018-11-15 11:33:25 UTC
Permalink
commit 293789bec05f8d943b1c123d662f3b52b213d59f
Author: Andrew Cooper <***@citrix.com>
AuthorDate: Fri Nov 9 18:55:59 2018 +0000
Commit: Andrew Cooper <***@citrix.com>
CommitDate: Thu Nov 15 11:11:30 2018 +0000

xen/domain: Move guest type checks into the arch_sanitise_domain_config() path

This is a more appropriate location for the checks to happen, and cleans up
the common code substantially.

Take the opportunity to make ARM strictly require HVM|HAP for guests, which is
how the toolstack behaves, and leave a dprintk() behind for auditing failures.

Signed-off-by: Andrew Cooper <***@citrix.com>
Acked-by: Julien Grall <***@arm.com>
Reviewed-by: Jan Beulich <***@suse.com>
---
xen/arch/arm/domain.c | 6 ++++++
xen/arch/x86/domain.c | 8 ++++++++
xen/common/domain.c | 34 +++-------------------------------
3 files changed, 17 insertions(+), 31 deletions(-)

diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
index c24ace69d0..71ad1f9653 100644
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -601,6 +601,12 @@ void vcpu_switch_to_aarch64_mode(struct vcpu *v)

int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
{
+ if ( config->flags != (XEN_DOMCTL_CDF_hvm_guest | XEN_DOMCTL_CDF_hap) )
+ {
+ dprintk(XENLOG_INFO, "Unsupported configuration %#x\n", config->flags);
+ return -EINVAL;
+ }
+
/* Fill in the native GIC version, passed back to the toolstack. */
if ( config->arch.gic_version == XEN_DOMCTL_CONFIG_GIC_NATIVE )
{
diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 28a145a300..272fd84a3c 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -420,6 +420,14 @@ void arch_vcpu_destroy(struct vcpu *v)

int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
{
+ bool hvm = config->flags & XEN_DOMCTL_CDF_hvm_guest;
+
+ if ( hvm ? !hvm_enabled : !IS_ENABLED(CONFIG_PV) )
+ {
+ dprintk(XENLOG_INFO, "%s support not available\n", hvm ? "HVM" : "PV");
+ return -EINVAL;
+ }
+
return 0;
}

diff --git a/xen/common/domain.c b/xen/common/domain.c
index ddaf74aaa9..f69f4055cd 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -339,37 +339,9 @@ struct domain *domain_create(domid_t domid,
hardware_domain = d;
}

- /* Sort out our idea of is_{pv,hvm}_domain(). */
- if ( config )
- {
- if ( config->flags & XEN_DOMCTL_CDF_hvm_guest )
- {
-#ifdef CONFIG_HVM
- d->guest_type = guest_type_hvm;
-#else
- err = -EINVAL;
- goto fail;
-#endif
- }
- else
- {
-#ifdef CONFIG_PV
- d->guest_type = guest_type_pv;
-#else
- err = -EINVAL;
- goto fail;
-#endif
- }
- }
- else
- {
- /*
- * At least the idle domain should be treated as PV domain
- * because it uses PV context switch functions. To err on the
- * safe side, leave all system domains to be guest_type_pv.
- */
- d->guest_type = guest_type_pv;
- }
+ /* Sort out our idea of is_{pv,hvm}_domain(). All system domains are PV. */
+ d->guest_type = ((config && (config->flags & XEN_DOMCTL_CDF_hvm_guest))
+ ? guest_type_hvm : guest_type_pv);

TRACE_1D(TRC_DOM0_DOM_ADD, d->domain_id);

--
generated by git-patchbot for /home/xen/git/xen.git#staging

Loading...