Skip to contentSkip to conversation

Fix xen crash when starting HVM guest due to missing io handler

PATCH Superseded [email protected] 3 participants 12 messages May 13, 2016 – May 19, 2016

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Fix xen crash when starting HVM guest due to missing io handler

From: Suravee Suthikulpanit <[email protected]>

Hi All,

On systems with iommu v2 enabled, the hypervisor crashes when trying to start up an HVM guest.

Investigating shows that the guest_iommu_init() is called before the HVM domain is initialized. It then tries to register_mmio_handler() causing the hvm_next_io_handler() to increment the io_handler_count. However, the registration fails silently and left the I/O handler uninitialized.

At later time, hvm_find_io_handler() is called and iterate through the registered handlered, but then resulting in referencing NULL pointers.

This patch series proposes fix for this issue.

NOTE: For patch 2, since guest IOMMU emulation is still incompleted, this change is tentative and will be verified in the future. Alterantively, I can just simply remove the guest_iommu_init()/destroy() for now. I will be also looking at re-enabling this feature in Xen.

Changes from V1:
* Fix upper bound NR_IO_HANDLERS check for in patch 1.

Thanks,
Suravee

Suravee Suthikulpanit (2):
x86/hvm: Add check when register io handler
svm: iommu: Only call guest_iommu_init() after initialized HVM domain

 xen/arch/x86/hvm/intercept.c                |  6 +++++-
 xen/arch/x86/hvm/svm/svm.c                  | 10 ++++++++++
 xen/drivers/passthrough/amd/iommu_guest.c   |  6 ++++++
 xen/drivers/passthrough/amd/pci_amd_iommu.c |  4 ----
 4 files changed, 21 insertions(+), 5 deletions(-)
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#1 lore raw

PATCH v2 1/2 x86/hvm: Add check when register io handler

From: Suravee Suthikulpanit <[email protected]>

At the time of registering HVM I/O handler, the HVM domain might not have been initialized, which means the hvm_domain.io_handler would be NULL. In the hvm_next_io_handler(), this should be checked before returning and referencing the array. Also, the io_handler_count should only be incremented on success.

So, this patch adds error handling in hvm_next_io_handler.

---
 xen/arch/x86/hvm/intercept.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/intercept.c +5 -1
index 7096d74..b837f5f 100644
@@ -248,7 +248,10 @@ int hvm_io_intercept(ioreq_t *p)
 
 struct hvm_io_handler *hvm_next_io_handler(struct domain *d)
 {
-    unsigned int i = d->arch.hvm_domain.io_handler_count++;
+    unsigned int i = d->arch.hvm_domain.io_handler_count;
+
+    if ( !d->arch.hvm_domain.io_handler )
+        return NULL;
 
     if ( i == NR_IO_HANDLERS )
     {
@@ -256,6 +259,7 @@ struct hvm_io_handler *hvm_next_io_handler(struct domain *d)
         return NULL;
     }
 
+    d->arch.hvm_domain.io_handler_count++;
     return &d->arch.hvm_domain.io_handler[i];
 }
 
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#2 lore raw

Re: [PATCH V2 1/2] x86/hvm: Add check when register io handler

Quoted 8 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: 13 May 2016 20:37
To: [email protected]; George Dunlap; [email protected]
Cc: Paul Durrant; Suravee Suthikulpanit; Suravee Suthikulpanit
Subject: [PATCH V2 1/2] x86/hvm: Add check when register io handler

Quoted 4 lines

From: Suravee Suthikulpanit <[email protected]>

At the time of registering HVM I/O handler, the HVM domain might not have been initialized,

I/O handler registration is internal to Xen so any caller that attempt to register before domain initialization should be removed and replaced with one that does it at the right time.

Quoted 7 lines

which means the hvm_domain.io_handler
would be NULL. In the hvm_next_io_handler(), this should be checked before returning and referencing the array. Also, the io_handler_count should only be incremented on success.

So, this patch adds error handling in hvm_next_io_handler.

This isn't necessary. An ASSERT would be preferable so that buggy callers can be easily caught.

Paul

Quoted 31 lines
---
 xen/arch/x86/hvm/intercept.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/intercept.c +5 -2
