All of
 help / color / mirror / Atom feed
From: Roger Pau Monne <>
To: <>
Cc: Andrew Cooper <>, Wei Liu <>,
	Jan Beulich <>,
	Roger Pau Monne <>
Subject: [Xen-devel] [PATCH v2 1/3] x86/hvm: allow ASID flush when v != current
Date: Fri, 10 Jan 2020 17:04:02 +0100	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

Current implementation of hvm_asid_flush_vcpu is not safe to use
unless the target vCPU is either paused or the currently running one,
as it modifies the generation without any locking.

Fix this by using atomic operations when accessing the generation
field, both in hvm_asid_flush_vcpu_asid and other ASID functions. This
allows to safely flush the current ASID generation. Note that for the
flush to take effect if the vCPU is currently running a vmexit is

Note the same could be achieved by introducing an extra field to
hvm_vcpu_asid that signals hvm_asid_handle_vmenter the need to call
hvm_asid_flush_vcpu on the given vCPU before vmentry, this however
seems unnecessary as hvm_asid_flush_vcpu itself only sets two vCPU
fields to 0, so there's no need to delay this to the vmentry ASID

This is not a bugfix as no callers that would violate the assumptions
listed in the first paragraph have been found, but a preparatory
change in order to allow remote flushing of HVM vCPUs.

Signed-off-by: Roger Pau Monné <>
 xen/arch/x86/hvm/asid.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/xen/arch/x86/hvm/asid.c b/xen/arch/x86/hvm/asid.c
index 9d3c671a5f..80b73da89b 100644
--- a/xen/arch/x86/hvm/asid.c
+++ b/xen/arch/x86/hvm/asid.c
@@ -82,7 +82,7 @@ void hvm_asid_init(int nasids)
 void hvm_asid_flush_vcpu_asid(struct hvm_vcpu_asid *asid)
-    asid->generation = 0;
+    write_atomic(&asid->generation, 0);
 void hvm_asid_flush_vcpu(struct vcpu *v)
@@ -120,7 +120,7 @@ bool_t hvm_asid_handle_vmenter(struct hvm_vcpu_asid *asid)
         goto disabled;
     /* Test if VCPU has valid ASID. */
-    if ( asid->generation == data->core_asid_generation )
+    if ( read_atomic(&asid->generation) == data->core_asid_generation )
         return 0;
     /* If there are no free ASIDs, need to go to a new generation */
@@ -134,7 +134,7 @@ bool_t hvm_asid_handle_vmenter(struct hvm_vcpu_asid *asid)
     /* Now guaranteed to be a free ASID. */
     asid->asid = data->next_asid++;
-    asid->generation = data->core_asid_generation;
+    write_atomic(&asid->generation, data->core_asid_generation);
      * When we assign ASID 1, flush all TLB entries as we are starting a new

Xen-devel mailing list

  reply	other threads:[~2020-01-10 16:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-10 16:04 [Xen-devel] [PATCH v2 0/3] x86: improve assisted tlb flush and use it in guest mode Roger Pau Monne
2020-01-10 16:04 ` Roger Pau Monne [this message]
2020-01-10 16:04 ` [Xen-devel] [PATCH v2 2/3] x86/hvm: rework HVMOP_flush_tlbs Roger Pau Monne
2020-01-10 16:04 ` [Xen-devel] [PATCH v2 3/3] x86/tlb: use Xen L0 assisted TLB flush when available Roger Pau Monne
2020-01-10 16:08 ` [Xen-devel] [PATCH v2 0/3] x86: improve assisted tlb flush and use it in guest mode Jan Beulich
2020-01-10 16:14   ` Roger Pau Monné

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:

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

  git send-email \ \ \ \ \ \ \
    --subject='Re: [Xen-devel] [PATCH v2 1/3] x86/hvm: allow ASID flush when v '\!'= current' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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.