From patchwork Fri May 20 08:53:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Feng" X-Patchwork-Id: 9129007 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 AE5BC6048B for ; Fri, 20 May 2016 09:19:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1A62208C2 for ; Fri, 20 May 2016 09:19:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 963CE2793B; Fri, 20 May 2016 09:19:45 +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 3A1CF208C2 for ; Fri, 20 May 2016 09:19:45 +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 1b3gZC-0006GZ-B8; Fri, 20 May 2016 09:17:58 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b3gZB-0006GC-D8 for xen-devel@lists.xen.org; Fri, 20 May 2016 09:17:57 +0000 Received: from [85.158.139.211] by server-4.bemta-5.messagelabs.com id A5/22-17285-446DE375; Fri, 20 May 2016 09:17:56 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrHLMWRWlGSWpSXmKPExsVywNwkQtflml2 4wYZtghZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa0bP7gtsBculKi7e3s/UwDhNtIuRk0NIoFLi /fbXLCC2hACvxJFlM1ghbH+JeZsbWSFq6iXOT/gMVsMmoChx8OIhsLiIgLTEtc+XGbsYuTiYB U4wSvyeMhMsISzgJvFkZgc7iM0ioCqx/tRGsGZeAUeJX+9PQS2Qk9iw+z8jiM0p4CTx7cIzNo hljhLTH39im8DIu4CRYRWjRnFqUVlqka6hkV5SUWZ6RkluYmaOrqGBqV5uanFxYnpqTmJSsV5 yfu4mRmA4MADBDsa+Wc6HGCU5mJREebkW2IUL8SXlp1RmJBZnxBeV5qQWH2KU4eBQkuCdegUo J1iUmp5akZaZAwxMmLQEB4+SCO8ckDRvcUFibnFmOkTqFKOilDjvDpCEAEgiozQPrg0WDZcYZ aWEeRmBDhHiKUgtys0sQZV/xSjOwagkzLsLZApPZl4J3PRXQIuZgBbfErMBWVySiJCSamC0O7 djo/Xa5VecBbb2dtk3+l4TmGj4sfbVodA3DX5Hd+soechekuqZYsXvI2GXuDHMJ900PoRrxc6 ZHOfkV/uGXQ4K2BDePGH3ZYbjP57euusUJW35XzGwwuZU0pSFElGBtSLNIfVTte/r8tsWiNuI phivOpST1F17wCCidcmDVZYa094/kFViKc5INNRiLipOBAAsq/BfgQIAAA== X-Env-Sender: feng.wu@intel.com X-Msg-Ref: server-11.tower-206.messagelabs.com!1463735872!28446085!2 X-Originating-IP: [192.55.52.88] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjg4ID0+IDM3NDcyNQ==\n X-StarScan-Received: X-StarScan-Version: 8.34; banners=-,-,- X-VirusChecked: Checked Received: (qmail 41793 invoked from network); 20 May 2016 09:17:56 -0000 Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by server-11.tower-206.messagelabs.com with SMTP; 20 May 2016 09:17:56 -0000 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 20 May 2016 02:17:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,338,1459839600"; d="scan'208";a="971023655" Received: from feng-bdw-de-pi.bj.intel.com ([10.238.154.60]) by fmsmga001.fm.intel.com with ESMTP; 20 May 2016 02:17:52 -0700 From: Feng Wu To: xen-devel@lists.xen.org Date: Fri, 20 May 2016 16:53:49 +0800 Message-Id: <1463734431-22353-2-git-send-email-feng.wu@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1463734431-22353-1-git-send-email-feng.wu@intel.com> References: <1463734431-22353-1-git-send-email-feng.wu@intel.com> Cc: kevin.tian@intel.com, keir@xen.org, george.dunlap@eu.citrix.com, andrew.cooper3@citrix.com, dario.faggioli@citrix.com, jbeulich@suse.com, Feng Wu Subject: [Xen-devel] [PATCH 1/3] VMX: Properly adjuest the status of pi descriptor 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 When the last assigned device is dettached from the domain, all the PI related hooks are removed then, however, the vCPU can be blocked, switched to another pCPU, etc, all without the aware of PI. After the next time we attach another device to the domain, which makes the PI realted hooks avaliable again, the status of the pi descriptor is not true, we need to properly adjust it. Signed-off-by: Feng Wu --- xen/arch/x86/hvm/vmx/vmx.c | 29 ++++++++++++++++++++++++++--- xen/include/asm-x86/hvm/vmx/vmcs.h | 1 + 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index bc4410f..3fbc7b1 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -107,12 +107,22 @@ void vmx_pi_per_cpu_init(unsigned int cpu) static void vmx_vcpu_block(struct vcpu *v) { unsigned long flags; - unsigned int dest; + unsigned int dest = cpu_physical_id(v->processor); spinlock_t *old_lock; spinlock_t *pi_blocking_list_lock = &per_cpu(vmx_pi_blocking, v->processor).lock; struct pi_desc *pi_desc = &v->arch.hvm_vmx.pi_desc; + if (v->arch.hvm_vmx.pi_back_from_hotplug == 1) + { + write_atomic(&pi_desc->ndst, + x2apic_enabled ? dest : MASK_INSR(dest, PI_xAPIC_NDST_MASK)); + write_atomic(&pi_desc->nv, posted_intr_vector); + pi_clear_sn(pi_desc); + + v->arch.hvm_vmx.pi_back_from_hotplug = 0; + } + spin_lock_irqsave(pi_blocking_list_lock, flags); old_lock = cmpxchg(&v->arch.hvm_vmx.pi_blocking.lock, NULL, pi_blocking_list_lock); @@ -130,8 +140,6 @@ static void vmx_vcpu_block(struct vcpu *v) ASSERT(!pi_test_sn(pi_desc)); - dest = cpu_physical_id(v->processor); - ASSERT(pi_desc->ndst == (x2apic_enabled ? dest : MASK_INSR(dest, PI_xAPIC_NDST_MASK))); @@ -164,6 +172,16 @@ static void vmx_pi_do_resume(struct vcpu *v) unsigned long flags; spinlock_t *pi_blocking_list_lock; struct pi_desc *pi_desc = &v->arch.hvm_vmx.pi_desc; + unsigned int dest = cpu_physical_id(v->processor); + + if (v->arch.hvm_vmx.pi_back_from_hotplug == 1) + { + write_atomic(&pi_desc->ndst, + x2apic_enabled ? dest : MASK_INSR(dest, PI_xAPIC_NDST_MASK)); + pi_clear_sn(pi_desc); + + v->arch.hvm_vmx.pi_back_from_hotplug = 0; + } ASSERT(!test_bit(_VPF_blocked, &v->pause_flags)); @@ -202,9 +220,14 @@ 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; + for_each_vcpu ( d, v ) + v->arch.hvm_vmx.pi_back_from_hotplug = 1; + ASSERT(!d->arch.hvm_domain.vmx.vcpu_block); d->arch.hvm_domain.vmx.vcpu_block = vmx_vcpu_block; diff --git a/xen/include/asm-x86/hvm/vmx/vmcs.h b/xen/include/asm-x86/hvm/vmx/vmcs.h index b54f52f..3feb60a 100644 --- a/xen/include/asm-x86/hvm/vmx/vmcs.h +++ b/xen/include/asm-x86/hvm/vmx/vmcs.h @@ -231,6 +231,7 @@ struct arch_vmx_struct { * pCPU and wakeup the related vCPU. */ struct pi_blocking_vcpu pi_blocking; + int pi_back_from_hotplug; }; int vmx_create_vmcs(struct vcpu *v);