index 7096d74..b837f5f 100644
@@ -248,7 +248,10 @@ int hvm_io_intercept(ioreq_t *p)
 
 struct hvm_io_handler *hvm_next_io_handler(struct domain *d)
 {
-    unsigned int i = d->arch.hvm_domain.io_handler_count++;
+    unsigned int i = d->arch.hvm_domain.io_handler_count;
+
+    if ( !d->arch.hvm_domain.io_handler )
+        return NULL;
 
     if ( i == NR_IO_HANDLERS )
     {
@@ -256,6 +259,7 @@ struct hvm_io_handler *hvm_next_io_handler(struct
 domain *d)
         return NULL;
     }
 
+    d->arch.hvm_domain.io_handler_count++;
     return &d->arch.hvm_domain.io_handler[i];
 }
 
--
Quoted 1 line

1.9.1

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

#3 lore raw

Re: [PATCH V2 1/2] x86/hvm: Add check when register io handler

Hi Paul,

Quoted 8 lines · Paul Durrant
Quoted 8 lines

-----Original Message-----

Quoted 7 lines

From:[email protected] [mailto:[email protected]]
Sent: 13 May 2016 20:37
To:[email protected]; George Dunlap;[email protected]
Cc: Paul Durrant; Suravee Suthikulpanit; Suravee Suthikulpanit
Subject: [PATCH V2 1/2] x86/hvm: Add check when register io handler

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

From: Suravee Suthikulpanit<[email protected]>

At the time of registering HVM I/O handler, the HVM domain might not have been initialized,

I/O handler registration is internal to Xen so any caller that attempt to register before domain initialization should be removed and replaced with one that does it at the right time.

Ok. I'll just remove that call for now.

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines

which means the hvm_domain.io_handler
would be NULL. In the hvm_next_io_handler(), this should be checked before returning and referencing the array. Also, the io_handler_count should only be incremented on success.

So, this patch adds error handling in hvm_next_io_handler.

This isn't necessary. An ASSERT would be preferable so that buggy callers can be easily caught.

Ok, I'll update the patch to ASSERT() and send it out. Although, just want to make sure that you think it should really be doing assert and not warning + handling error? It seems quite aggressive to crash the hypervisor simply because some io handler are not properly call.

Thanks,
Suravee

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

#4 lore raw

Re: [PATCH V2 1/2] x86/hvm: Add check when register io handler

Quoted 35 lines

-----Original Message-----
From: Suravee Suthikulpanit [mailto:[email protected]]
Sent: 16 May 2016 17:03
To: Paul Durrant; [email protected]; George Dunlap; [email protected]
Subject: Re: [PATCH V2 1/2] x86/hvm: Add check when register io handler

Hi Paul,

Quoted 8 lines · Paul Durrant
Quoted 8 lines

-----Original Message-----

Quoted 7 lines

From:[email protected] [mailto:[email protected]]
Sent: 13 May 2016 20:37
To:[email protected]; George Dunlap;[email protected]
Cc: Paul Durrant; Suravee Suthikulpanit; Suravee Suthikulpanit
Subject: [PATCH V2 1/2] x86/hvm: Add check when register io handler

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

From: Suravee Suthikulpanit<[email protected]>

At the time of registering HVM I/O handler, the HVM domain might not have been initialized,

I/O handler registration is internal to Xen so any caller that attempt to

register before domain initialization should be removed and replaced with one that does it at the right time.

Ok. I'll just remove that call for now.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

which means the hvm_domain.io_handler
would be NULL. In the hvm_next_io_handler(), this should be checked before returning and referencing the array. Also, the io_handler_count should only be incremented on success.

So, this patch adds error handling in hvm_next_io_handler.

Quoted 8 lines
Quoted 1 line

This isn't necessary. An ASSERT would be preferable so that buggy callers

can be easily caught.

Ok, I'll update the patch to ASSERT() and send it out. Although, just want to make sure that you think it should really be doing assert and not warning + handling error? It seems quite aggressive to crash the hypervisor simply because some io handler are not properly call.

That's a reasonable argument, but IMO since all the callers are in the hypervisor and ASSERTs only affect debug builds I think it's reasonable.

Paul

Quoted 2 lines

Thanks,
Suravee

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

#5 lore raw

PATCH v2 2/2 svm: iommu: Only call guest_iommu_init() after initialized HVM domain

In reply to [email protected]

From: Suravee Suthikulpanit <[email protected]>

The guest_iommu_init() is currently called by the following code path:

