Skip to contentSkip to conversation

Skip unneeded VMENTRY & VMEXIT

PATCH In review Don Slutz 3 participants 7 messages Feb 10, 2015 – Feb 11, 2015

lore
Share & tools
lore

Don Slutz

author
#0 lore raw

v3 cover Skip unneeded VMENTRY & VMEXIT

Changes v3:

George Dunlap:
Acked-by for #1 "xentrace: Adjust IOPORT & MMIO format"

Paul Durrant:
Reviewed-by for #3 "hvmemul_do_io: Do not retry if no ioreq server exists"
Did not add to commit message do to code changes.

Jan Beulich:
#2 "hvm_complete_assist_req: We should not be able to get":
Move ASSERT() into switch and use ASSERT_UNREACHABLE().
Done.
#3 "hvmemul_do_io: Do not retry if no ioreq server exists":
Commit message is lacking.
New commit message.
Adjust comment containing "no backing DM"
Done
The name hvm_has_dm strictly suggests a "read-only" operation.
Dropped the routine hvm_has_dm.
From v2 "hvm_complete_assist_req() should return void"
Changed. I did not fold that routine into hvmemul_do_io() because I plan to add a 2nd caller.
I'd much favor you renaming hvm_send_assist_req_to_ioreq_server() to hvm_send_assist_req().
Done
the closing brace should follow the break statement.
Done
you could avoid "struct hvm_ioreq_server;" by re-ordering declarations.
Done

Changes v2:

Paul Durrant:
I think the two changes only make sense in combination.
folded old #3 and old #5 into #3.
Actually that comment is not right. The operation is not binned; it's just already been done.
Comment has been dropped.
I think you can ASSERT(s) here, as you should never get here ...
Dropped call to hvm_complete_assist_req(), added ASSERT.
So basically collapses down to just this call.
Yes, so changed to call on hvm_send_assist_req_to_ioreq_server() and removed hvm_send_assist_req() which had 1 caller.

