From patchwork Thu Feb 23 09:41:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9587995 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C4C0360578 for ; Thu, 23 Feb 2017 09:43:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1A8A28613 for ; Thu, 23 Feb 2017 09:43:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A60A52862B; Thu, 23 Feb 2017 09:43:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2FB7E28613 for ; Thu, 23 Feb 2017 09:43:48 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cgpu4-0000Nw-J4; Thu, 23 Feb 2017 09:41:36 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cgpu3-0000NO-LZ for xen-devel@lists.xen.org; Thu, 23 Feb 2017 09:41:35 +0000 Received: from [85.158.139.211] by server-9.bemta-5.messagelabs.com id 93/08-16818-F4EAEA85; Thu, 23 Feb 2017 09:41:35 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrDLMWRWlGSWpSXmKPExsVywNxEW9dv3bo Ig4/LpC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1owVnV0sBX+FKtb23mJvYDzE38XIySEkUCmx /uhXRhBbQoBX4siyGawQtp/EpF2dLF2MXEA1vYwSJ+6tYwdJsAnoS6x4fBCsSERAWuLa58tgz cwC1RITp88Bs4UFYiW+7H7KBmKzCKhKrF/9kgnE5hWwkbjYcpoFYoG8xIWrp4BsDg5OAVuJeR PTIO6xkXh4qI9tAiPvAkaGVYzqxalFZalFuiZ6SUWZ6RkluYmZObqGBqZ6uanFxYnpqTmJScV 6yfm5mxiBocAABDsYb/U5H2KU5GBSEuVlW7kuQogvKT+lMiOxOCO+qDQntfgQowwHh5IEb9pa oJxgUWp6akVaZg4wKGHSEhw8SiK8fCBp3uKCxNzizHSI1ClGRSlx3iyQhABIIqM0D64NFgmXG GWlhHkZgQ4R4ilILcrNLEGVf8UozsGoJMwbAzKFJzOvBG76K6DFTECLLZ3XgiwuSURISTUwrt s/5eGc7Y80NvAXzXircHNp8gej5sk1xrYOyZ2L+uK1LvS/1ttTKyphFbE/XLuuX25l+7y+nRx BvxdKXHd8xaKwQ8U0Qezj19Pfd0awef3WMbIore46qdBTu3KhhbK0CptL3I24huoYjTnxqwVW SppwpvavVX52QIv3yVudm708gtb/rn5RYinOSDTUYi4qTgQARroCOX8CAAA= X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-12.tower-206.messagelabs.com!1487842892!50039680!1 X-Originating-IP: [192.55.52.43] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 8110 invoked from network); 23 Feb 2017 09:41:33 -0000 Received: from mga05.intel.com (HELO mga05.intel.com) (192.55.52.43) by server-12.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 23 Feb 2017 09:41:33 -0000 Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP; 23 Feb 2017 01:41:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,197,1484035200"; d="scan'208";a="69207989" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.133]) by fmsmga006.fm.intel.com with ESMTP; 23 Feb 2017 01:41:30 -0800 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Thu, 23 Feb 2017 17:41:16 +0800 Message-Id: <20170223094117.7212-2-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170223094117.7212-1-haozhong.zhang@intel.com> References: <20170223094117.7212-1-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Jan Beulich , Andrew Cooper Subject: [Xen-devel] [PATCH v2 2/3] xen/x86: ensure copying to L1 guest in update_secondary_system_time() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Suggested-by: Jan Beulich --- Cc: Jan Beulich Cc: Andrew Cooper --- 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 #include #include +#include #include #include #include @@ -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; }