arch/x86/domain.c: arch_domain_create()
]- drivers/passthrough/iommu.c: iommu_domain_init()
|- drivers/passthrough/amd/pci_amd_iommu.c: amd_iommu_domain_init();
|- drivers/passthrough/amd/iommu_guest.c: guest_iommu_init()

At this point, the hvm_domain_initialised() has not been called. So register_mmio_handler(), in guest_iommu_init(), silently fails. This patch moves the call to guest_iommu_init/destroy() into the svm_domain_intialise/_destroy() instead.

---
 xen/arch/x86/hvm/svm/svm.c                  | 10 ++++++++++
 xen/drivers/passthrough/amd/iommu_guest.c   |  6 ++++++
 xen/drivers/passthrough/amd/pci_amd_iommu.c |  4 ----
 3 files changed, 16 insertions(+), 4 deletions(-)
xen/arch/x86/hvm/svm/svm.c +10 -0
index e62dfa1..0c4affc 100644
@@ -45,6 +45,7 @@
 #include <asm/hvm/support.h>
 #include <asm/hvm/io.h>
 #include <asm/hvm/emulate.h>
+#include <asm/hvm/svm/amd-iommu-proto.h>
 #include <asm/hvm/svm/asid.h>
 #include <asm/hvm/svm/svm.h>
 #include <asm/hvm/svm/vmcb.h>
@@ -1176,11 +1177,20 @@ void svm_host_osvw_init()
 
 static int svm_domain_initialise(struct domain *d)
 {
+    if ( is_hvm_domain(d) )
+        /*
+         * This requires the hvm domain to be
+         * initialized first.
+         */
+        return guest_iommu_init(d);
+
     return 0;
 }
 
 static void svm_domain_destroy(struct domain *d)
 {
+    if ( is_hvm_domain(d) )
+        guest_iommu_destroy(d);
 }
 
 static int svm_vcpu_initialise(struct vcpu *v)
xen/drivers/passthrough/amd/iommu_guest.c +6 -0
index b4e75ac..9f26765 100644
@@ -891,6 +891,12 @@ int guest_iommu_init(struct domain* d)
          !has_viommu(d) )
         return 0;
 
+    if ( d->arch.hvm_domain.io_handler == NULL )
+    {
+        AMD_IOMMU_DEBUG("Error: uninitalized hvm io handler\n");
+        return 1;
+    }
+
     iommu = xzalloc(struct guest_iommu);
     if ( !iommu )
     {
xen/drivers/passthrough/amd/pci_amd_iommu.c +0 -4
index c1c0b6b..f791618 100644
@@ -274,9 +274,6 @@ static int amd_iommu_domain_init(struct domain *d)
     hd->arch.paging_mode = is_hvm_domain(d) ?
                       IOMMU_PAGING_MODE_LEVEL_2 :
                       get_paging_mode(max_page);
-
-    guest_iommu_init(d);
-
     return 0;
 }
 
@@ -476,7 +473,6 @@ static void deallocate_iommu_page_tables(struct domain *d)
 
 static void amd_iommu_domain_destroy(struct domain *d)
 {
-    guest_iommu_destroy(d);
     deallocate_iommu_page_tables(d);
     amd_iommu_flush_all_pages(d);
 }
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#6 lore raw

Re: [PATCH V2 2/2] svm: iommu: Only call guest_iommu_init() after initialized HVM domain

Quoted 19 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: 13 May 2016 20:37
To: [email protected]; George Dunlap; [email protected]
Cc: Paul Durrant; Suravee Suthikulpanit; Suravee Suthikulpanit
Subject: [PATCH V2 2/2] svm: iommu: Only call guest_iommu_init() after initialized HVM domain

From: Suravee Suthikulpanit <[email protected]>

The guest_iommu_init() is currently called by the following code path:

arch/x86/domain.c: arch_domain_create()
]- drivers/passthrough/iommu.c: iommu_domain_init()
|- drivers/passthrough/amd/pci_amd_iommu.c:
amd_iommu_domain_init();
|- drivers/passthrough/amd/iommu_guest.c: guest_iommu_init()

Quoted 5 lines

At this point, the hvm_domain_initialised() has not been called. So register_mmio_handler(), in guest_iommu_init(), silently fails. This patch moves the call to guest_iommu_init/destroy() into the svm_domain_intialise/_destroy() instead.

