From patchwork Tue May 16 17:29:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luwei Kang X-Patchwork-Id: 9730113 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 4E2E8602DB for ; Wed, 17 May 2017 07:09:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 401CD28715 for ; Wed, 17 May 2017 07:09:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 349352871B; Wed, 17 May 2017 07:09:36 +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=-3.2 required=2.0 tests=BAYES_00, DATE_IN_PAST_12_24, 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 D1D1B28715 for ; Wed, 17 May 2017 07:09:35 +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 1dAt2z-0008AR-D1; Wed, 17 May 2017 07:07:01 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dAt2x-0008AL-QW for xen-devel@lists.xen.org; Wed, 17 May 2017 07:06:59 +0000 Received: from [85.158.139.211] by server-16.bemta-5.messagelabs.com id E1/DF-01752-296FB195; Wed, 17 May 2017 07:06:58 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrKLMWRWlGSWpSXmKPExsXS1tYhoTvpm3S kwcNn4hZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bqZ1fYCnYIVSzacZ+pgfEkXxcjF4eQwHRG iVub5zJ3MXJySAjwShxZNoMVwvaXaFh1khHEFhIolbhw/T0LiM0moC6x9f1GsBoRAWmJa58vg 9UwC4RKnP50lg3EFhawl3j28jRYDYuAqkTrsWnsIDavgIvE3FPvoebLSdw818k8gZF7ASPDKk b14tSistQiXUO9pKLM9IyS3MTMHF1DA1O93NTi4sT01JzEpGK95PzcTYxA79YzMDDuYGzqdT7 EKMnBpCTKu/+BdKQQX1J+SmVGYnFGfFFpTmrxIUYZDg4lCV7Lr0A5waLU9NSKtMwcYJjBpCU4 eJREeLtA0rzFBYm5xZnpEKlTjIpS4rxHQBICIImM0jy4NlhoX2KUlRLmZWRgYBDiKUgtys0sQ ZV/xSjOwagkzCsNMoUnM68EbvoroMVMQIubH4AtLklESEk1MGaY3fD7UxuS/mWpWOh2M/EH11 zM7duvfQvcI/npoITJIY0jy1RE1y8WuqOlzcp/6POsJc2T/81pLPx8+2LzbrZv92Ypt6/klLz IXvk108N7S1F9yFG3wrDXrLkhVrJb+B0uSPSqiorI/RX2tFhas/ba3lts1qs84/JPuXyNu2Sz 8eGPYP6Ni5RYijMSDbWYi4oTAYixXi5oAgAA X-Env-Sender: luwei.kang@intel.com X-Msg-Ref: server-13.tower-206.messagelabs.com!1495004816!83181079!1 X-Originating-IP: [134.134.136.24] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjQgPT4gMzkwOTcx\n X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 31566 invoked from network); 17 May 2017 07:06:58 -0000 Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by server-13.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 17 May 2017 07:06:58 -0000 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 May 2017 00:06:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,353,1491289200"; d="scan'208";a="857736482" Received: from vmm.bj.intel.com ([10.238.135.172]) by FMSMGA003.fm.intel.com with ESMTP; 17 May 2017 00:06:53 -0700 From: Luwei Kang To: xen-devel@lists.xen.org Date: Wed, 17 May 2017 01:29:45 +0800 Message-Id: <1494955785-31546-1-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 2.7.4 Cc: andrew.cooper3@citrix.com, Luwei Kang , jbeulich@suse.com Subject: [Xen-devel] [PATCH] x86/vpmu: add cpu hot unplug notifier for vpmu 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 Currently, hot unplug a cpu with vpmu enabled may cause system hang due to send IPI to a die physical cpu. This patch add a cpu hot unplug notifer to save vpmu context before cpu offline. Consider one scene, hotplug physical cpu N with vpmu is enabled. The vcpu which running on this physical cpu before will be switch to other online cpu. Before load the vpmu context to new physical cpu, a IPI will be send to cpu N to save the vpmu context. System will hang in function on_select_cpus because of that physical cpu is offline and can not do any response. Signed-off-by: Luwei Kang --- xen/arch/x86/cpu/vpmu.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/cpu/vpmu.c b/xen/arch/x86/cpu/vpmu.c index 03401fd..89e0ea8 100644 --- a/xen/arch/x86/cpu/vpmu.c +++ b/xen/arch/x86/cpu/vpmu.c @@ -35,6 +35,7 @@ #include #include #include +#include #include CHECK_pmu_cntr_pair; @@ -835,6 +836,36 @@ long do_xenpmu_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg) return ret; } +static int cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu) +{ + unsigned int cpu = (unsigned long)hcpu; + struct vcpu *vcpu = per_cpu(last_vcpu, cpu); + struct vpmu_struct *vpmu; + + if ( !vcpu ) + return NOTIFY_DONE; + + vpmu = vcpu_vpmu(vcpu); + if ( !vpmu_is_set(vpmu, VPMU_CONTEXT_ALLOCATED) ) + return NOTIFY_DONE; + + switch ( action ) + { + case CPU_DYING: + vpmu_save_force(vcpu); + vpmu_reset(vpmu, VPMU_CONTEXT_LOADED); + break; + default: + break; + } + + return NOTIFY_DONE; +} + +static struct notifier_block vpmu_cpu_nfb = { + .notifier_call = cpu_callback +}; + static int __init vpmu_init(void) { int vendor = current_cpu_data.x86_vendor; @@ -871,10 +902,11 @@ static int __init vpmu_init(void) break; } - if ( vpmu_mode != XENPMU_MODE_OFF ) + if ( vpmu_mode != XENPMU_MODE_OFF ) { + register_cpu_notifier(&vpmu_cpu_nfb); printk(XENLOG_INFO "VPMU: version " __stringify(XENPMU_VER_MAJ) "." __stringify(XENPMU_VER_MIN) "\n"); - else + } else opt_vpmu_enabled = 0; return 0;