From patchwork Tue Feb 4 15:36:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11364871 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1B48C92A for ; Tue, 4 Feb 2020 15:38:10 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EC7AD20674 for ; Tue, 4 Feb 2020 15:38:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M/0GpiCD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EC7AD20674 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0GK-0001Hh-8h; Tue, 04 Feb 2020 15:37:16 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0GJ-0001HS-9t for xen-devel@lists.xenproject.org; Tue, 04 Feb 2020 15:37:15 +0000 X-Inumbo-ID: 353637f2-4764-11ea-8396-bc764e2007e4 Received: from mail-wm1-x342.google.com (unknown [2a00:1450:4864:20::342]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 353637f2-4764-11ea-8396-bc764e2007e4; Tue, 04 Feb 2020 15:37:10 +0000 (UTC) Received: by mail-wm1-x342.google.com with SMTP id p9so3805562wmc.2 for ; Tue, 04 Feb 2020 07:37:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aG90iG13/0eYUDF/3LrYyCyn+fxbAfySSbQ2wlI3Qww=; b=M/0GpiCDJiLyUaV+iYwQOHlrlkeNvWy3oUJKwGRM3/z7rToX/WpYji61av7hAebDFw i+rQIaCk6ly8GXpov0PbJUeclfq9gyCQeEwMJJhsbh/rNsIQx/l9FFvEQzZFMb6+iCrS jtjqvgx6TJsvE8Sycu62SjuhzS+JrF+pGrPhN0FcJsoEgIYcP+P7yVS3u1VnuUbGgvEp PWR3DiGc5BA+1CfLVsUX51i0whuj37FuOeQqzVr7Z47Lho27z7VsB4u1U6+LuR7nT2rr AxSYj0yH1c/5Lo6T/I8mUeyDZsa0MpCdEFv90DanaswN9jZ8dm4i/9C/MNDeNAFZWTDo LWHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=aG90iG13/0eYUDF/3LrYyCyn+fxbAfySSbQ2wlI3Qww=; b=rjhUbY9hDxDFaBOhL6dEJnZ803hBjr/Hi+Jab+swqroVwYezeaU06kKJjYUqs+3S8L +NDwO1Z2vjLmHZ34lCRNSooLUDCnY2SYEKchZleclS6mRy1add7Yt2/aRVk8RIoDxcL1 8vhTcSJxym0mDjSzrTRWja8DM6IyBrwJXHxaGpqJpiv1ByqBJMshlVrystTCKtSMHuO0 p3aLj5xOj0jgcw/bBnpp8Y1l6sH4QKx/ETG0cJH9qNQGCMtUGFCLhqpULgGVCRfwfV+h gw6aTZ+2Mj6T20AlI6OUSattT/QBAuuc0nW80GjoCR2vGnDOFvplmxCbyXADDBDWEBac c2LQ== X-Gm-Message-State: APjAAAXUN0dafB6hFU8i4kmybIzAdLv/F8Mb94GSYOvz+s7ZumKxf081 ulWZBLi1u5KhY394G46vB6H6IG4woxw= X-Google-Smtp-Source: APXvYqxdp+yJBoBr7Qph0C3n4m9hTqut/78cGrZ/3UpN169IwftMv0hTjrOTj1I5CMCWwKhrbUCInA== X-Received: by 2002:a7b:c1da:: with SMTP id a26mr6831535wmj.155.1580830629750; Tue, 04 Feb 2020 07:37:09 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id p26sm4067143wmc.24.2020.02.04.07.37.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 07:37:09 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Tue, 4 Feb 2020 15:36:55 +0000 Message-Id: <20200204153704.15934-2-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200204153704.15934-1-liuwe@microsoft.com> References: <20200204153704.15934-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v7 01/10] x86/hypervisor: make hypervisor_ap_setup return an error code 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: Wei Liu , Wei Liu , Andrew Cooper , Paul Durrant , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" We want to be able to handle AP setup error in the upper layer. For Xen, remove all panic() and BUG_ON() in init_evtchn and map_vcpuinfo. Only panic/BUG_ON when Xen can't fail gracefully. Signed-off-by: Wei Liu Reviewed-by: Jan Beulich --- v7: 1. Change init_evtchn v6: 1. Change map_vcpuinfo as well 2. Make code shorter --- xen/arch/x86/guest/hypervisor.c | 6 ++- xen/arch/x86/guest/xen/xen.c | 58 ++++++++++++++++---------- xen/include/asm-x86/guest/hypervisor.h | 6 +-- 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c index 4f27b98740..e72c92ffdf 100644 --- a/xen/arch/x86/guest/hypervisor.c +++ b/xen/arch/x86/guest/hypervisor.c @@ -52,10 +52,12 @@ void __init hypervisor_setup(void) ops->setup(); } -void hypervisor_ap_setup(void) +int hypervisor_ap_setup(void) { if ( ops && ops->ap_setup ) - ops->ap_setup(); + return ops->ap_setup(); + + return 0; } void hypervisor_resume(void) diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c index 6dbc5f953f..1cf09886da 100644 --- a/xen/arch/x86/guest/xen/xen.c +++ b/xen/arch/x86/guest/xen/xen.c @@ -113,16 +113,16 @@ static int map_vcpuinfo(void) info.mfn = virt_to_mfn(&vcpu_info[vcpu]); info.offset = (unsigned long)&vcpu_info[vcpu] & ~PAGE_MASK; rc = xen_hypercall_vcpu_op(VCPUOP_register_vcpu_info, vcpu, &info); - if ( rc ) - { - BUG_ON(vcpu >= XEN_LEGACY_MAX_VCPUS); - this_cpu(vcpu_info) = &XEN_shared_info->vcpu_info[vcpu]; - } - else + if ( !rc ) { this_cpu(vcpu_info) = &vcpu_info[vcpu]; set_bit(vcpu, vcpu_info_mapped); } + else if ( vcpu < XEN_LEGACY_MAX_VCPUS ) + { + rc = 0; + this_cpu(vcpu_info) = &XEN_shared_info->vcpu_info[vcpu]; + } return rc; } @@ -202,10 +202,15 @@ static void xen_evtchn_upcall(struct cpu_user_regs *regs) ack_APIC_irq(); } -static void init_evtchn(void) +static int init_evtchn(void) { static uint8_t evtchn_upcall_vector; int rc; + struct xen_hvm_param a = { + .domid = DOMID_SELF, + .index = HVM_PARAM_CALLBACK_IRQ, + .value = 1, + }; if ( !evtchn_upcall_vector ) alloc_direct_apic_vector(&evtchn_upcall_vector, xen_evtchn_upcall); @@ -215,18 +220,19 @@ static void init_evtchn(void) rc = xen_hypercall_set_evtchn_upcall_vector(this_cpu(vcpu_id), evtchn_upcall_vector); if ( rc ) - panic("Unable to set evtchn upcall vector: %d\n", rc); + { + printk("Unable to set evtchn upcall vector: %d\n", rc); + goto out; + } /* Trick toolstack to think we are enlightened */ - { - struct xen_hvm_param a = { - .domid = DOMID_SELF, - .index = HVM_PARAM_CALLBACK_IRQ, - .value = 1, - }; + rc = xen_hypercall_hvm_op(HVMOP_set_param, &a); - BUG_ON(xen_hypercall_hvm_op(HVMOP_set_param, &a)); - } + if ( rc ) + printk("Unable to set HVM_PARAM_CALLBACK_IRQ\n"); + + out: + return rc; } static void __init setup(void) @@ -254,14 +260,20 @@ static void __init setup(void) XEN_LEGACY_MAX_VCPUS); } - init_evtchn(); + BUG_ON(init_evtchn()); } -static void ap_setup(void) +static int ap_setup(void) { + int rc; + set_vcpu_id(); - map_vcpuinfo(); - init_evtchn(); + + rc = map_vcpuinfo(); + if ( rc ) + return rc; + + return init_evtchn(); } int xg_alloc_unused_page(mfn_t *mfn) @@ -283,8 +295,8 @@ int xg_free_unused_page(mfn_t mfn) static void ap_resume(void *unused) { - map_vcpuinfo(); - init_evtchn(); + BUG_ON(map_vcpuinfo()); + BUG_ON(init_evtchn()); } static void resume(void) @@ -303,7 +315,7 @@ static void resume(void) panic("unable to remap vCPU info and vCPUs > legacy limit\n"); /* Setup event channel upcall vector. */ - init_evtchn(); + BUG_ON(init_evtchn()); smp_call_function(ap_resume, NULL, 1); if ( pv_console ) diff --git a/xen/include/asm-x86/guest/hypervisor.h b/xen/include/asm-x86/guest/hypervisor.h index 392f4b90ae..b503854c5b 100644 --- a/xen/include/asm-x86/guest/hypervisor.h +++ b/xen/include/asm-x86/guest/hypervisor.h @@ -25,7 +25,7 @@ struct hypervisor_ops { /* Main setup routine */ void (*setup)(void); /* AP setup */ - void (*ap_setup)(void); + int (*ap_setup)(void); /* Resume from suspension */ void (*resume)(void); }; @@ -34,7 +34,7 @@ struct hypervisor_ops { const char *hypervisor_probe(void); void hypervisor_setup(void); -void hypervisor_ap_setup(void); +int hypervisor_ap_setup(void); void hypervisor_resume(void); #else @@ -44,7 +44,7 @@ void hypervisor_resume(void); static inline const char *hypervisor_probe(void) { return NULL; } static inline void hypervisor_setup(void) { ASSERT_UNREACHABLE(); } -static inline void hypervisor_ap_setup(void) { ASSERT_UNREACHABLE(); } +static inline int hypervisor_ap_setup(void) { ASSERT_UNREACHABLE(); return 0; } static inline void hypervisor_resume(void) { ASSERT_UNREACHABLE(); } #endif /* CONFIG_GUEST */