That seems wrong. You're taking a call that currently comes via a jump table, i.e. an abstraction layer, and calling it directly. Is it possible, instead, to move the call to iommu_domain_init() later in arch_domain_create()? It seems odd, to me at least, that it's done before hvm_domain_initialise() anyway.

Paul

Quoted 81 lines
---
 xen/arch/x86/hvm/svm/svm.c                  | 10 ++++++++++
 xen/drivers/passthrough/amd/iommu_guest.c   |  6 ++++++
 xen/drivers/passthrough/amd/pci_amd_iommu.c |  4 ----
 3 files changed, 16 insertions(+), 4 deletions(-)
xen/arch/x86/hvm/svm/svm.c +10 -0
index e62dfa1..0c4affc 100644
@@ -45,6 +45,7 @@
 #include <asm/hvm/support.h>
 #include <asm/hvm/io.h>
 #include <asm/hvm/emulate.h>
+#include <asm/hvm/svm/amd-iommu-proto.h>
 #include <asm/hvm/svm/asid.h>
 #include <asm/hvm/svm/svm.h>
 #include <asm/hvm/svm/vmcb.h>
@@ -1176,11 +1177,20 @@ void svm_host_osvw_init()
 
 static int svm_domain_initialise(struct domain *d)
 {
+    if ( is_hvm_domain(d) )
+        /*
+         * This requires the hvm domain to be
+         * initialized first.
+         */
+        return guest_iommu_init(d);
+
     return 0;
 }
 
 static void svm_domain_destroy(struct domain *d)
 {
+    if ( is_hvm_domain(d) )
+        guest_iommu_destroy(d);
 }
 
 static int svm_vcpu_initialise(struct vcpu *v)
xen/drivers/passthrough/amd/iommu_guest.c +6 -0
index b4e75ac..9f26765 100644
@@ -891,6 +891,12 @@ int guest_iommu_init(struct domain* d)
          !has_viommu(d) )
         return 0;
 
+    if ( d->arch.hvm_domain.io_handler == NULL )
+    {
+        AMD_IOMMU_DEBUG("Error: uninitalized hvm io handler\n");
+        return 1;
+    }
+
     iommu = xzalloc(struct guest_iommu);
     if ( !iommu )
     {
xen/drivers/passthrough/amd/pci_amd_iommu.c +0 -4
index c1c0b6b..f791618 100644
@@ -274,9 +274,6 @@ static int amd_iommu_domain_init(struct domain *d)
     hd->arch.paging_mode = is_hvm_domain(d) ?
                       IOMMU_PAGING_MODE_LEVEL_2 :
                       get_paging_mode(max_page);
-
-    guest_iommu_init(d);
-
     return 0;
 }
 
@@ -476,7 +473,6 @@ static void deallocate_iommu_page_tables(struct
 domain *d)
 
 static void amd_iommu_domain_destroy(struct domain *d)
 {
-    guest_iommu_destroy(d);
     deallocate_iommu_page_tables(d);
     amd_iommu_flush_all_pages(d);
Quoted 3 lines

}
--
1.9.1

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

#7 lore raw

Re: [PATCH V2 2/2] svm: iommu: Only call guest_iommu_init() after initialized HVM domain

+ Keir (since he added this code originally).

Quoted 19 lines · Paul Durrant
Quoted 19 lines

-----Original Message-----

Quoted 18 lines

From:[email protected] [mailto:[email protected]]
Sent: 13 May 2016 20:37
To:[email protected]; George Dunlap;[email protected]
Cc: Paul Durrant; Suravee Suthikulpanit; Suravee Suthikulpanit
Subject: [PATCH V2 2/2] svm: iommu: Only call guest_iommu_init() after initialized HVM domain

From: Suravee Suthikulpanit<[email protected]>

The guest_iommu_init() is currently called by the following code path:

arch/x86/domain.c: arch_domain_create()
]- drivers/passthrough/iommu.c: iommu_domain_init()
|- drivers/passthrough/amd/pci_amd_iommu.c:
amd_iommu_domain_init();
|- drivers/passthrough/amd/iommu_guest.c: guest_iommu_init()

Quoted 9 lines
Quoted 5 lines
Quoted 5 lines

At this point, the hvm_domain_initialised() has not been called. So register_mmio_handler(), in guest_iommu_init(), silently fails. This patch moves the call to guest_iommu_init/destroy() into the svm_domain_intialise/_destroy() instead.