Jan Beulich:
The change on what to do when hvm_send_assist_req() fails is bad.
That is correct. Made hvm_has_dm() do full checking so that the extra VMEXIT and VMENTRY can be skipped.
Add Suggested-by to old #4
Done (Now #2)
hvm_complete_assist_req() be a separate function yet having only a single caller ...
Folded hvm_complete_assist_req() in to hvm_has_dm() which is the only place it is called.

Using a new enough QEMU that has:

commit 7665d6ba98e20fb05c420de947c1750fd47e5c07

Author: Paul Durrant <[email protected]>
Date:   Tue Jan 20 11:06:19 2015 +0000

Xen: Use the ioreq-server API when available

means that hvmloader and the guest will do pci config accesses that will not be sent to QEMU. However hvm_complete_assist_req() (which is the routine that does the work) returns a 1 which hvm_send_assist_req() returns to the caller which means that the request was sent to QEMU and need to be waited for.

This is not the case. hvm_complete_assist_req() has called on hvm_io_assist() which has changed the io_state from HVMIO_awaiting_completion to HVMIO_completed if needed. But hvmemul_do_io() thinks that it needs to wait on the IOREQ_READ case, and returns X86EMUL_RETRY.

[PATCH 1/5] DEBUG: xentrace: Add debug of HANDLE_PIO
-- No need to apply

[PATCH 2/5] xentrace: Adjust IOPORT & MMIO format
-- Simple bugfix. xentrace_format is not converting these correctly

[PATCH 3/5] hvmemul_do_io: If the send to the ioreq server failed do
-- Simple bugfix. Do the same thing as when hvm_has_dm() returns
a zero.

[PATCH 4/5] hvm_complete_assist_req: We should not be able to get
-- This ASSERT was sugested by Paul Durrant. Since I was in the
file, just add it.

[PATCH 5/5] hvm_complete_assist_req: Tell caller we failed to send
-- The real fix. Does depend on [PATCH 3/5] hvmemul_do_io: If the send ...

Here is the before xentrace output using the "[PATCH 1/5] DEBUG:
xentrace: Add debug of HANDLE_PIO" (which I do not expect to be applied. It is first because that is the order you need to use to reproduce the xentrace output):

CPU0  685992932190 (+    2292)  VMEXIT      [ exitcode = 0x0000001e, rIP  = 0x00101581 ]
CPU0  0 (+       0)  HANDLE_PIO [ port = 0x0cfe size = 2 dir = 1 io_state = 5 ret = 0 ]
CPU0  685992934938 (+    2748)  vlapic_accept_pic_intr [ i8259_target = 1, accept_pic_int = 1 ]
CPU0  685992935526 (+     588)  VMENTRY
CPU0  685992937650 (+    2124)  VMEXIT      [ exitcode = 0x0000001e, rIP  = 0x00101581 ]
CPU0  0 (+       0)  IOPORT_READ [ port = 0x0cfe, data = 0x00000000 ]
CPU0  0 (+       0)  HANDLE_PIO [ port = 0x0cfe size = 2 dir = 1 io_state = 0 ret = 1 ]
CPU0  685992940248 (+    2598)  vlapic_accept_pic_intr [ i8259_target = 1, accept_pic_int = 1 ]
CPU0  685992940968 (+     720)  VMENTRY

And after:

CPU2  1028654638584 (+    2388)  VMEXIT      [ exitcode = 0x0000001e, rIP  = 0x00101581 ]
CPU2  0 (+       0)  IOPORT_READ [ port = 0x0cfe, data = 0xffffffff ]
CPU2  0 (+       0)  HANDLE_PIO [ port = 0x0cfe size = 2 dir = 1 io_state = 0 ret = 1 ]
CPU2  1028654641932 (+    3348)  vlapic_accept_pic_intr [ i8259_target = 1, accept_pic_int = 1 ]
CPU2  1028654642586 (+     654)  VMENTRY

Don Slutz (3):
xentrace: Adjust IOPORT & MMIO format
hvm_complete_assist_req: We should not be able to get here on
IOREQ_TYPE_PCI_CONFIG
hvmemul_do_io: Do not retry if no ioreq server exists for this I/O.

 tools/xentrace/formats        |  8 ++++----
 xen/arch/x86/hvm/emulate.c    | 12 +++++++++---
 xen/arch/x86/hvm/hvm.c        | 32 +++++++++-----------------------
 xen/include/asm-x86/hvm/hvm.h |  6 ++++--
 4 files changed, 26 insertions(+), 32 deletions(-)
Signature · 1 line
1.8.4
author
#1 lore raw

PATCH v3 1/3 xentrace: Adjust IOPORT & MMIO format

The 1st item is not data, but the port (address).
The 2nd item is the data.

---
v3:
Added Acked-by, George Dunlap

 tools/xentrace/formats | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/xentrace/formats +4 -4
index da658bf..5d7b72a 100644
@@ -68,10 +68,10 @@
 0x00082014  CPU%(cpu)d  %(tsc)d (+%(reltsc)8d)  INVLPG      [ is invlpga? = %(1)d, virt = 0x%(2)08x ]
 0x00082114  CPU%(cpu)d  %(tsc)d (+%(reltsc)8d)  INVLPG      [ is invlpga? = %(1)d, virt = 0x%(3)08x%(2)08x ]
 0x00082015  CPU%(cpu)d  %(tsc)d (+%(reltsc)8d)  MCE
-0x00082016  CPU%(cpu)d  %(tsc)d (+%(reltsc)8d)  IOPORT_READ [ data = 0x%(1)04x ]
-0x00082216  CPU%(cpu)d  %(tsc)d (+%(reltsc)8d)  IOPORT_WRITE [ data = 0x%(1)04x ]
-0x00082017  CPU%(cpu)d  %(tsc)d (+%(reltsc)8d)  MMIO_READ   [ data = 0x%(1)04x ]
-0x00082217  CPU%(cpu)d  %(tsc)d (+%(reltsc)8d)  MMIO_WRITE  [ data = 0x%(1)04x ]
+0x00082016  CPU%(cpu)d  %(tsc)d (+%(reltsc)8d)  IOPORT_READ [ port = 0x%(1)04x, data = 0x%(2)08x ]
+0x00082216  CPU%(cpu)d  %(tsc)d (+%(reltsc)8d)  IOPORT_WRITE [ port = 0x%(1)04x, data = 0x%(2)08x ]
+0x00082017  CPU%(cpu)d  %(tsc)d (+%(reltsc)8d)  MMIO_READ   [ port = 0x%(1)08x, data = 0x%(2)08x ]
+0x00082217  CPU%(cpu)d  %(tsc)d (+%(reltsc)8d)  MMIO_WRITE  [ port = 0x%(1)08x, data = 0x%(2)08x ]
 0x00082018  CPU%(cpu)d  %(tsc)d (+%(reltsc)8d)  CLTS
 0x00082019  CPU%(cpu)d  %(tsc)d (+%(reltsc)8d)  LMSW        [ value = 0x%(1)08x ]
 0x00082119  CPU%(cpu)d  %(tsc)d (+%(reltsc)8d)  LMSW        [ value = 0x%(2)08x%(1)08x ]
Signature · 1 line
1.8.4
author
#2 lore raw

PATCH v3 2/3 hvm_complete_assist_req: We should not be able to get here on IOREQ_TYPE_PCI_CONFIG

In reply to Don Slutz

---
v3:
Move ASSERT() into switch and use ASSERT_UNREACHABLE().

 xen/arch/x86/hvm/hvm.c | 3 +++
 1 file changed, 3 insertions(+)
xen/arch/x86/hvm/hvm.c +3 -0
index b03ee4e..1e722fc 100644
@@ -2632,6 +2632,9 @@ static bool_t hvm_complete_assist_req(ioreq_t *p)
 {
     switch ( p->type )
     {
+    case IOREQ_TYPE_PCI_CONFIG:
+        ASSERT_UNREACHABLE();
+        break;
     case IOREQ_TYPE_COPY:
     case IOREQ_TYPE_PIO:
         if ( p->dir == IOREQ_READ )
Signature · 1 line
1.8.4
Reviewed-by on v3 2/3
#3 lore raw

Re: [PATCH v3 2/3] hvm_complete_assist_req: We should not be able to get here on IOREQ_TYPE_PCI_CONFIG

Quoted 11 lines

-----Original Message-----
From: Don Slutz [mailto:[email protected]]
Sent: 10 February 2015 22:52
To: [email protected]; Jan Beulich; Paul Durrant
Cc: Andrew Cooper; George Dunlap; Ian Campbell; Ian Jackson; Keir (Xen.org); Stefano Stabellini; Wei Liu; Don Slutz
Subject: [PATCH v3 2/3] hvm_complete_assist_req: We should not be able to get here on IOREQ_TYPE_PCI_CONFIG

Quoted 24 lines

---
v3:
Move ASSERT() into switch and use ASSERT_UNREACHABLE().

 xen/arch/x86/hvm/hvm.c | 3 +++
 1 file changed, 3 insertions(+)
xen/arch/x86/hvm/hvm.c +3 -1
index b03ee4e..1e722fc 100644
@@ -2632,6 +2632,9 @@ static bool_t hvm_complete_assist_req(ioreq_t *p)
 {
     switch ( p->type )
     {
+    case IOREQ_TYPE_PCI_CONFIG:
+        ASSERT_UNREACHABLE();
+        break;
     case IOREQ_TYPE_COPY:
     case IOREQ_TYPE_PIO:
         if ( p->dir == IOREQ_READ )
--

1.8.4

author
#4 lore raw

PATCH v3 3/3 hvmemul_do_io: Do not retry if no ioreq server exists for this I/O.

In reply to Don Slutz

This saves a VMENTRY and a VMEXIT since we no longer retry the ioport read on backing DM not handling a given ioreq.

There are 2 case about "no ioreq server exists for this I/O":

1) No ioreq servers (PVH case)
2) No ioreq servers for this I/O (non PVH case)

The routine hvm_has_dm() used to check for the empty list, the PVH case (#1).

By changing from hvm_has_dm() to hvm_select_ioreq_server() both cases are considered. Doing it this way allows hvm_send_assist_req() to only have 2 possible return values.

The key part of skipping the retry is to do "rc = X86EMUL_OKAY" which is what the error path on the call to hvm_has_dm() does in hvmemul_do_io() (the only call on hvm_has_dm()).

Since this case is no longer handled in hvm_send_assist_req(), move the call to hvm_complete_assist_req() into hvmemul_do_io().

As part of this change, do the work of hvm_complete_assist_req() in the PVH case. Acting more like real hardware looks to be better.

Adding "rc = X86EMUL_OKAY" in the failing case of hvm_send_assist_req() would break what was done in commit bac0999325056a3b3a92f7622df7ffbc5388b1c3 and commit f20f3c8ece5c10fa7626f253d28f570a43b23208. We are currently doing the succeeding case of hvm_send_assist_req() and retying the I/O.

Since hvm_select_ioreq_server() has already been called, switch to using hvm_send_assist_req_to_ioreq_server().

Since there is no longer any calls to hvm_send_assist_req(), drop that routine and rename hvm_send_assist_req_to_ioreq_server() to hvm_send_assist_req.

Since hvm_send_assist_req() is an extern, add an ASSERT() on s.

---

v3:
Reviewed-by, Paul Durrant
Did not add to commit message do to code changes.

Commit message is lacking.
New commit message.
Adjust comment containing "no backing DM"
Done
The name hvm_has_dm strictly suggests a "read-only" operation.
Dropped the routine hvm_has_dm.
From v2 "hvm_complete_assist_req() should return void"
Changed. I did not fold that routine into hvmemul_do_io() because I plan to add a 2nd caller.
I'd much favor you renaming hvm_send_assist_req_to_ioreq_server() to hvm_send_assist_req().
Done
the closing brace should follow the break statement.
Done
you could avoid "struct hvm_ioreq_server;" by re-ordering declarations.
Done

 xen/arch/x86/hvm/emulate.c    | 12 +++++++++---
 xen/arch/x86/hvm/hvm.c        | 29 ++++++-----------------------
 xen/include/asm-x86/hvm/hvm.h |  6 ++++--
 3 files changed, 19 insertions(+), 28 deletions(-)
xen/arch/x86/hvm/emulate.c +9 -3
index 2ed4344..636c909 100644
@@ -218,21 +218,27 @@ static int hvmemul_do_io(
             vio->io_state = HVMIO_handle_mmio_awaiting_completion;
         break;
     case X86EMUL_UNHANDLEABLE:
-        /* If there is no backing DM, just ignore accesses */
-        if ( !hvm_has_dm(curr->domain) )
+    {
+        struct hvm_ioreq_server *s =
+            hvm_select_ioreq_server(curr->domain, &p);
+
+        /* If there is no suitable backing DM, just ignore accesses */
+        if ( !s )
         {
+            hvm_complete_assist_req(&p);
             rc = X86EMUL_OKAY;
             vio->io_state = HVMIO_none;
         }
         else
         {
             rc = X86EMUL_RETRY;
-            if ( !hvm_send_assist_req(&p) )
+            if ( !hvm_send_assist_req(s, &p) )
                 vio->io_state = HVMIO_none;
             else if ( p_data == NULL )
                 rc = X86EMUL_OKAY;
         }
         break;
+    }
     default:
         BUG();
     }
xen/arch/x86/hvm/hvm.c +6 -23
index 1e722fc..f149ce5 100644
@@ -2381,8 +2381,8 @@ void hvm_vcpu_down(struct vcpu *v)
     }
 }
 
-static struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d,
-                                                        ioreq_t *p)
+struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d,
+                                                 ioreq_t *p)
 {
 #define CF8_BDF(cf8)     (((cf8) & 0x00ffff00) >> 8)
 #define CF8_ADDR_LO(cf8) ((cf8) & 0x000000fc)
@@ -2564,18 +2564,13 @@ int hvm_buffered_io_send(ioreq_t *p)
     return 1;
 }
 
