From patchwork Wed Sep 21 02:37:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Feng" X-Patchwork-Id: 9342717 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 E0DD6607EE for ; Wed, 21 Sep 2016 03:10:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6E8029651 for ; Wed, 21 Sep 2016 03:10:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA70A29689; Wed, 21 Sep 2016 03:10:24 +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 6844029689 for ; Wed, 21 Sep 2016 03:10:23 +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 1bmXt9-0002gQ-Tl; Wed, 21 Sep 2016 03:07:59 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bmXt8-0002gC-MB for xen-devel@lists.xen.org; Wed, 21 Sep 2016 03:07:58 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id 08/EC-13744-D89F1E75; Wed, 21 Sep 2016 03:07:57 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrHLMWRWlGSWpSXmKPExsVywNwkVrf358N wg8nbFC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1ozfGy4xFZyQqHjftY6tgfGrcBcjJ4eQQIXE sw/zmEFsCQFeiSPLZrBC2AES6w5/Z4WoqZeYMaeVEcRmE1CUOHjxEFhcREBa4trny0BxLg5mg QWMEo0Xj4INEhYIlZh+9xMTiM0ioCqx/PoTFhCbV8BB4seix+wQC+QkNuz+DzaUU8BR4kYbRL 0QUM3Drx/ZJzDyLmBkWMWoUZxaVJZapGtooZdUlJmeUZKbmJmja2hgppebWlycmJ6ak5hUrJe cn7uJERgODECwg/HmxoBDjJIcTEqivHJ8D8KF+JLyUyozEosz4otKc1KLDzHKcHAoSfBu+/Ew XEiwKDU9tSItMwcYmDBpCQ4eJRFeIZA0b3FBYm5xZjpE6hSjopQ4bwVIQgAkkVGaB9cGi4ZLj LJSwryMQIcI8RSkFuVmlqDKv2IU52BUEua9BzKFJzOvBG76K6DFTECLt/x8ALK4JBEhJdXAuE BaRnv2lNVumQfiz2uLPr27w1GgKXtOtUFw8Inrc2rMOCOFX885Ma1DXGJhdOSejoZT02QOXMs NCdhis1uD17D9vW7h0p3Vb3h0Exq3KX/ffEumquPw/ye2Ju/em6zaIGcz1b98qb/9gh5R3y9W SSu2x4h++7ueTff5XtfLnEy+zM6G1kdXKrEUZyQaajEXFScCAMe4WyiBAgAA X-Env-Sender: feng.wu@intel.com X-Msg-Ref: server-12.tower-21.messagelabs.com!1474427268!34296260!5 X-Originating-IP: [192.55.52.93] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjkzID0+IDMyNDY2NQ==\n X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 50237 invoked from network); 21 Sep 2016 03:07:57 -0000 Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by server-12.tower-21.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 21 Sep 2016 03:07:57 -0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP; 20 Sep 2016 20:07:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.30,371,1470726000"; d="scan'208"; a="1033977574" Received: from feng-bdw-de-pi.bj.intel.com ([10.238.154.76]) by orsmga001.jf.intel.com with ESMTP; 20 Sep 2016 20:07:54 -0700 From: Feng Wu To: xen-devel@lists.xen.org Date: Wed, 21 Sep 2016 10:37:48 +0800 Message-Id: <1474425470-3629-5-git-send-email-feng.wu@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1474425470-3629-1-git-send-email-feng.wu@intel.com> References: <1474425470-3629-1-git-send-email-feng.wu@intel.com> Cc: kevin.tian@intel.com, Feng Wu , george.dunlap@eu.citrix.com, andrew.cooper3@citrix.com, dario.faggioli@citrix.com, jbeulich@suse.com Subject: [Xen-devel] [PATCH v4 4/6] VMX: Make sure PI is in proper state before install the hooks 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 We may hit the ASSERT() in vmx_vcpu_block in the current code, since vmx_vcpu_block() may get called before vmx_pi_switch_to() has been installed or executed. Here We use cmpxchg to update the NDST field, this can make sure we only update the NDST when vmx_pi_switch_to() has not been called. So the NDST is in a proper state in vmx_vcpu_block(). Suggested-by: Jan Beulich Signed-off-by: Feng Wu --- v4: - This patch is previously called "Pause/Unpause the domain before/after assigning PI hooks" - Remove the pause/unpause method - Use cmpxchg to update NDST xen/arch/x86/hvm/vmx/vmcs.c | 13 +++++-------- xen/arch/x86/hvm/vmx/vmx.c | 27 ++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 1bd875a..e733753 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -956,16 +956,13 @@ void virtual_vmcs_vmwrite(const struct vcpu *v, u32 vmcs_encoding, u64 val) */ static void pi_desc_init(struct vcpu *v) { - uint32_t dest; - v->arch.hvm_vmx.pi_desc.nv = posted_intr_vector; - dest = cpu_physical_id(v->processor); - - if ( x2apic_enabled ) - v->arch.hvm_vmx.pi_desc.ndst = dest; - else - v->arch.hvm_vmx.pi_desc.ndst = MASK_INSR(dest, PI_xAPIC_NDST_MASK); + /* + * Mark NDST as invalid, then we can use this invalid value as a + * marker to whether update NDST or not in vmx_pi_hooks_assign(). + */ + v->arch.hvm_vmx.pi_desc.ndst = 0xff; } static int construct_vmcs(struct vcpu *v) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 821cba2..09262d5 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -211,14 +211,39 @@ static void vmx_pi_list_cleanup(struct vcpu *v) /* This function is called when pcidevs_lock is held */ void vmx_pi_hooks_assign(struct domain *d) { + struct vcpu *v; + if ( !iommu_intpost || !has_hvm_container_domain(d) ) return; ASSERT(!d->arch.hvm_domain.vmx.vcpu_block); - d->arch.hvm_domain.vmx.vcpu_block = vmx_vcpu_block; + /* + * We carefully handle the timing here: + * - Install the context switch first + * - Then set the NDST field + * - Install the block and resume hooks in the end + * + * This can make sure the PI (especially the NDST feild) is + * in proper state when we call vmx_vcpu_block(). + */ d->arch.hvm_domain.vmx.pi_switch_from = vmx_pi_switch_from; d->arch.hvm_domain.vmx.pi_switch_to = vmx_pi_switch_to; + + for_each_vcpu ( d, v ) + { + unsigned int dest = cpu_physical_id(v->processor); + struct pi_desc *pi_desc = &v->arch.hvm_vmx.pi_desc; + + /* + * We don't need to update NDST if 'arch.hvm_domain.vmx.pi_switch_to' + * already gets called + */ + (void)cmpxchg(&pi_desc->ndst, 0xff, + x2apic_enabled ? dest : MASK_INSR(dest, PI_xAPIC_NDST_MASK)); + } + + d->arch.hvm_domain.vmx.vcpu_block = vmx_vcpu_block; d->arch.hvm_domain.vmx.pi_do_resume = vmx_pi_do_resume; }