That seems wrong. You're taking a call that currently comes via a jump table, i.e. an abstraction layer, and calling it directly. Is it possible, instead, to move the call to iommu_domain_init() later in arch_domain_create()? It seems odd, to me at least, that it's done before hvm_domain_initialise() anyway.

Paul

Good point. I think I should be able to move iommu_domain_init() call to go after hvm_domain_initialise() as the following.

xen/arch/x86/domain.c +3 -6
index 9d43f7b..ac289b6 100644
@@ -625,24 +625,21 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
 
         if ( (rc = init_domain_irq_mapping(d)) != 0 )
             goto fail;
-
-        if ( (rc = iommu_domain_init(d)) != 0 )
-            goto fail;
     }
     spin_lock_init(&d->arch.e820_lock);
 
     if ( has_hvm_container_domain(d) )
     {
         if ( (rc = hvm_domain_initialise(d)) != 0 )
-        {
-            iommu_domain_destroy(d);
             goto fail;
-        }
     }
     else
         /* 64-bit PV guest by default. */
         d->arch.is_32bit_pv = d->arch.has_32bit_shinfo = 0;
 
+    if ( !is_idle_domain(d) && (rc = iommu_domain_init(d)) != 0 )
+        goto fail;
+
     if ( (rc = psr_domain_init(d)) != 0 )
         goto fail;
 

-----

This was added in the commit 66a882392272346ce1d0bc5a26568894f450a7c0,
and only says initialization cleanup and bugfix. I am not sure what bug was reported at the time. Anyone has an idea?

Suravee

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

#8 lore raw

Re: [PATCH V2 2/2] svm: iommu: Only call guest_iommu_init() after initialized HVM domain

Quoted 33 lines
Quoted 1 line
Quoted 1 line

Suravee Suthikulpanit <[email protected]> 05/19/16 7:22 AM >>>

Quoted 10 lines · Paul Durrant
Quoted 10 lines

From:[email protected]
Sent: 13 May 2016 20:37

Quoted 8 lines

The guest_iommu_init() is currently called by the following code path:

arch/x86/domain.c: arch_domain_create()
]- drivers/passthrough/iommu.c: iommu_domain_init()
|- drivers/passthrough/amd/pci_amd_iommu.c:
amd_iommu_domain_init();
|- drivers/passthrough/amd/iommu_guest.c: guest_iommu_init()

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

At this point, the hvm_domain_initialised() has not been called. So register_mmio_handler(), in guest_iommu_init(), silently fails. This patch moves the call to guest_iommu_init/destroy() into the svm_domain_intialise/_destroy() instead.

That seems wrong. You're taking a call that currently comes via a jump table, i.e. an abstraction layer, and calling it directly. Is it possible, instead, to move the call to iommu_domain_init() later in arch_domain_create()? It seems odd, to me at least, that it's done before hvm_domain_initialise() anyway.

Good point. I think I should be able to move iommu_domain_init() call to go after hvm_domain_initialise() as the following.

xen/arch/x86/domain.c +0 -3
@@ -625,24 +625,21 @@ int arch_domain_create(struct domain *d, unsigned 
 int domcr_flags,
 
 if ( (rc = init_domain_irq_mapping(d)) != 0 )
 goto fail;
-
-        if ( (rc = iommu_domain_init(d)) != 0 )
-            goto fail;
 }

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned · line 636

Quoted 10 lines
xen/arch/x86/domain.c +0 -3
 spin_lock_init(&d->arch.e820_lock);
 
 if ( has_hvm_container_domain(d) )
 {
 if ( (rc = hvm_domain_initialise(d)) != 0 )
-        {
-            iommu_domain_destroy(d);
 goto fail;
-        }
 }

>else

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags, · line 641

Quoted 5 lines
xen/arch/x86/domain.c +2 -0
 /* 64-bit PV guest by default. */
 d->arch.is_32bit_pv = d->arch.has_32bit_shinfo = 0;
 
+    if ( !is_idle_domain(d) && (rc = iommu_domain_init(d)) != 0 )
+        goto fail;

This would in the error case fail to undo what hvm_domain_initialise() did. There was a fix very recently dealing with a similar issue. There really shouldn't be anything that can fail after hvm_domain_initialise(). And I also can't see why both of you think iommu_domain_init() has to come later - that's a function affecting not just HVM guests.

Jan

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

