xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Paul Durrant <paul.durrant@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Paul Durrant <paul.durrant@citrix.com>,
	Jan Beulich <jbeulich@suse.com>
Subject: [PATCH v3 8/8] x86/hvm: serialize trap injecting producer and consumer
Date: Thu, 12 Jan 2017 14:58:40 +0000	[thread overview]
Message-ID: <1484233120-2015-9-git-send-email-paul.durrant@citrix.com> (raw)
In-Reply-To: <1484233120-2015-1-git-send-email-paul.durrant@citrix.com>

Since injection works on a remote vCPU, and since there's no
enforcement of the subject vCPU being paused, there's a potential race
between the producing and consuming sides. Fix this by leveraging the
vector field as synchronization variable.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
[re-based]
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
---
Cc: Andrew Cooper <andrew.cooper3@citrix.com>

v3:
- Re-re-re-based after more changes.

v2:
- Re-re-based after Andrew's recent changes.
---
 xen/arch/x86/hvm/dm.c         | 5 ++++-
 xen/arch/x86/hvm/hvm.c        | 8 +++++---
 xen/include/asm-x86/hvm/hvm.h | 3 +++
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/xen/arch/x86/hvm/dm.c b/xen/arch/x86/hvm/dm.c
index 0a7e50a..e09c8e7 100644
--- a/xen/arch/x86/hvm/dm.c
+++ b/xen/arch/x86/hvm/dm.c
@@ -286,13 +286,16 @@ static int inject_trap(struct domain *d, unsigned int vcpuid,
     if ( vcpuid >= d->max_vcpus || !(v = d->vcpu[vcpuid]) )
         return -EINVAL;
 
-    if ( v->arch.hvm_vcpu.inject_trap.vector != -1 )
+    if ( cmpxchg(&v->arch.hvm_vcpu.inject_trap.vector,
+                 HVM_TRAP_VECTOR_UNSET, HVM_TRAP_VECTOR_UPDATING) !=
+         HVM_TRAP_VECTOR_UNSET )
         return -EBUSY;
 
     v->arch.hvm_vcpu.inject_trap.type = type;
     v->arch.hvm_vcpu.inject_trap.insn_len = insn_len;
     v->arch.hvm_vcpu.inject_trap.error_code = error_code;
     v->arch.hvm_vcpu.inject_trap.cr2 = cr2;
+    smp_wmb();
     v->arch.hvm_vcpu.inject_trap.vector = vector;
 
     return 0;
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 8d42adc..441111b 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -539,12 +539,14 @@ void hvm_do_resume(struct vcpu *v)
     }
 
     /* Inject pending hw/sw trap */
-    if ( v->arch.hvm_vcpu.inject_trap.vector != -1 )
+    if ( v->arch.hvm_vcpu.inject_trap.vector >= 0 )
     {
+        smp_rmb();
+
         if ( !hvm_event_pending(v) )
             hvm_inject_event(&v->arch.hvm_vcpu.inject_trap);
 
-        v->arch.hvm_vcpu.inject_trap.vector = -1;
+        v->arch.hvm_vcpu.inject_trap.vector = HVM_TRAP_VECTOR_UNSET;
     }
 
     if ( unlikely(v->arch.vm_event) && v->arch.monitor.next_interrupt_enabled )
@@ -1563,7 +1565,7 @@ int hvm_vcpu_initialise(struct vcpu *v)
         (void(*)(unsigned long))hvm_assert_evtchn_irq,
         (unsigned long)v);
 
-    v->arch.hvm_vcpu.inject_trap.vector = -1;
+    v->arch.hvm_vcpu.inject_trap.vector = HVM_TRAP_VECTOR_UNSET;
 
     if ( is_pvh_domain(d) )
     {
diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h
index 8c95c08..bcacee3 100644
--- a/xen/include/asm-x86/hvm/hvm.h
+++ b/xen/include/asm-x86/hvm/hvm.h
@@ -77,6 +77,9 @@ enum hvm_intblk {
 #define HVM_HAP_SUPERPAGE_2MB   0x00000001
 #define HVM_HAP_SUPERPAGE_1GB   0x00000002
 
+#define HVM_TRAP_VECTOR_UNSET    (-1)
+#define HVM_TRAP_VECTOR_UPDATING (-2)
+
 /*
  * The hardware virtual machine (HVM) interface abstracts away from the
  * x86/x86_64 CPU virtualization assist specifics. Currently this interface
-- 
2.1.4


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

  parent reply	other threads:[~2017-01-12 14:58 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-12 14:58 [PATCH v3 0/8] New hypercall for device models Paul Durrant
2017-01-12 14:58 ` [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op Paul Durrant
2017-01-12 15:33   ` Andrew Cooper
2017-01-12 16:10     ` Paul Durrant
2017-01-12 16:29       ` Jan Beulich
2017-01-13  9:05         ` Paul Durrant
2017-01-13 10:30           ` Jan Beulich
2017-01-13 10:47             ` Paul Durrant
2017-01-13 10:44           ` Wei Liu
2017-01-13 12:03         ` Andrew Cooper
2017-01-13 12:47           ` Jan Beulich
2017-01-16 16:05             ` Andrew Cooper
2017-01-16 16:16               ` Jan Beulich
2017-01-16 17:07                 ` Paul Durrant
2017-01-16 17:18                   ` Jan Beulich
2017-01-17 11:22                 ` Andrew Cooper
2017-01-17 12:29                   ` George Dunlap
2017-01-17 15:06                     ` Andrew Cooper
2017-01-17 15:37                       ` Jan Beulich
2017-01-17 12:42                   ` Jan Beulich
2017-01-17 15:13                     ` Andrew Cooper
2017-01-17 15:31                       ` Jan Beulich
2017-01-12 14:58 ` [PATCH v3 2/8] dm_op: convert HVMOP_*ioreq_server* Paul Durrant
2017-01-12 16:30   ` Jan Beulich
2017-01-12 14:58 ` [PATCH v3 3/8] dm_op: convert HVMOP_track_dirty_vram Paul Durrant
2017-01-13 11:45   ` Jan Beulich
2017-01-13 11:46     ` Paul Durrant
2017-01-13 13:22   ` Tim Deegan
2017-01-16 15:12   ` George Dunlap
2017-01-12 14:58 ` [PATCH v3 4/8] dm_op: convert HVMOP_set_pci_intx_level, HVMOP_set_isa_irq_level, and Paul Durrant
2017-01-12 14:58 ` [PATCH v3 5/8] dm_op: convert HVMOP_modified_memory Paul Durrant
2017-01-13 11:51   ` Jan Beulich
2017-01-13 11:54     ` Paul Durrant
2017-01-12 14:58 ` [PATCH v3 6/8] dm_op: convert HVMOP_set_mem_type Paul Durrant
2017-01-13 11:54   ` Jan Beulich
2017-01-12 14:58 ` [PATCH v3 7/8] dm_op: convert HVMOP_inject_trap and HVMOP_inject_msi Paul Durrant
2017-01-12 14:58 ` Paul Durrant [this message]
2017-01-12 16:28   ` [PATCH v3 8/8] x86/hvm: serialize trap injecting producer and consumer Andrew Cooper
2017-01-12 16:41     ` Jan Beulich

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=1484233120-2015-9-git-send-email-paul.durrant@citrix.com \
    --to=paul.durrant@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=xen-devel@lists.xenproject.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).