-bool_t hvm_has_dm(struct domain *d)
-{
-    return !list_empty(&d->arch.hvm_domain.ioreq_server.list);
-}
-
-bool_t hvm_send_assist_req_to_ioreq_server(struct hvm_ioreq_server *s,
-                                           ioreq_t *proto_p)
+bool_t hvm_send_assist_req(struct hvm_ioreq_server *s, ioreq_t *proto_p)
 {
     struct vcpu *curr = current;
     struct domain *d = curr->domain;
     struct hvm_ioreq_vcpu *sv;
 
+    ASSERT(s);
     if ( unlikely(!vcpu_start_shutdown_deferral(curr)) )
         return 0; /* implicitly bins the i/o operation */
 
@@ -2628,7 +2623,7 @@ bool_t hvm_send_assist_req_to_ioreq_server(struct hvm_ioreq_server *s,
     return 0;
 }
 
-static bool_t hvm_complete_assist_req(ioreq_t *p)
+void hvm_complete_assist_req(ioreq_t *p)
 {
     switch ( p->type )
     {
@@ -2657,18 +2652,6 @@ static bool_t hvm_complete_assist_req(ioreq_t *p)
         hvm_io_assist(p);
         break;
     }
-
-    return 1;
-}
-
-bool_t hvm_send_assist_req(ioreq_t *p)
-{
-    struct hvm_ioreq_server *s = hvm_select_ioreq_server(current->domain, p);
-
-    if ( !s )
-        return hvm_complete_assist_req(p);
-
-    return hvm_send_assist_req_to_ioreq_server(s, p);
 }
 
 void hvm_broadcast_assist_req(ioreq_t *p)
@@ -2681,7 +2664,7 @@ void hvm_broadcast_assist_req(ioreq_t *p)
     list_for_each_entry ( s,
                           &d->arch.hvm_domain.ioreq_server.list,
                           list_entry )
-        (void) hvm_send_assist_req_to_ioreq_server(s, p);
+        (void) hvm_send_assist_req(s, p);
 }
 
 void hvm_hlt(unsigned long rflags)
xen/include/asm-x86/hvm/hvm.h +4 -2
index e3d2d9a..0dc909b 100644
@@ -228,8 +228,11 @@ int hvm_vcpu_cacheattr_init(struct vcpu *v);
 void hvm_vcpu_cacheattr_destroy(struct vcpu *v);
 void hvm_vcpu_reset_state(struct vcpu *v, uint16_t cs, uint16_t ip);
 
-bool_t hvm_send_assist_req(ioreq_t *p);
+struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d,
+                                                 ioreq_t *p);
+bool_t hvm_send_assist_req(struct hvm_ioreq_server *s, ioreq_t *p);
 void hvm_broadcast_assist_req(ioreq_t *p);
+void hvm_complete_assist_req(ioreq_t *p);
 
 void hvm_get_guest_pat(struct vcpu *v, u64 *guest_pat);
 int hvm_set_guest_pat(struct vcpu *v, u64 guest_pat);
@@ -359,7 +362,6 @@ void hvm_hypervisor_cpuid_leaf(uint32_t sub_idx,
 void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx,
                                    unsigned int *ecx, unsigned int *edx);
 void hvm_migrate_timers(struct vcpu *v);
-bool_t hvm_has_dm(struct domain *d);
 bool_t hvm_io_pending(struct vcpu *v);
 void hvm_do_resume(struct vcpu *v);
 void hvm_migrate_pirqs(struct vcpu *v);