#9 lore raw

Re: [PATCH V2 2/2] svm: iommu: Only call guest_iommu_init() after initialized HVM domain

Quoted 62 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 19 May 2016 07:04
To: [email protected]; Paul Durrant
Cc: George Dunlap; [email protected]; Keir (Xen.org)
Subject: Re: [PATCH V2 2/2] svm: iommu: Only call guest_iommu_init() after initialized HVM domain

Quoted 1 line
Quoted 1 line
Quoted 1 line

Suravee Suthikulpanit <[email protected]> 05/19/16 7:22

AM >>>

Quoted 5 lines · Paul Durrant
Quoted 4 lines
Quoted 4 lines

From:[email protected]
Sent: 13 May 2016 20:37

Quoted 2 lines

The guest_iommu_init() is currently called by the following code path:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

arch/x86/domain.c: arch_domain_create()
]- drivers/passthrough/iommu.c: iommu_domain_init()
|- drivers/passthrough/amd/pci_amd_iommu.c:
amd_iommu_domain_init();
|- drivers/passthrough/amd/iommu_guest.c: guest_iommu_init()

At this point, the hvm_domain_initialised() has not been called. So register_mmio_handler(), in guest_iommu_init(), silently

fails.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

This patch moves the call to guest_iommu_init/destroy() into the svm_domain_intialise/_destroy() instead.

That seems wrong. You're taking a call that currently comes via a jump

table, i.e. an abstraction layer, and calling it directly. Is it possible, instead, to move the call to iommu_domain_init() later in arch_domain_create()? It seems odd, to me at least, that it's done before hvm_domain_initialise() anyway.

