All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Liu <wl@xen.org>
To: Xen Development List <xen-devel@lists.xenproject.org>
Cc: "Wei Liu" <liuwe@microsoft.com>, "Wei Liu" <wl@xen.org>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Paul Durrant" <pdurrant@amazon.com>,
	"Michael Kelley" <mikelley@microsoft.com>,
	"Jan Beulich" <jbeulich@suse.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [Xen-devel] [PATCH v7 01/10] x86/hypervisor: make hypervisor_ap_setup return an error code
Date: Tue,  4 Feb 2020 15:36:55 +0000	[thread overview]
Message-ID: <20200204153704.15934-2-liuwe@microsoft.com> (raw)
In-Reply-To: <20200204153704.15934-1-liuwe@microsoft.com>

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 <liuwe@microsoft.com>
---
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 */
-- 
2.20.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2020-02-04 15:37 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-04 15:36 [Xen-devel] [PATCH v7 00/10] More Hyper-V infrastructures Wei Liu
2020-02-04 15:36 ` Wei Liu [this message]
2020-02-04 16:48   ` [Xen-devel] [PATCH v7 01/10] x86/hypervisor: make hypervisor_ap_setup return an error code Wei Liu
2020-02-04 16:56     ` Roger Pau Monné
2020-02-04 17:03       ` Wei Liu
2020-02-05 11:12   ` Jan Beulich
2020-02-05 12:09     ` Wei Liu
2020-02-05 12:42       ` Jan Beulich
2020-02-04 15:36 ` [Xen-devel] [PATCH v7 02/10] x86/smp: don't online cpu if hypervisor_ap_setup fails Wei Liu
2020-02-04 15:36 ` [Xen-devel] [PATCH v7 03/10] x86: provide executable fixmap facility Wei Liu
2020-02-05 11:15   ` Jan Beulich
2020-02-04 15:36 ` [Xen-devel] [PATCH v7 04/10] x86/hypervisor: provide hypervisor_fixup_e820 Wei Liu
2020-02-04 15:36 ` [Xen-devel] [PATCH v7 05/10] x86/hyperv: setup hypercall page Wei Liu
2020-02-05 14:04   ` Roger Pau Monné
2020-02-05 15:00     ` Wei Liu
2020-02-05 15:03       ` Wei Liu
2020-02-05 15:52   ` Durrant, Paul
2020-02-04 15:37 ` [Xen-devel] [PATCH v7 06/10] x86/hyperv: provide Hyper-V hypercall functions Wei Liu
2020-02-05 11:17   ` Jan Beulich
2020-02-04 15:37 ` [Xen-devel] [PATCH v7 07/10] DO NOT APPLY: x86/hyperv: issue an hypercall Wei Liu
2020-02-04 15:37 ` [Xen-devel] [PATCH v7 08/10] x86/hyperv: provide percpu hypercall input page Wei Liu
2020-02-04 15:37 ` [Xen-devel] [PATCH v7 09/10] x86/hyperv: retrieve vp_index from Hyper-V Wei Liu
2020-02-04 15:37 ` [Xen-devel] [PATCH v7 10/10] x86/hyperv: setup VP assist page Wei Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200204153704.15934-2-liuwe@microsoft.com \
    --to=wl@xen.org \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=liuwe@microsoft.com \
    --cc=mikelley@microsoft.com \
    --cc=pdurrant@amazon.com \
    --cc=roger.pau@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.