Signature · 1 line
1.8.4
#5 lore raw

Re: [PATCH v3 3/3] hvmemul_do_io: Do not retry if no ioreq server exists for this I/O.

Quoted 39 lines
Quoted 1 line
Quoted 1 line · On 10.02.15 at 23:52, <[email protected]> wrote:

This saves a VMENTRY and a VMEXIT since we no longer retry the ioport read on backing DM not handling a given ioreq.

There are 2 case about "no ioreq server exists for this I/O":

1) No ioreq servers (PVH case)
2) No ioreq servers for this I/O (non PVH case)

The routine hvm_has_dm() used to check for the empty list, the PVH case (#1).

By changing from hvm_has_dm() to hvm_select_ioreq_server() both cases are considered. Doing it this way allows hvm_send_assist_req() to only have 2 possible return values.

The key part of skipping the retry is to do "rc = X86EMUL_OKAY" which is what the error path on the call to hvm_has_dm() does in hvmemul_do_io() (the only call on hvm_has_dm()).

Since this case is no longer handled in hvm_send_assist_req(), move the call to hvm_complete_assist_req() into hvmemul_do_io().

As part of this change, do the work of hvm_complete_assist_req() in the PVH case. Acting more like real hardware looks to be better.

Adding "rc = X86EMUL_OKAY" in the failing case of hvm_send_assist_req() would break what was done in commit bac0999325056a3b3a92f7622df7ffbc5388b1c3 and commit f20f3c8ece5c10fa7626f253d28f570a43b23208. We are currently doing the succeeding case of hvm_send_assist_req() and retying the I/O.

Since hvm_select_ioreq_server() has already been called, switch to using hvm_send_assist_req_to_ioreq_server().

Since there is no longer any calls to hvm_send_assist_req(), drop that routine and rename hvm_send_assist_req_to_ioreq_server() to hvm_send_assist_req.

Quoted 5 lines

Since hvm_send_assist_req() is an extern, add an ASSERT() on s.

---

So Paul, does you R-b stand despite the code changes in v3?

Jan

#6 lore raw

Re: [PATCH v3 3/3] hvmemul_do_io: Do not retry if no ioreq server exists for this I/O.

Quoted 48 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 11 February 2015 13:37
To: Paul Durrant
Cc: Andrew Cooper; Ian Campbell; Wei Liu; George Dunlap; Ian Jackson; Stefano Stabellini; [email protected]; Don Slutz; Keir (Xen.org)
Subject: Re: [PATCH v3 3/3] hvmemul_do_io: Do not retry if no ioreq server exists for this I/O.

Quoted 39 lines
Quoted 1 line
Quoted 1 line · On 10.02.15 at 23:52, <[email protected]> wrote:

This saves a VMENTRY and a VMEXIT since we no longer retry the ioport read on backing DM not handling a given ioreq.

There are 2 case about "no ioreq server exists for this I/O":

1) No ioreq servers (PVH case)
2) No ioreq servers for this I/O (non PVH case)

