All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Tim Deegan <tim@xen.org>
Cc: Kevin Tian <kevin.tian@intel.com>,
	Jan Beulich <JBeulich@suse.com>,
	George Dunlap <george.dunlap@eu.citrix.com>,
	Xen-devel <xen-devel@lists.xen.org>,
	Paul Durrant <paul.durrant@citrix.com>,
	Jun Nakajima <jun.nakajima@intel.com>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Subject: Re: [PATCH 06/15] x86/emul: Rework emulator event injection
Date: Wed, 23 Nov 2016 16:38:45 +0000	[thread overview]
Message-ID: <d29d020c-1ab4-070a-2f5a-41551b5b20d1@citrix.com> (raw)
In-Reply-To: <20161123161916.GC62912@deinos.phlegethon.org>


[-- Attachment #1.1: Type: text/plain, Size: 2808 bytes --]

On 23/11/16 16:19, Tim Deegan wrote:
> Hi,
>
> At 15:38 +0000 on 23 Nov (1479915529), Andrew Cooper wrote:
>> The emulator needs to gain an understanding of interrupts and exceptions
>> generated by its actions.
>>
>> Move hvm_emulate_ctxt.{exn_pending,trap} into struct x86_emulate_ctxt so they
>> are visible to the emulator.  This removes the need for the
>> inject_{hw,sw}_interrupt() hooks, which are dropped and replaced with
>> x86_emul_{hw_exception,software_event}() instead.
>>
>> The shadow pagetable and PV uses of x86_emulate() previously failed with
>> X86EMUL_UNHANDLEABLE due to the lack of inject_*() hooks, but this behaviour
>> has subtly changed.  Adjust the return value checking to cause a pending event
>> to fall back into the previous codepath.
>>
>> No overall functional change.
> AIUI this does have a change in the shadow callers in the case where
> the emulated instruction would inject an event.  Previously we would
> have failed the emulation, perhaps unshadowed something, and returned
> to the guest to retry.
> Now the emulator records the event in the context struct, updates the
> register state and returns success, so we'll return on the *next*
> instruction.  I think that's OK, though.

We are still passing X86EMUL_EXCEPTION back into the emulator, so
nothing changes immediately from that point of view.  It will still
"goto done" and skip the writeback phase.

> Also, handle_mmio() and other callers of the emulator check for that
> pending event and pass it to the hardware but you haven't added
> anything in the shadow code to do that.  Does the event get dropped?

Yes.  That was the intended purpose of these hunks:

diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c
index d70b1c6..84cb6b6 100644
--- a/xen/arch/x86/mm/shadow/multi.c
+++ b/xen/arch/x86/mm/shadow/multi.c
@@ -3378,7 +3378,7 @@ static int sh_page_fault(struct vcpu *v,
      * would be a good unshadow hint. If we *do* decide to unshadow-on-fault
      * then it must be 'failable': we cannot require the unshadow to succeed.
      */
-    if ( r == X86EMUL_UNHANDLEABLE )
+    if ( r == X86EMUL_UNHANDLEABLE || emul_ctxt.ctxt.event_pending )
     {
         perfc_incr(shadow_fault_emulate_failed);
 #if SHADOW_OPTIMIZATIONS & SHOPT_FAST_EMULATION
@@ -3433,7 +3433,7 @@ static int sh_page_fault(struct vcpu *v,
             shadow_continue_emulation(&emul_ctxt, regs);
             v->arch.paging.last_write_was_pt = 0;
             r = x86_emulate(&emul_ctxt.ctxt, emul_ops);
-            if ( r == X86EMUL_OKAY )
+            if ( r == X86EMUL_OKAY && !emul_ctxt.ctxt.event_pending )
             {
                 emulation_count++;
                 if ( v->arch.paging.last_write_was_pt )

To take the failure path any time an event is seen pending.

~Andrew

[-- Attachment #1.2: Type: text/html, Size: 3695 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2016-11-23 16:38 UTC|newest]

Thread overview: 91+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-23 15:38 [PATCH for-4.9 00/15] XSA-191 followup Andrew Cooper
2016-11-23 15:38 ` [PATCH 01/15] x86/hvm: Rename hvm_emulate_init() and hvm_emulate_prepare() for clarity Andrew Cooper
2016-11-23 15:49   ` Paul Durrant
2016-11-23 15:53   ` Wei Liu
2016-11-23 16:40   ` Jan Beulich
2016-11-23 16:41   ` Boris Ostrovsky
2016-11-23 16:41     ` Andrew Cooper
2016-11-24  6:16   ` Tian, Kevin
2016-11-23 15:38 ` [PATCH 02/15] x86/emul: Simplfy emulation state setup Andrew Cooper
2016-11-23 15:58   ` Paul Durrant
2016-11-23 16:01     ` Andrew Cooper
2016-11-23 16:03       ` Paul Durrant
2016-11-23 16:07   ` Tim Deegan
2016-11-24 13:44   ` Jan Beulich
2016-11-24 13:59     ` Andrew Cooper
2016-11-24 14:18       ` Jan Beulich
2016-11-23 15:38 ` [PATCH 03/15] x86/emul: Rename hvm_trap to x86_event and move it into the emulation infrastructure Andrew Cooper
2016-11-23 16:12   ` Paul Durrant
2016-11-23 16:22     ` Andrew Cooper
2016-11-23 16:59   ` Boris Ostrovsky
2016-11-24  6:17   ` Tian, Kevin
2016-11-24 13:56   ` Jan Beulich
2016-11-24 14:42     ` Andrew Cooper
2016-11-24 14:57       ` Jan Beulich
2016-11-23 15:38 ` [PATCH 04/15] x86/emul: Rename HVM_DELIVER_NO_ERROR_CODE to X86_EVENT_NO_EC Andrew Cooper
2016-11-23 16:20   ` Paul Durrant
2016-11-23 17:05   ` Boris Ostrovsky
2016-11-24  6:18   ` Tian, Kevin
2016-11-24 14:18   ` Jan Beulich
2016-11-23 15:38 ` [PATCH 05/15] x86/emul: Remove opencoded exception generation Andrew Cooper
2016-11-24 14:31   ` Jan Beulich
2016-11-24 16:24     ` Andrew Cooper
2016-11-24 16:31       ` Jan Beulich
2016-11-24 17:04         ` Andrew Cooper
2016-11-23 15:38 ` [PATCH 06/15] x86/emul: Rework emulator event injection Andrew Cooper
2016-11-23 16:19   ` Tim Deegan
2016-11-23 16:33     ` Jan Beulich
2016-11-23 16:43       ` Tim Deegan
2016-11-23 16:38     ` Andrew Cooper [this message]
2016-11-23 17:56   ` Boris Ostrovsky
2016-11-24  6:20   ` Tian, Kevin
2016-11-24 14:53   ` Jan Beulich
2016-11-24 17:00     ` Andrew Cooper
2016-11-24 17:08       ` Jan Beulich
2016-11-24 17:19         ` Andrew Cooper
2016-11-24 17:30           ` Tim Deegan
2016-11-24 17:37             ` Andrew Cooper
2016-11-25  7:25               ` Jan Beulich
2016-11-25  9:41                 ` Tim Deegan
2016-11-25  7:42           ` Jan Beulich
2016-11-23 15:38 ` [PATCH 07/15] x86/vmx: Use hvm_{get, set}_segment_register() rather than vmx_{get, set}_segment_register() Andrew Cooper
2016-11-24  6:20   ` Tian, Kevin
2016-11-23 15:38 ` [PATCH 08/15] x86/hvm: Reposition the modification of raw segment data from the VMCB/VMCS Andrew Cooper
2016-11-23 19:01   ` Boris Ostrovsky
2016-11-23 19:28     ` Andrew Cooper
2016-11-23 19:41       ` Boris Ostrovsky
2016-11-23 19:58         ` Andrew Cooper
2016-11-24  6:24   ` Tian, Kevin
2016-11-24 15:25   ` Jan Beulich
2016-11-24 17:22     ` Andrew Cooper
2016-11-25  7:45       ` Jan Beulich
2016-11-23 15:38 ` [PATCH 09/15] x86/emul: Avoid raising faults behind the emulators back Andrew Cooper
2016-11-23 16:31   ` Tim Deegan
2016-11-23 16:40     ` Andrew Cooper
2016-11-23 16:50       ` Tim Deegan
2016-11-23 16:58         ` Andrew Cooper
2016-11-24 10:43           ` Jan Beulich
2016-11-24 10:46             ` Andrew Cooper
2016-11-24 11:24               ` Jan Beulich
2016-11-23 15:38 ` [PATCH 10/15] x86/hvm: Extend the hvm_copy_*() API with a pagefault_info pointer Andrew Cooper
2016-11-23 16:32   ` Tim Deegan
2016-11-23 16:36   ` Paul Durrant
2016-11-24  6:25   ` Tian, Kevin
2016-11-23 15:38 ` [PATCH 11/15] x86/hvm: Reimplement hvm_copy_*_nofault() in terms of no pagefault_info Andrew Cooper
2016-11-23 16:35   ` Tim Deegan
2016-11-23 16:38     ` Andrew Cooper
2016-11-23 16:40     ` Tim Deegan
2016-11-23 15:38 ` [PATCH 12/15] x86/hvm: Rename hvm_copy_*_guest_virt() to hvm_copy_*_guest_linear() Andrew Cooper
2016-11-23 16:35   ` Tim Deegan
2016-11-24  6:26   ` Tian, Kevin
2016-11-24 15:41   ` Jan Beulich
2016-11-23 15:38 ` [PATCH 13/15] x86/hvm: Avoid __hvm_copy() raising #PF behind the emulators back Andrew Cooper
2016-11-23 16:18   ` Andrew Cooper
2016-11-23 16:39   ` Tim Deegan
2016-11-23 17:06     ` Andrew Cooper
2016-11-23 15:38 ` [PATCH 14/15] x86/hvm: Prepare to allow use of system segments for memory references Andrew Cooper
2016-11-23 16:42   ` Paul Durrant
2016-11-24 15:48   ` Jan Beulich
2016-11-23 15:38 ` [PATCH 15/15] x86/hvm: Use system-segment relative memory accesses Andrew Cooper
2016-11-24 16:01   ` Jan Beulich
2016-11-24 16:03     ` Andrew Cooper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d29d020c-1ab4-070a-2f5a-41551b5b20d1@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=jun.nakajima@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=paul.durrant@citrix.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.