Skip to contentSkip to conversation

x86/hvm: ioreq server fixes

PATCH In review Paul Durrant 3 participants 7 messages Apr 23, 2015 – Apr 24, 2015

lore
Share & tools
lore
#0 lore raw

cover x86/hvm: ioreq server fixes

The following two patches fix a bug in the ioreq server gmfn release code and also make the semantics of server destruction more intuitive.

#1 lore raw

PATCH 1/2 x86/hvm: actually release ioreq server pages

hvm_free_ioreq_gmfn has the sense of the ioreq_gmfn mask inverted; it needs to set a bit to release the gmfn, not clear it.

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/hvm.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/hvm/hvm.c +1 -1
index bfde380..f840175 100644
@@ -496,7 +496,7 @@ static void hvm_free_ioreq_gmfn(struct domain *d, unsigned long gmfn)
 {
     unsigned int i = gmfn - d->arch.hvm_domain.ioreq_gmfn.base;
 
-    clear_bit(i, &d->arch.hvm_domain.ioreq_gmfn.mask);
+    set_bit(i, &d->arch.hvm_domain.ioreq_gmfn.mask);
 }
 
 static void hvm_unmap_ioreq_page(struct hvm_ioreq_server *s, bool_t buf)
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH 2/2 x86/hvm: implicitly disable an ioreq server when it is destroyed

In reply to Paul Durrant