The routine hvm_has_dm() used to check for the empty list, the PVH case (#1).

By changing from hvm_has_dm() to hvm_select_ioreq_server() both cases are considered. Doing it this way allows hvm_send_assist_req() to only have 2 possible return values.

The key part of skipping the retry is to do "rc = X86EMUL_OKAY" which is what the error path on the call to hvm_has_dm() does in hvmemul_do_io() (the only call on hvm_has_dm()).

Since this case is no longer handled in hvm_send_assist_req(), move the call to hvm_complete_assist_req() into hvmemul_do_io().

As part of this change, do the work of hvm_complete_assist_req() in the PVH case. Acting more like real hardware looks to be better.

Adding "rc = X86EMUL_OKAY" in the failing case of hvm_send_assist_req() would break what was done in commit bac0999325056a3b3a92f7622df7ffbc5388b1c3 and commit f20f3c8ece5c10fa7626f253d28f570a43b23208. We are currently doing the succeeding case of hvm_send_assist_req() and retying the I/O.

Since hvm_select_ioreq_server() has already been called, switch to using hvm_send_assist_req_to_ioreq_server().

Since there is no longer any calls to hvm_send_assist_req(), drop that routine and rename hvm_send_assist_req_to_ioreq_server() to hvm_send_assist_req.

Quoted 8 lines
Quoted 5 lines

Since hvm_send_assist_req() is an extern, add an ASSERT() on s.

---

So Paul, does you R-b stand despite the code changes in v3?

Yes, I am happy with the changes. Getting rid of hvm_has_dm() does make things better.

Paul

Quoted 1 line

Jan