x86/HVM: don't retain emulated insn cache when exiting back to guest
PATCH 1/1 x86/HVM: don't retain emulated insn cache when exiting back to guest
vio->mmio_retry is being set when a repeated string insn is being split up. In that case we'll exit to the guest, expecting immediate re-entry. Interruptions, however, may be serviced by the guest before re-entry from the repeated string insn. Any emulation needed in the course of handling the interruption must not fetch from the internally maintained cache.
xen/arch/x86/hvm/emulate.c +10 -8
@@ -2109,20 +2109,22 @@ static int _hvm_emulate_one(struct hvm_e vio->mmio_retry =0 ; - rc =x86_emulate (&hvmemul_ctxt->ctxt, ops); - -if ( rc ==X86EMUL_OKAY && vio->mmio_retry ) - rc =X86EMUL_RETRY ; -if ( rc !=X86EMUL_RETRY ) +switch ( rc =x86_emulate (&hvmemul_ctxt->ctxt, ops) ) { +case X86EMUL_OKAY : +if ( vio->mmio_retry ) + rc =X86EMUL_RETRY ; +/* fall through */ +default : vio->mmio_cache_count =0 ; vio->mmio_insn_bytes =0 ; - } -else - { +break ; + +case X86EMUL_RETRY :BUILD_BUG_ON (sizeof (vio->mmio_insn) <sizeof (hvmemul_ctxt->insn_buf)); vio->mmio_insn_bytes = hvmemul_ctxt->insn_buf_bytes;memcpy (vio->mmio_insn, hvmemul_ctxt->insn_buf, vio->mmio_insn_bytes); +break ; }if ( hvmemul_ctxt->ctxt.retire.singlestep )
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 40 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 05 December 2017 16:14
To: xen-devel <[email protected]>
Cc: Julien Grall <[email protected]>; Andrew Cooper <[email protected]>; Paul Durrant <[email protected]>
Subject: [PATCH] x86/HVM: don't retain emulated insn cache when exiting back to guest
vio->mmio_retryis being set when a repeated string insn is being split up. In that case we'll exit to the guest, expecting immediate re-entry. Interruptions, however, may be serviced by the guest before re-entry from the repeated string insn. Any emulation needed in the course of handling the interruption must not fetch from the internally maintained cache.Signed-off-by Jan Beulich <[email protected]>xen/arch/x86/hvm/emulate.c +6
-7@@ -2109,20 +2109,22 @@ static int _hvm_emulate_one(struct hvm_e vio->mmio_retry =0 ; - rc =x86_emulate (&hvmemul_ctxt->ctxt, ops); - -if ( rc ==X86EMUL_OKAY && vio->mmio_retry ) - rc =X86EMUL_RETRY ; -if ( rc !=X86EMUL_RETRY ) +switch ( rc =x86_emulate (&hvmemul_ctxt->ctxt, ops) ) { +case X86EMUL_OKAY : +if ( vio->mmio_retry ) + rc =X86EMUL_RETRY ; +/* fall through */ +default : vio->mmio_cache_count =0 ; vio->mmio_insn_bytes =0 ; - } -else
xen/arch/x86/hvm/emulate.c static int _hvm_emulate_one(struct hvm_e · line 2129
Quoted 10 lines
xen/arch/x86/hvm/emulate.c +4
-1- { +break ; + +case X86EMUL_RETRY :BUILD_BUG_ON (sizeof (vio->mmio_insn) <sizeof (hvmemul_ctxt- >insn_buf)); vio->mmio_insn_bytes = hvmemul_ctxt->insn_buf_bytes;memcpy (vio->mmio_insn, hvmemul_ctxt->insn_buf, vio- >mmio_insn_bytes); +break ;
So, we have two distinct cases when X86EMUL_RETRY will be returned: the former when we do want to return to guest part way through a rep operation, and another when an MMIO has been sent for external emulation and we are expecting a completion. The code looks correct so...
...but I wonder there should be two distinct return codes for these two cases.
Quoted 5 lines
xen/arch/x86/hvm/emulate.c +0
-0}if ( hvmemul_ctxt->ctxt.retire.singlestep )
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 34 lines
Quoted 34 lines
Quoted 1 line · On 05.12.17 at 17:44, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 05 December 2017 16:14xen/arch/x86/hvm/emulate.c +9
-8@@ -2109,20 +2109,22 @@ static int _hvm_emulate_one(struct hvm_e vio->mmio_retry =0 ; - rc =x86_emulate (&hvmemul_ctxt->ctxt, ops); - -if ( rc ==X86EMUL_OKAY && vio->mmio_retry ) - rc =X86EMUL_RETRY ; -if ( rc !=X86EMUL_RETRY ) +switch ( rc =x86_emulate (&hvmemul_ctxt->ctxt, ops) ) { +case X86EMUL_OKAY : +if ( vio->mmio_retry ) + rc =X86EMUL_RETRY ; +/* fall through */ +default : vio->mmio_cache_count =0 ; vio->mmio_insn_bytes =0 ; - } -else - { +break ; + +case X86EMUL_RETRY :BUILD_BUG_ON (sizeof (vio->mmio_insn) <sizeof (hvmemul_ctxt- >insn_buf)); vio->mmio_insn_bytes = hvmemul_ctxt->insn_buf_bytes;memcpy (vio->mmio_insn, hvmemul_ctxt->insn_buf, vio- >mmio_insn_bytes);
Quoted 8 lines
xen/arch/x86/hvm/emulate.c static int _hvm_emulate_one(struct hvm_e · line 2129
Quoted 1 line
xen/arch/x86/hvm/emulate.c +1
-0+break ;So, we have two distinct cases when
X86EMUL_RETRYwill be returned: the former when we do want to return to guest part way through a rep operation, and another when an MMIO has been sent for external emulation and we are expecting a completion. The code looks correct so...Reviewed-by Paul Durrant <[email protected]>
Thanks.
Quoted 2 lines
...but I wonder there should be two distinct return codes for these two cases.
The question is - does any of the callers care about the difference. I think the relevant information has been recorded in data structures by the time we get here.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 55 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 05 December 2017 17:19
To: Paul Durrant <[email protected]>
Cc: Julien Grall <[email protected]>; Andrew Cooper <[email protected]>; xen-devel <xen- [email protected]>
Subject: RE: [PATCH] x86/HVM: don't retain emulated insn cache when exiting back to guestQuoted 30 lines
Quoted 30 lines
Quoted 1 line · On 05.12.17 at 17:44, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 05 December 2017 16:14xen/arch/x86/hvm/emulate.c +9
-8@@ -2109,20 +2109,22 @@ static int _hvm_emulate_one(struct hvm_e vio->mmio_retry =0 ; - rc =x86_emulate (&hvmemul_ctxt->ctxt, ops); - -if ( rc ==X86EMUL_OKAY && vio->mmio_retry ) - rc =X86EMUL_RETRY ; -if ( rc !=X86EMUL_RETRY ) +switch ( rc =x86_emulate (&hvmemul_ctxt->ctxt, ops) ) { +case X86EMUL_OKAY : +if ( vio->mmio_retry ) + rc =X86EMUL_RETRY ; +/* fall through */ +default : vio->mmio_cache_count =0 ; vio->mmio_insn_bytes =0 ; - } -else - { +break ; + +case X86EMUL_RETRY : BUILD_BUG_ON(sizeof(vio->mmio_insn) < sizeof(hvmemul_ctxt-Quoted 8 lines
xen/arch/x86/hvm/emulate.c static int _hvm_emulate_one(struct hvm_e · line 2129
Quoted 5 lines
xen/arch/x86/hvm/emulate.c +1
-0>insn_buf)); vio->mmio_insn_bytes = hvmemul_ctxt->insn_buf_bytes;memcpy (vio->mmio_insn, hvmemul_ctxt->insn_buf, vio- >mmio_insn_bytes); +break ;So, we have two distinct cases when
X86EMUL_RETRYwill be returned: the former when we do want to return to guest part way through a repoperation,
Quoted 1 line
and another when an MMIO has been sent for external emulation and we
are
Quoted 3 lines
expecting a completion. The code looks correct so...
Reviewed-by Paul Durrant <[email protected]>
Quoted 8 lines
Thanks.
Quoted 2 lines
...but I wonder there should be two distinct return codes for these two cases.
The question is - does any of the callers care about the difference. I think the relevant information has been recorded in data structures by the time we get here.
Technically, no I don't think the callers need to know but I've certainly got a bit tied in knots while trying to remember how this stuff is supposed to work so I was just hoping something could be done to make the 'don't return to guest because we need to retry mmio' and the 'return to guest even though want to retry a string operation' cases more obviously distinct.
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi Jan,
I guess I have been CCed because you would like this patch is fixing the regression you mentioned on IRC?
Cheers,
Quoted 46 lines · Jan Beulich
vio->mmio_retryis being set when a repeated string insn is being split up. In that case we'll exit to the guest, expecting immediate re-entry. Interruptions, however, may be serviced by the guest before re-entry from the repeated string insn. Any emulation needed in the course of handling the interruption must not fetch from the internally maintained cache.Signed-off-by Jan Beulich <[email protected]>xen/arch/x86/hvm/emulate.c +10
-8@@ -2109,20 +2109,22 @@ static int _hvm_emulate_one(struct hvm_e vio->mmio_retry =0 ; - rc =x86_emulate (&hvmemul_ctxt->ctxt, ops); - -if ( rc ==X86EMUL_OKAY && vio->mmio_retry ) - rc =X86EMUL_RETRY ; -if ( rc !=X86EMUL_RETRY ) +switch ( rc =x86_emulate (&hvmemul_ctxt->ctxt, ops) ) { +case X86EMUL_OKAY : +if ( vio->mmio_retry ) + rc =X86EMUL_RETRY ; +/* fall through */ +default : vio->mmio_cache_count =0 ; vio->mmio_insn_bytes =0 ; - } -else - { +break ; + +case X86EMUL_RETRY :BUILD_BUG_ON (sizeof (vio->mmio_insn) <sizeof (hvmemul_ctxt->insn_buf)); vio->mmio_insn_bytes = hvmemul_ctxt->insn_buf_bytes;memcpy (vio->mmio_insn, hvmemul_ctxt->insn_buf, vio->mmio_insn_bytes); +break ; }if ( hvmemul_ctxt->ctxt.retire.singlestep )
Quoted 5 lines
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 06.12.17 at 10:47, <[email protected]> wrote:
I guess I have been CCed because you would like this patch is fixing the regression you mentioned on IRC?
Yes, but first of all we need to see whether the issue goes away in master once the patch is in.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 6 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 06.12.17 at 10:47, <[email protected]> wrote:
I guess I have been CCed because you would like this patch is fixing the regression you mentioned on IRC?
Yes, but first of all we need to see whether the issue goes away in master once the patch is in.
Would reverting the offending patch in Xen 4.10 be solution?
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 06.12.17 at 12:47, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 06.12.17 at 10:47, <[email protected]> wrote:
I guess I have been CCed because you would like this patch is fixing the regression you mentioned on IRC?
Yes, but first of all we need to see whether the issue goes away in master once the patch is in.
Would reverting the offending patch in Xen 4.10 be solution?
Probably yes, at the price of re-introducing the issue that change did fix. But reverting wouldn't feel right: The change, after all, was not buggy - it merely uncovered the other issue, as far as we can tell.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi Jan,
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 06.12.17 at 12:47, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 06.12.17 at 10:47, <[email protected]> wrote:
I guess I have been CCed because you would like this patch is fixing the regression you mentioned on IRC?
Yes, but first of all we need to see whether the issue goes away in master once the patch is in.
Quoted 6 lines
Quoted 1 line
Would reverting the offending patch in Xen 4.10 be solution?
Probably yes, at the price of re-introducing the issue that change did fix. But reverting wouldn't feel right: The change, after all, was not buggy - it merely uncovered the other issue, as far as we can tell.
I understand. I have seen you pushed the fixes in master today. Let see how it perform and decide tomorrow what to do.
Cheers,
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 15 lines · Julien Grall
Hi Jan,
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 06.12.17 at 12:47, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.12.17 at 10:47, <[email protected]> wrote:
I guess I have been CCed because you would like this patch is fixing the
regression you mentioned on IRC?Yes, but first of all we need to see whether the issue goes away in master once the patch is in.
Would reverting the offending patch in Xen 4.10 be solution?
Quoted 7 lines
Quoted 4 lines
Probably yes, at the price of re-introducing the issue that change did fix. But reverting wouldn't feel right: The change, after all, was not buggy - it merely uncovered the other issue, as far as we can tell.
I understand. I have seen you pushed the fixes in master today. Let see how it perform and decide tomorrow what to do.
XenServer testing has identified this bug, and shown the bug to be fixed with this patch in place.
Therefore, a retroactive Tested-by: Andrew Cooper
<[email protected]>
No other emulation issues seen running windows on this particular piece of old AMD hardware.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi Andrew,
Quoted 24 lines · Andrew Cooper
Quoted 15 lines · Julien Grall
Hi Jan,
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 06.12.17 at 12:47, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.12.17 at 10:47, <[email protected]> wrote:
I guess I have been CCed because you would like this patch is fixing the
regression you mentioned on IRC?Yes, but first of all we need to see whether the issue goes away in master once the patch is in.
Would reverting the offending patch in Xen 4.10 be solution?
Quoted 7 lines
Quoted 4 lines
Probably yes, at the price of re-introducing the issue that change did fix. But reverting wouldn't feel right: The change, after all, was not buggy - it merely uncovered the other issue, as far as we can tell.
I understand. I have seen you pushed the fixes in master today. Let see how it perform and decide tomorrow what to do.
Quoted 8 lines
XenServer testing has identified this bug, and shown the bug to be fixed with this patch in place.
Therefore, a retroactive Tested-by: Andrew Cooper
<[email protected]>No other emulation issues seen running windows on this particular piece of old AMD hardware.
Thank you for doing regresison tests! On that basis:
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel