From patchwork Wed Sep 21 02:37: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: 9342713 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 0B6C2607EE 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 1317129651 for ; Wed, 21 Sep 2016 03:10:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08158296C1; 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 3E7B329651 for ; Wed, 21 Sep 2016 03:10:21 +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 1bmXtE-0002hu-FX; Wed, 21 Sep 2016 03:08:04 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bmXtD-0002hj-Va for xen-devel@lists.xen.org; Wed, 21 Sep 2016 03:08:04 +0000 Received: from [85.158.143.35] by server-4.bemta-6.messagelabs.com id 53/FE-29421-399F1E75; Wed, 21 Sep 2016 03:08:03 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrHLMWRWlGSWpSXmKPExsVywNwkVnfSz4f hBkvbzCyWfFzM4sDocXT3b6YAxijWzLyk/IoE1oy/u/8yFsyWqHh39itzA+MF4S5GTg4hgQqJ yws+MIPYEgK8EkeWzWCFsAMkOg8/Y4SoqZfYsP0MG4jNJqAocfDiIbAaEQFpiWufLwPVcHEwC yxglGi8eBRskLCAi8TJfYvBmlkEVCWeXboB1swr4CDxf1Mr1AI5iQ27/4PVcAo4Stxo+8QEsc xB4uHXj+wTGHkXMDKsYtQoTi0qSy3SNbTQSyrKTM8oyU3MzNE1NDDTy00tLk5MT81JTCrWS87 P3cQIDAcGINjBeHNjwCFGSQ4mJVFeOb4H4UJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeLf9eBgu JFiUmp5akZaZAwxMmLQEB4+SCK8QSJq3uCAxtzgzHSJ1ilFRSpy3AiQhAJLIKM2Da4NFwyVGW SlhXkagQ4R4ClKLcjNLUOVfMYpzMCoJ894DmcKTmVcCN/0V0GImoMVbfj4AWVySiJCSamA0+K C2SDSLw2CuC+/6XY6n288Iz/0016x64ffpSxq/X1AtWe5QtGfWy6Xilt7zDi253bXVnN1O9ee JRI+f5+JO3y1el7D9+47/3XMK35V8DJ327/L2JfoddiY7jR77Re1vW7+Ru7TTzPxeiI1u+uoV 2lfmel//YRimXPWl6v8FEbe75if5Cl6uUGIpzkg01GIuKk4EACTNYA2BAgAA X-Env-Sender: feng.wu@intel.com X-Msg-Ref: server-12.tower-21.messagelabs.com!1474427268!34296260!7 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 50339 invoked from network); 21 Sep 2016 03:08:02 -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:08:02 -0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP; 20 Sep 2016 20:08:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.30,371,1470726000"; d="scan'208"; a="1033977623" 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:59 -0700 From: Feng Wu To: xen-devel@lists.xen.org Date: Wed, 21 Sep 2016 10:37:50 +0800 Message-Id: <1474425470-3629-7-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 6/6] VMX: Fixup PI descritpor when cpu is offline 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 cpu is offline, we need to move all the vcpus in its blocking list to another online cpu, this patch handles it. Signed-off-by: Feng Wu --- v4: - Remove the pointless check since we are in machine stop context and no other cpus go down in parallel. xen/arch/x86/hvm/vmx/vmcs.c | 1 + xen/arch/x86/hvm/vmx/vmx.c | 42 +++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/hvm/vmx/vmx.h | 1 + 3 files changed, 44 insertions(+) diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index e733753..9f56c7c 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -578,6 +578,7 @@ void vmx_cpu_dead(unsigned int cpu) vmx_free_vmcs(per_cpu(vmxon_region, cpu)); per_cpu(vmxon_region, cpu) = 0; nvmx_cpu_dead(cpu); + vmx_pi_desc_fixup(cpu); } int vmx_cpu_up(void) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 09262d5..ff87444 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -208,6 +208,48 @@ static void vmx_pi_list_cleanup(struct vcpu *v) vmx_pi_list_remove(v); } +void vmx_pi_desc_fixup(int cpu) +{ + unsigned int new_cpu, dest; + unsigned long flags; + struct arch_vmx_struct *vmx, *tmp; + spinlock_t *new_lock, *old_lock = &per_cpu(vmx_pi_blocking, cpu).lock; + struct list_head *blocked_vcpus = &per_cpu(vmx_pi_blocking, cpu).list; + + if ( !iommu_intpost ) + return; + + spin_lock_irqsave(old_lock, flags); + + list_for_each_entry_safe(vmx, tmp, blocked_vcpus, pi_blocking.list) + { + /* + * We need to find an online cpu as the NDST of the PI descriptor, it + * doesn't matter whether it is within the cpupool of the domain or + * not. As long as it is online, the vCPU will be woken up once the + * notification event arrives. + */ + new_cpu = cpumask_any(&cpu_online_map); + new_lock = &per_cpu(vmx_pi_blocking, new_cpu).lock; + + spin_lock(new_lock); + + ASSERT(vmx->pi_blocking.lock == old_lock); + + dest = cpu_physical_id(new_cpu); + write_atomic(&vmx->pi_desc.ndst, + x2apic_enabled ? dest : MASK_INSR(dest, PI_xAPIC_NDST_MASK)); + + list_move(&vmx->pi_blocking.list, + &per_cpu(vmx_pi_blocking, new_cpu).list); + vmx->pi_blocking.lock = new_lock; + + spin_unlock(new_lock); + } + + spin_unlock_irqrestore(old_lock, flags); +} + /* This function is called when pcidevs_lock is held */ void vmx_pi_hooks_assign(struct domain *d) { diff --git a/xen/include/asm-x86/hvm/vmx/vmx.h b/xen/include/asm-x86/hvm/vmx/vmx.h index 4cdd9b1..9783c70 100644 --- a/xen/include/asm-x86/hvm/vmx/vmx.h +++ b/xen/include/asm-x86/hvm/vmx/vmx.h @@ -569,6 +569,7 @@ void free_p2m_hap_data(struct p2m_domain *p2m); void p2m_init_hap_data(struct p2m_domain *p2m); void vmx_pi_per_cpu_init(unsigned int cpu); +void vmx_pi_desc_fixup(int cpu); void vmx_pi_hooks_assign(struct domain *d); void vmx_pi_hooks_deassign(struct domain *d);