From: Haozhong Zhang <haozhong.zhang@intel.com>
To: xen-devel@lists.xen.org
Cc: Haozhong Zhang <haozhong.zhang@intel.com>,
Jan Beulich <jbeulich@suse.com>,
Andrew Cooper <andrew.cooper3@citrix.com>
Subject: [PATCH v2 2/3] xen/x86: ensure copying to L1 guest in update_secondary_system_time()
Date: Thu, 23 Feb 2017 17:41:16 +0800 [thread overview]
Message-ID: <20170223094117.7212-2-haozhong.zhang@intel.com> (raw)
In-Reply-To: <20170223094117.7212-1-haozhong.zhang@intel.com>
For a HVM domain, if a vcpu is in the nested guest mode,
__copy_field_to_guest() and __copy_to_guest() used by
update_secondary_system_time() will copy data to L2 guest rather than
L1 guest.
This commit temporally clears the nested guest flag before all
__copy_field_to_guest() and __copy_to_guest() in
update_secondary_system_time(), and restores the flag after those
guest copy operations.
Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
Suggested-by: Jan Beulich <jbeulich@suse.com>
---
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
---
xen/arch/x86/time.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
index 3ad2ab0..cb69dd5 100644
--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -24,6 +24,7 @@
#include <xen/symbols.h>
#include <xen/keyhandler.h>
#include <xen/guest_access.h>
+#include <asm/hvm/nestedhvm.h>
#include <asm/io.h>
#include <asm/msr.h>
#include <asm/mpspec.h>
@@ -992,10 +993,30 @@ bool_t update_secondary_system_time(struct vcpu *v,
{
XEN_GUEST_HANDLE(vcpu_time_info_t) user_u = v->arch.time_info_guest;
smap_check_policy_t saved_policy;
+ bool nested_guest_mode = false;
if ( guest_handle_is_null(user_u) )
return 1;
+ /*
+ * Must be before all following __copy_field_to_guest() and
+ * __copy_to_guest().
+ *
+ * Otherwise, if 'v' is in the nested guest mode, paging_gva_to_gfn() called
+ * from __copy_field_to_guest() and __copy_to_guest() will treat the target
+ * address as L2 gva, and __copy_field_to_guest() and __copy_to_guest() will
+ * consequently copy runstate to L2 guest rather than L1 guest.
+ *
+ * Therefore, we clear the nested guest flag before __copy_field_to_guest()
+ * and __copy_to_guest(), and restore the flag after all guest copy.
+ */
+ if ( nestedhvm_enabled(v->domain) )
+ {
+ nested_guest_mode = nestedhvm_is_n2(v);
+ if ( nested_guest_mode )
+ nestedhvm_vcpu_exit_guestmode(v);
+ }
+
saved_policy = smap_policy_change(v, SMAP_CHECK_ENABLED);
/* 1. Update userspace version. */
@@ -1014,6 +1035,9 @@ bool_t update_secondary_system_time(struct vcpu *v,
smap_policy_change(v, saved_policy);
+ if ( unlikely(nested_guest_mode) )
+ nestedhvm_vcpu_enter_guestmode(v);
+
return 1;
}
--
2.10.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-02-23 9:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-23 9:41 [PATCH v2 1/3] xen/x86: ensure copying to L1 guest in update_runstate_area() Haozhong Zhang
2017-02-23 9:41 ` Haozhong Zhang [this message]
2017-02-24 15:24 ` [PATCH v2 2/3] xen/x86: ensure copying to L1 guest in update_secondary_system_time() Jan Beulich
2017-02-23 9:41 ` [PATCH v2 3/3] x86/hvm: check HAP before enabling nested VMX Haozhong Zhang
2017-02-24 15:27 ` 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=20170223094117.7212-2-haozhong.zhang@intel.com \
--to=haozhong.zhang@intel.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--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 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).