xen/arch/x86/domain.c int arch_domain_create(struct domain *d,

Quoted 7 lines

Good point. I think I should be able to move iommu_domain_init() call to go after hvm_domain_initialise() as the following.

xen/arch/x86/domain.c +0 -0
@@ -625,24 +625,21 @@ int arch_domain_create(struct domain *d,

unsigned

Quoted 8 lines
xen/arch/x86/domain.c +0 -3
 int domcr_flags,
 
 if ( (rc = init_domain_irq_mapping(d)) != 0 )
 goto fail;
-
-        if ( (rc = iommu_domain_init(d)) != 0 )
-            goto fail;
 }

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags, · line 635

Quoted 10 lines
xen/arch/x86/domain.c +0 -3
 spin_lock_init(&d->arch.e820_lock);
 
 if ( has_hvm_container_domain(d) )
 {
 if ( (rc = hvm_domain_initialise(d)) != 0 )
-        {
-            iommu_domain_destroy(d);
 goto fail;
-        }
 }

>else

Quoted 3 lines
xen/arch/x86/domain.c +0 -0
 /* 64-bit PV guest by default. */
 d->arch.is_32bit_pv = d->arch.has_32bit_shinfo = 0;
 
Quoted 6 lines

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags, · line 641

Quoted 2 lines
xen/arch/x86/domain.c +2 -0
+    if ( !is_idle_domain(d) && (rc = iommu_domain_init(d)) != 0 )
+        goto fail;

This would in the error case fail to undo what hvm_domain_initialise() did. There was a fix very recently dealing with a similar issue. There really shouldn't be anything that can fail after hvm_domain_initialise().

Why is that? There are many failure paths within hvm_domain_initialise(). What's wrong with calling hvm_domain_destroy() to undo the whole thing? (Although I do notice that the io_bitmap would appear to leak in that case... but that looks like a bug to me).

Quoted 4 lines

And I also
can't see why both of you think iommu_domain_init() has to come later - that's a function affecting not just HVM guests.

Yes, I realise that. But the problem is that, in the HVM case, it calls functions that make use of infrastructure that's initialized by hvm_domain_initialise().

Paul

Quoted 1 line

Jan

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

#10 lore raw

Re: [PATCH V2 2/2] svm: iommu: Only call guest_iommu_init() after initialized HVM domain

Quoted 30 lines
Quoted 30 lines

xen/arch/x86/domain.c int arch_domain_create(struct domain *d,

Quoted 4 lines · On 19.05.16 at 09:52, <[email protected]> wrote:
xen/arch/x86/domain.c +0 -0
@@ -625,24 +625,21 @@ int arch_domain_create(struct domain *d,

unsigned

Quoted 8 lines
xen/arch/x86/domain.c +0 -3
 int domcr_flags,
 
 if ( (rc = init_domain_irq_mapping(d)) != 0 )
 goto fail;
-
-        if ( (rc = iommu_domain_init(d)) != 0 )
-            goto fail;
 }

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags, · line 635

Quoted 10 lines
xen/arch/x86/domain.c +0 -3
 spin_lock_init(&d->arch.e820_lock);
 
 if ( has_hvm_container_domain(d) )
 {
 if ( (rc = hvm_domain_initialise(d)) != 0 )
-        {
-            iommu_domain_destroy(d);
 goto fail;
-        }
 }

>else

Quoted 5 lines
xen/arch/x86/domain.c +2 -0
 /* 64-bit PV guest by default. */
 d->arch.is_32bit_pv = d->arch.has_32bit_shinfo = 0;
 
+    if ( !is_idle_domain(d) && (rc = iommu_domain_init(d)) != 0 )
+        goto fail;
Quoted 6 lines
Quoted 3 lines

This would in the error case fail to undo what hvm_domain_initialise() did. There was a fix very recently dealing with a similar issue. There really shouldn't be anything that can fail after hvm_domain_initialise().

Why is that? There are many failure paths within hvm_domain_initialise(). What's wrong with calling hvm_domain_destroy() to undo the whole thing?

Well, I simply didn't check whether hvm_domain_destroy() would be suitable to be called in that case, but yes, it looks like it would be.

Quoted 2 lines

(Although I do notice that the io_bitmap would appear to leak in that case... but that looks like a bug to me).

That's a hardware domain only aspect, and failure to construct the hardware domain would be fatal to the system anyway.

Jan

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

#11 lore raw

Re: [PATCH V2 2/2] svm: iommu: Only call guest_iommu_init() after initialized HVM domain

Quoted 50 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 19 May 2016 10:00
To: Paul Durrant
Cc: [email protected]; George Dunlap; xen- [email protected]; Keir (Xen.org)
Subject: RE: [PATCH V2 2/2] svm: iommu: Only call guest_iommu_init() after initialized HVM domain

Quoted 30 lines
Quoted 30 lines

xen/arch/x86/domain.c int arch_domain_create(struct domain *d,

Quoted 4 lines · On 19.05.16 at 09:52, <[email protected]> wrote:
xen/arch/x86/domain.c +0 -0
@@ -625,24 +625,21 @@ int arch_domain_create(struct domain *d,

unsigned

Quoted 8 lines
xen/arch/x86/domain.c +0 -3
 int domcr_flags,
 
 if ( (rc = init_domain_irq_mapping(d)) != 0 )
 goto fail;
-
-        if ( (rc = iommu_domain_init(d)) != 0 )
-            goto fail;
 }

xen/arch/x86/domain.c int arch_domain_create(struct domain *d, unsigned int domcr_flags, · line 635

Quoted 10 lines
xen/arch/x86/domain.c +0 -3
 spin_lock_init(&d->arch.e820_lock);
 
 if ( has_hvm_container_domain(d) )
 {
 if ( (rc = hvm_domain_initialise(d)) != 0 )
-        {
-            iommu_domain_destroy(d);
 goto fail;
-        }
 }

>else

Quoted 5 lines
xen/arch/x86/domain.c +2 -0
 /* 64-bit PV guest by default. */
 d->arch.is_32bit_pv = d->arch.has_32bit_shinfo = 0;
 
+    if ( !is_idle_domain(d) && (rc = iommu_domain_init(d)) != 0 )
+        goto fail;
Quoted 6 lines
Quoted 3 lines

This would in the error case fail to undo what hvm_domain_initialise() did. There was a fix very recently dealing with a similar issue. There really shouldn't be anything that can fail after hvm_domain_initialise().

Why is that? There are many failure paths within hvm_domain_initialise(). What's wrong with calling hvm_domain_destroy() to undo the whole

thing?

Well, I simply didn't check whether hvm_domain_destroy() would be suitable to be called in that case, but yes, it looks like it would be.

Quoted 7 lines
Quoted 1 line

(Although I do notice that the io_bitmap would appear to leak in that

case...

Quoted 1 line

but that looks like a bug to me).

That's a hardware domain only aspect, and failure to construct the hardware domain would be fatal to the system anyway.

Ok. No problem then.

Paul

Quoted 1 line

Jan

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