From patchwork Tue Oct 11 00:57:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Feng" X-Patchwork-Id: 9370055 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 B286160487 for ; Tue, 11 Oct 2016 01:31:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABB2528C9D for ; Tue, 11 Oct 2016 01:31:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F75228CB3; Tue, 11 Oct 2016 01:31:01 +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 0B5BD28CB1 for ; Tue, 11 Oct 2016 01:31:01 +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 1btlsB-0005wP-36; Tue, 11 Oct 2016 01:28:51 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1btls9-0005w6-Gu for xen-devel@lists.xen.org; Tue, 11 Oct 2016 01:28:49 +0000 Received: from [85.158.143.35] by server-11.bemta-6.messagelabs.com id E6/C5-08498-0504CF75; Tue, 11 Oct 2016 01:28:48 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrDLMWRWlGSWpSXmKPExsVywNxEWzfA4U+ 4QecdAYslHxezODB6HN39mymAMYo1My8pvyKBNaN/3mLWgh6JikWnPjM3MK4S7mLk5BASqJSY +bGJFcSWEOCVOLJsBpTtL/Hu5l52iJp6iYkNd1lAbDYBRYmDFw+B1YgISEtc+3yZsYuRi4NZY AGjROPFo8wgCWGBUIk5k76ANbAIqEos+t/PBGLzCjhKdDx4yAixQE5iw+7/YDangJPE5LdT2b oYOYCWAdXsZ5/AyLuAkWEVo3pxalFZapGuqV5SUWZ6RkluYmaOrqGBmV5uanFxYnpqTmJSsV5 yfu4mRmAoMADBDsbpl/0PMUpyMCmJ8hYZ/QkX4kvKT6nMSCzOiC8qzUktPsQow8GhJMGrZw+U EyxKTU+tSMvMAQYlTFqCg0dJhDcfJM1bXJCYW5yZDpE6xagoJc7LCZIQAElklObBtcEi4RKjr JQwLyPQIUI8BalFuZklqPKvGMU5GJWEeU1ApvBk5pXATX8FtJgJaDHL4h8gi0sSEVJSDYx5/r N9FnPnJu22+VjYyB7PUsvD9f67y1Xff+UrK0Jjjc+Lykt/d2r+F1/VszI7bi//I2OByP9r0sw 4fqzRPjbX8k9iftTtnyWfRL7r/kmxv2/DtNyp+qHQ+50J7S/aJJuK99cryu0UP9RcmjnjSNT1 VcsULWWdD9n+Nvy1MfJCohLDjuq2BUosxRmJhlrMRcWJAJzD4A9/AgAA X-Env-Sender: feng.wu@intel.com X-Msg-Ref: server-10.tower-21.messagelabs.com!1476149320!30791318!5 X-Originating-IP: [192.55.52.43] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 54668 invoked from network); 11 Oct 2016 01:28:47 -0000 Received: from mga05.intel.com (HELO mga05.intel.com) (192.55.52.43) by server-10.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 11 Oct 2016 01:28:47 -0000 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP; 10 Oct 2016 18:28:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,327,1473145200"; d="scan'208";a="178535727" Received: from feng-bdw-de-pi.bj.intel.com ([10.238.154.57]) by fmsmga004.fm.intel.com with ESMTP; 10 Oct 2016 18:28:46 -0700 From: Feng Wu To: xen-devel@lists.xen.org Date: Tue, 11 Oct 2016 08:57:50 +0800 Message-Id: <1476147473-30970-5-git-send-email-feng.wu@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1476147473-30970-1-git-send-email-feng.wu@intel.com> References: <1476147473-30970-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 v5 4/7] 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 last 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 --- v5: - Use 0xffffffff as the invalid value for NDST field. 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..10976bd 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 = 0xffffffff; } 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 b8b152a..b14c84e 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_do_resume(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, 0xffffffff, + 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; }