Currently, unless a (non-default) ioreq server is explicitly disabled before being destroyed, its gmfns will not be placed back into the p2m but still released back into the ioreq_gmfn mask. This is somewhat counter-intuitive and easily remedied by this small patch.

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/hvm.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/hvm.c +5 -3
index f840175..3c62b80 100644
@@ -972,6 +972,7 @@ static int hvm_ioreq_server_init(struct hvm_ioreq_server *s, struct domain *d,
 static void hvm_ioreq_server_deinit(struct hvm_ioreq_server *s,
                                     bool_t is_default)
 {
+    ASSERT(!s->enabled);
     hvm_ioreq_server_remove_all_vcpus(s);
     hvm_ioreq_server_unmap_pages(s, is_default);
     hvm_ioreq_server_free_rangesets(s, is_default);
@@ -1074,6 +1075,8 @@ static int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id)
 
         domain_pause(d);
 
+        hvm_ioreq_server_disable(s, 0);
+
         list_del(&s->list_entry);
         
         hvm_ioreq_server_deinit(s, 0);
@@ -1332,11 +1335,10 @@ static void hvm_destroy_all_ioreq_servers(struct domain *d)
     {
         bool_t is_default = (s == d->arch.hvm_domain.default_ioreq_server);
 
+        hvm_ioreq_server_disable(s, is_default);
+
         if ( is_default )
-        {
-            hvm_ioreq_server_disable(s, 1);
             d->arch.hvm_domain.default_ioreq_server = NULL;
-        }
 
         list_del(&s->list_entry);
         
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [PATCH 1/2] x86/hvm: actually release ioreq server pages

In reply to Paul Durrant
Quoted 7 lines · Paul Durrant

hvm_free_ioreq_gmfn has the sense of the ioreq_gmfn mask inverted; it needs to set a bit to release the gmfn, not clear it.

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>

s/mask/free_mask/ ?

For the change itself, Reviewed-by: Andrew Cooper
<[email protected]>

Quoted 17 lines
---
 xen/arch/x86/hvm/hvm.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/hvm/hvm.c +1 -1
index bfde380..f840175 100644
@@ -496,7 +496,7 @@ static void hvm_free_ioreq_gmfn(struct domain *d, unsigned long gmfn)
 {
     unsigned int i = gmfn - d->arch.hvm_domain.ioreq_gmfn.base;
 
-    clear_bit(i, &d->arch.hvm_domain.ioreq_gmfn.mask);
+    set_bit(i, &d->arch.hvm_domain.ioreq_gmfn.mask);
 }
 
 static void hvm_unmap_ioreq_page(struct hvm_ioreq_server *s, bool_t buf)
Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] x86/hvm: implicitly disable an ioreq server when it is destroyed

In reply to Paul Durrant
Quoted 9 lines · Paul Durrant

Currently, unless a (non-default) ioreq server is explicitly disabled before being destroyed, its gmfns will not be placed back into the p2m but still released back into the ioreq_gmfn mask. This is somewhat counter-intuitive and easily remedied by this small patch.

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
Quoted 39 lines
---
 xen/arch/x86/hvm/hvm.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/hvm.c +5 -3
index f840175..3c62b80 100644
@@ -972,6 +972,7 @@ static int hvm_ioreq_server_init(struct hvm_ioreq_server *s, struct domain *d,
 static void hvm_ioreq_server_deinit(struct hvm_ioreq_server *s,
                                     bool_t is_default)
 {
+    ASSERT(!s->enabled);
     hvm_ioreq_server_remove_all_vcpus(s);
     hvm_ioreq_server_unmap_pages(s, is_default);
     hvm_ioreq_server_free_rangesets(s, is_default);
@@ -1074,6 +1075,8 @@ static int hvm_destroy_ioreq_server(struct domain *d, ioservid_t id)
 
         domain_pause(d);
 
+        hvm_ioreq_server_disable(s, 0);
+
         list_del(&s->list_entry);
 
         hvm_ioreq_server_deinit(s, 0);
@@ -1332,11 +1335,10 @@ static void hvm_destroy_all_ioreq_servers(struct domain *d)
     {
         bool_t is_default = (s == d->arch.hvm_domain.default_ioreq_server);
 
+        hvm_ioreq_server_disable(s, is_default);
+
         if ( is_default )
-        {
-            hvm_ioreq_server_disable(s, 1);
             d->arch.hvm_domain.default_ioreq_server = NULL;
-        }
 
         list_del(&s->list_entry);
 
#3 lore raw

Re: [PATCH 1/2] x86/hvm: actually release ioreq server pages

In reply to Paul Durrant

xen/arch/x86/hvm/hvm.c static void hvm_free_ioreq_gmfn(struct domain *d, unsigned long gmfn) · line 500

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 23.04.15 at 17:46, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +1 -1
@@ -496,7 +496,7 @@ static void hvm_free_ioreq_gmfn(struct domain *d, unsigned long gmfn)
 {
     unsigned int i = gmfn - d->arch.hvm_domain.ioreq_gmfn.base;
 
-    clear_bit(i, &d->arch.hvm_domain.ioreq_gmfn.mask);
+    set_bit(i, &d->arch.hvm_domain.ioreq_gmfn.mask);
 }

Double checking this I came to wonder whether HVM_PARAM_NR_IOREQ_SERVER_PAGES handling isn't broken when invoked a second time with a.value smaller than what was used the first time, or when any server pages are already in use.

Jan

#4 lore raw

Re: [PATCH 1/2] x86/hvm: actually release ioreq server pages

Quoted 19 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 24 April 2015 09:01
To: Paul Durrant
Cc: Andrew Cooper; [email protected]; Keir (Xen.org)
Subject: Re: [PATCH 1/2] x86/hvm: actually release ioreq server pages

xen/arch/x86/hvm/hvm.c static void hvm_free_ioreq_gmfn(struct domain *d,

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 23.04.15 at 17:46, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +0 -0
@@ -496,7 +496,7 @@ static void hvm_free_ioreq_gmfn(struct domain *d,

unsigned long gmfn)

xen/arch/x86/hvm/hvm.c static void hvm_free_ioreq_gmfn(struct domain *d, unsigned long gmfn) · line 500

Quoted 6 lines
xen/arch/x86/hvm/hvm.c +1 -1
 {
     unsigned int i = gmfn - d->arch.hvm_domain.ioreq_gmfn.base;
 
-    clear_bit(i, &d->arch.hvm_domain.ioreq_gmfn.mask);
+    set_bit(i, &d->arch.hvm_domain.ioreq_gmfn.mask);
 }
Quoted 6 lines

Double checking this I came to wonder whether HVM_PARAM_NR_IOREQ_SERVER_PAGES handling isn't broken when invoked a second time with a.value smaller than what was used the first time, or when any server pages are already in use.

Yes, the param is only intended to be a set-once param, the same as HVM_PARAM_IOREQ_SERVER_PFN. If the latter were changed after ioreq servers had been created then it could also lead to strangeness. I'll put together a patch to add checks for both.

Paul

Quoted 1 line

Jan