From patchwork Tue Apr 2 05:34:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 10881015 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0AFC413B5 for ; Tue, 2 Apr 2019 05:37:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6F902883A for ; Tue, 2 Apr 2019 05:37:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9012288CB; Tue, 2 Apr 2019 05:37:14 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5CB4D2883A for ; Tue, 2 Apr 2019 05:37:14 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hBC4h-00061A-Mi; Tue, 02 Apr 2019 05:35:07 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hBC4g-00060W-79 for xen-devel@lists.xenproject.org; Tue, 02 Apr 2019 05:35:06 +0000 X-Inumbo-ID: 0f6fcac2-5509-11e9-b68a-335cc162ba42 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 0f6fcac2-5509-11e9-b68a-335cc162ba42; Tue, 02 Apr 2019 05:35:01 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id F15D5AF0C; Tue, 2 Apr 2019 05:35:00 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Tue, 2 Apr 2019 07:34:53 +0200 Message-Id: <20190402053457.24912-3-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190402053457.24912-1-jgross@suse.com> References: <20190402053457.24912-1-jgross@suse.com> Subject: [Xen-devel] [PATCH v3 2/6] xen: add helper for calling notifier_call_chain() to common/cpu.c X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add a helper cpu_notifier_call_chain() to call notifier_call_chain() for a cpu with a specified action, returning an errno value. This avoids coding the same pattern multiple times. While at it avoid side effects from using BUG_ON() by not using cpu_online(cpu) as a parameter. Signed-off-by: Juergen Gross Reviewed-by: Dario Faggioli Acked-by: Jan Beulich --- V2: - add nofail parameter to cpu_notifier_call_chain() - avoid side effects from using BUG_ON() macro (Andrew Cooper) --- xen/common/cpu.c | 56 ++++++++++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/xen/common/cpu.c b/xen/common/cpu.c index 836c62f97f..8bf69600a6 100644 --- a/xen/common/cpu.c +++ b/xen/common/cpu.c @@ -71,11 +71,21 @@ void __init register_cpu_notifier(struct notifier_block *nb) spin_unlock(&cpu_add_remove_lock); } +static int cpu_notifier_call_chain(unsigned int cpu, unsigned long action, + struct notifier_block **nb, bool nofail) +{ + void *hcpu = (void *)(long)cpu; + int notifier_rc = notifier_call_chain(&cpu_chain, action, hcpu, nb); + int ret = (notifier_rc == NOTIFY_DONE) ? 0 : notifier_to_errno(notifier_rc); + + BUG_ON(ret && nofail); + + return ret; +} + static void _take_cpu_down(void *unused) { - void *hcpu = (void *)(long)smp_processor_id(); - int notifier_rc = notifier_call_chain(&cpu_chain, CPU_DYING, hcpu, NULL); - BUG_ON(notifier_rc != NOTIFY_DONE); + cpu_notifier_call_chain(smp_processor_id(), CPU_DYING, NULL, true); __cpu_disable(); } @@ -87,8 +97,7 @@ static int take_cpu_down(void *arg) int cpu_down(unsigned int cpu) { - int err, notifier_rc; - void *hcpu = (void *)(long)cpu; + int err; struct notifier_block *nb = NULL; if ( !cpu_hotplug_begin() ) @@ -100,12 +109,9 @@ int cpu_down(unsigned int cpu) return -EINVAL; } - notifier_rc = notifier_call_chain(&cpu_chain, CPU_DOWN_PREPARE, hcpu, &nb); - if ( notifier_rc != NOTIFY_DONE ) - { - err = notifier_to_errno(notifier_rc); + err = cpu_notifier_call_chain(cpu, CPU_DOWN_PREPARE, &nb, false); + if ( err ) goto fail; - } if ( unlikely(system_state < SYS_STATE_active) ) on_selected_cpus(cpumask_of(cpu), _take_cpu_down, NULL, true); @@ -113,26 +119,24 @@ int cpu_down(unsigned int cpu) goto fail; __cpu_die(cpu); - BUG_ON(cpu_online(cpu)); + err = cpu_online(cpu); + BUG_ON(err); - notifier_rc = notifier_call_chain(&cpu_chain, CPU_DEAD, hcpu, NULL); - BUG_ON(notifier_rc != NOTIFY_DONE); + cpu_notifier_call_chain(cpu, CPU_DEAD, NULL, true); send_global_virq(VIRQ_PCPU_STATE); cpu_hotplug_done(); return 0; fail: - notifier_rc = notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED, hcpu, &nb); - BUG_ON(notifier_rc != NOTIFY_DONE); + cpu_notifier_call_chain(cpu, CPU_DOWN_FAILED, &nb, true); cpu_hotplug_done(); return err; } int cpu_up(unsigned int cpu) { - int notifier_rc, err = 0; - void *hcpu = (void *)(long)cpu; + int err; struct notifier_block *nb = NULL; if ( !cpu_hotplug_begin() ) @@ -144,19 +148,15 @@ int cpu_up(unsigned int cpu) return -EINVAL; } - notifier_rc = notifier_call_chain(&cpu_chain, CPU_UP_PREPARE, hcpu, &nb); - if ( notifier_rc != NOTIFY_DONE ) - { - err = notifier_to_errno(notifier_rc); + err = cpu_notifier_call_chain(cpu, CPU_UP_PREPARE, &nb, false); + if ( err ) goto fail; - } err = __cpu_up(cpu); if ( err < 0 ) goto fail; - notifier_rc = notifier_call_chain(&cpu_chain, CPU_ONLINE, hcpu, NULL); - BUG_ON(notifier_rc != NOTIFY_DONE); + cpu_notifier_call_chain(cpu, CPU_ONLINE, NULL, true); send_global_virq(VIRQ_PCPU_STATE); @@ -164,18 +164,14 @@ int cpu_up(unsigned int cpu) return 0; fail: - notifier_rc = notifier_call_chain(&cpu_chain, CPU_UP_CANCELED, hcpu, &nb); - BUG_ON(notifier_rc != NOTIFY_DONE); + cpu_notifier_call_chain(cpu, CPU_UP_CANCELED, &nb, true); cpu_hotplug_done(); return err; } void notify_cpu_starting(unsigned int cpu) { - void *hcpu = (void *)(long)cpu; - int notifier_rc = notifier_call_chain( - &cpu_chain, CPU_STARTING, hcpu, NULL); - BUG_ON(notifier_rc != NOTIFY_DONE); + cpu_notifier_call_chain(cpu, CPU_STARTING, NULL, true); } static cpumask_t frozen_cpus;