From patchwork Tue Oct 11 00:57:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Feng" X-Patchwork-Id: 9370053 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 3E4C260487 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 398B228C9D for ; Tue, 11 Oct 2016 01:31:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D6E628D16; 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 51F6328C9D for ; Tue, 11 Oct 2016 01:30:59 +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 1btlsG-00060i-Ts; Tue, 11 Oct 2016 01:28:56 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1btlsF-0005zX-C6 for xen-devel@lists.xen.org; Tue, 11 Oct 2016 01:28:55 +0000 Received: from [85.158.143.35] by server-1.bemta-6.messagelabs.com id 62/56-01767-6504CF75; Tue, 11 Oct 2016 01:28:54 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrNLMWRWlGSWpSXmKPExsVywNxEWzfM4U+ 4wc/5bBZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8a9lyeYCqZLVXw4sJqpgbFNtIuRg0NIoFLi 0jy7LkZODgkBXokjy2awQtj+Et0ty5lBbCGBeokNk26xg9hsAooSBy8eAqsREZCWuPb5MmMXI xcHs8ACRonGi0fBGoQFXCQaXr4Ba2ARUJWY1XgDLM4r4ChxcdI7FogFchIbdv9nBLE5BZwkJr +dygZxj6NEx372CYy8CxgZVjGqF6cWlaUW6ZrqJRVlpmeU5CZm5ugaGpjp5aYWFyemp+YkJhX rJefnbmIEBgIDEOxgnH7Z/xCjJAeTkihvkdGfcCG+pPyUyozE4oz4otKc1OJDjDIcHEoSvHr2 QDnBotT01Iq0zBxgSMKkJTh4lER480HSvMUFibnFmekQqVOMilLivJwgCQGQREZpHlwbLA4uM cpKCfMyAh0ixFOQWpSbWYIq/4pRnINRSZjXBGQKT2ZeCdz0V0CLmYAWsyz+AbK4JBEhJdXAKP KTL8TkefL9ZOkfuxzOc078fu1uZviDN4K8Z0U9A9mmirke461J6l2yJOCeT7vcyy8V9jqp+52 bXBnq/3jUnk6Wst98uqFi02LpXwLy7NcVLvqV/3wleCTWY3H7lyj1vy+C5XR7D16r2nOTv1ci L2FGfVVus2rou4tL4g4+5/XcGM4VrvNOiaU4I9FQi7moOBEALgPO8H4CAAA= X-Env-Sender: feng.wu@intel.com X-Msg-Ref: server-10.tower-21.messagelabs.com!1476149320!30791318!8 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 54742 invoked from network); 11 Oct 2016 01:28:53 -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:53 -0000 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP; 10 Oct 2016 18:28:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,327,1473145200"; d="scan'208";a="178535743" 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:52 -0700 From: Feng Wu To: xen-devel@lists.xen.org Date: Tue, 11 Oct 2016 08:57:53 +0800 Message-Id: <1476147473-30970-8-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 7/7] VMX: Fixup PI descriptor 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 --- v5: - Add some comments to explain why it doesn't cause deadlock for the ABBA deadlock scenario. xen/arch/x86/hvm/vmx/vmcs.c | 1 + xen/arch/x86/hvm/vmx/vmx.c | 48 +++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/hvm/vmx/vmx.h | 1 + 3 files changed, 50 insertions(+) diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 10976bd..5dd68ca 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 b14c84e..c71d496 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -208,6 +208,54 @@ static void vmx_pi_do_resume(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; + + /* + * We are in the context of CPU_DEAD or CPU_UP_CANCELED notification, + * and it is impossible for a second CPU go down in parallel. So we + * can safely acquire the old cpu's lock and then acquire the new_cpu's + * lock after that. + */ + 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);