xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Subject: [PATCH RFC 38/44] x86/mca: Move __HYPERVISOR_mca IPI parameters off the stack
Date: Thu, 4 Jan 2018 20:22:03 +0000	[thread overview]
Message-ID: <1515097329-31902-39-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1515097329-31902-1-git-send-email-andrew.cooper3@citrix.com>

do_mca() makes several IPI with huge parameter blocks.  All operations are
control-plane, and for debugging/development purposes, so restrict them to
being serialised.  This allows the hypercall parameter block to safely be
static.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/arch/x86/cpu/mcheck/mce.c | 143 +++++++++++++++++++++++++-----------------
 1 file changed, 87 insertions(+), 56 deletions(-)

diff --git a/xen/arch/x86/cpu/mcheck/mce.c b/xen/arch/x86/cpu/mcheck/mce.c
index a8c287d..6e88c64 100644
--- a/xen/arch/x86/cpu/mcheck/mce.c
+++ b/xen/arch/x86/cpu/mcheck/mce.c
@@ -49,18 +49,6 @@ struct mca_banks *mca_allbanks;
 #define SEG_PL(segsel)   ((segsel) & 0x3)
 #define _MC_MSRINJ_F_REQ_HWCR_WREN (1 << 16)
 
-#if 0
-#define x86_mcerr(fmt, err, args...)                                    \
-    ({                                                                  \
-        int _err = (err);                                               \
-        gdprintk(XENLOG_WARNING, "x86_mcerr: " fmt ", returning %d\n",  \
-                 ## args, _err);                                        \
-        _err;                                                           \
-    })
-#else
-#define x86_mcerr(fmt, err, args...) (err)
-#endif
-
 int mce_verbosity;
 static int __init mce_set_verbosity(const char *str)
 {
@@ -1306,8 +1294,11 @@ CHECK_mcinfo_recovery;
 /* Machine Check Architecture Hypercall */
 long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
 {
+    static spinlock_t mca_lock = SPIN_LOCK_UNLOCKED;
+    static struct xen_mc curop;
+
     long ret = 0;
-    struct xen_mc curop, *op = &curop;
+    struct xen_mc *op = &curop;
     struct vcpu *v = current;
     union {
         struct xen_mc_fetch *nat;
@@ -1328,13 +1319,26 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
 
     ret = xsm_do_mca(XSM_PRIV);
     if ( ret )
-        return x86_mcerr("", ret);
+        return ret;
+
+    while ( !spin_trylock(&mca_lock) )
+    {
+        if ( hypercall_preempt_check() )
+            return hypercall_create_continuation(__HYPERVISOR_mca,
+                                                 "h", u_xen_mc);
+    }
 
     if ( copy_from_guest(op, u_xen_mc, 1) )
-        return x86_mcerr("do_mca: failed copyin of xen_mc_t", -EFAULT);
+    {
+        ret = -EFAULT;
+        goto out;
+    }
 
     if ( op->interface_version != XEN_MCA_INTERFACE_VERSION )
-        return x86_mcerr("do_mca: interface version mismatch", -EACCES);
+    {
+        ret = -EACCES;
+        goto out;
+    }
 
     switch ( op->cmd )
     {
@@ -1353,7 +1357,8 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
             break;
 
         default:
-            return x86_mcerr("do_mca fetch: bad cmdflags", -EINVAL);
+            ret = -EINVAL;
+            goto out;
         }
 
         flags = XEN_MC_OK;
@@ -1368,8 +1373,10 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
             if ( !is_pv_32bit_vcpu(v)
                  ? guest_handle_is_null(mc_fetch.nat->data)
                  : compat_handle_is_null(mc_fetch.cmp->data) )
-                return x86_mcerr("do_mca fetch: guest buffer "
-                                 "invalid", -EINVAL);
+            {
+                ret = -EINVAL;
+                goto out;
+            }
 
             mctc = mctelem_consume_oldest_begin(which);
             if ( mctc )
@@ -1402,7 +1409,10 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
         break;
 
     case XEN_MC_notifydomain:
-        return x86_mcerr("do_mca notify unsupported", -EINVAL);
+    {
+        ret = -EINVAL;
+        goto out;
+    }
 
     case XEN_MC_physcpuinfo:
         mc_physcpuinfo.nat = &op->u.mc_physcpuinfo;
@@ -1413,12 +1423,17 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
              : !compat_handle_is_null(mc_physcpuinfo.cmp->info) )
         {
             if ( mc_physcpuinfo.nat->ncpus <= 0 )
-                return x86_mcerr("do_mca cpuinfo: ncpus <= 0",
-                                 -EINVAL);
+            {
+                ret = -EINVAL;
+                goto out;
+            }
             nlcpu = min(nlcpu, (int)mc_physcpuinfo.nat->ncpus);
             log_cpus = xmalloc_array(xen_mc_logical_cpu_t, nlcpu);
             if ( log_cpus == NULL )
-                return x86_mcerr("do_mca cpuinfo", -ENOMEM);
+            {
+                ret = -ENOMEM;
+                goto out;
+            }
             on_each_cpu(do_mc_get_cpu_info, log_cpus, 1);
             if ( !is_pv_32bit_vcpu(v)
                  ? copy_to_guest(mc_physcpuinfo.nat->info, log_cpus, nlcpu)
@@ -1430,26 +1445,27 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
         mc_physcpuinfo.nat->ncpus = nlcpu;
 
         if ( copy_to_guest(u_xen_mc, op, 1) )
-            return x86_mcerr("do_mca cpuinfo", -EFAULT);
-
+            ret = -EFAULT;
         break;
 
     case XEN_MC_msrinject:
         if ( nr_mce_banks == 0 )
-            return x86_mcerr("do_mca inject", -ENODEV);
+        {
+            ret = -ENODEV;
+            goto out;
+        }
 
         mc_msrinject = &op->u.mc_msrinject;
         target = mc_msrinject->mcinj_cpunr;
 
-        if ( target >= nr_cpu_ids )
-            return x86_mcerr("do_mca inject: bad target", -EINVAL);
-
-        if ( !cpu_online(target) )
-            return x86_mcerr("do_mca inject: target offline",
-                             -EINVAL);
+        if ( target >= nr_cpu_ids || !cpu_online(target) )
+        {
+            ret = -EINVAL;
+            goto out;
+        }
 
         if ( mc_msrinject->mcinj_count == 0 )
-            return 0;
+            goto out;
 
         if ( mc_msrinject->mcinj_flags & MC_MSRINJ_F_GPADDR )
         {
@@ -1464,14 +1480,17 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
             domid = (mc_msrinject->mcinj_domid == DOMID_SELF) ?
                     current->domain->domain_id : mc_msrinject->mcinj_domid;
             if ( domid >= DOMID_FIRST_RESERVED )
-                return x86_mcerr("do_mca inject: incompatible flag "
-                                 "MC_MSRINJ_F_GPADDR with domain %d",
-                                 -EINVAL, domid);
+            {
+                ret = -EINVAL;
+                goto out;
+            }
 
             d = get_domain_by_id(domid);
             if ( d == NULL )
-                return x86_mcerr("do_mca inject: bad domain id %d",
-                                 -EINVAL, domid);
+            {
+                ret = -EINVAL;
+                goto out;
+            }
 
             for ( i = 0, msr = &mc_msrinject->mcinj_msr[0];
                   i < mc_msrinject->mcinj_count;
@@ -1485,8 +1504,8 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
                 {
                     put_gfn(d, gfn);
                     put_domain(d);
-                    return x86_mcerr("do_mca inject: bad gfn %#lx of domain %d",
-                                     -EINVAL, gfn, domid);
+                    ret = -EINVAL;
+                    goto out;
                 }
 
                 msr->value = pfn_to_paddr(mfn) | (gaddr & (PAGE_SIZE - 1));
@@ -1498,7 +1517,10 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
         }
 
         if ( !x86_mc_msrinject_verify(mc_msrinject) )
-            return x86_mcerr("do_mca inject: illegal MSR", -EINVAL);
+        {
+            ret = -EINVAL;
+            goto out;
+        }
 
         add_taint(TAINT_ERROR_INJECT);
 
@@ -1509,16 +1531,19 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
 
     case XEN_MC_mceinject:
         if ( nr_mce_banks == 0 )
-            return x86_mcerr("do_mca #MC", -ENODEV);
+        {
+            ret = -ENODEV;
+            goto out;
+        }
 
         mc_mceinject = &op->u.mc_mceinject;
         target = mc_mceinject->mceinj_cpunr;
 
-        if ( target >= nr_cpu_ids )
-            return x86_mcerr("do_mca #MC: bad target", -EINVAL);
-
-        if ( !cpu_online(target) )
-            return x86_mcerr("do_mca #MC: target offline", -EINVAL);
+        if ( target >= nr_cpu_ids || !cpu_online(target) )
+        {
+            ret = -EINVAL;
+            goto out;
+        }
 
         add_taint(TAINT_ERROR_INJECT);
 
@@ -1536,7 +1561,10 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
         bool broadcast = op->u.mc_inject_v2.flags & XEN_MC_INJECT_CPU_BROADCAST;
 
         if ( nr_mce_banks == 0 )
-            return x86_mcerr("do_mca #MC", -ENODEV);
+        {
+            ret = -ENODEV;
+            goto out;
+        }
 
         if ( broadcast )
             cpumap = &cpu_online_map;
@@ -1549,7 +1577,7 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
             if ( !cpumask_intersects(cpumap, &cpu_online_map) )
             {
                 free_cpumask_var(cmv);
-                ret = x86_mcerr("No online CPU passed\n", -EINVAL);
+                ret = -EINVAL;
                 break;
             }
             if ( !cpumask_subset(cpumap, &cpu_online_map) )
@@ -1568,7 +1596,7 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
 
         case XEN_MC_INJECT_TYPE_CMCI:
             if ( !cmci_apic_vector )
-                ret = x86_mcerr("No CMCI supported in platform\n", -EINVAL);
+                ret = -EINVAL;
             else
             {
                 if ( cpumask_test_cpu(smp_processor_id(), cpumap) )
@@ -1580,26 +1608,25 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
         case XEN_MC_INJECT_TYPE_LMCE:
             if ( !lmce_support )
             {
-                ret = x86_mcerr("No LMCE support", -EINVAL);
+                ret = -EINVAL;
                 break;
             }
             if ( broadcast )
             {
-                ret = x86_mcerr("Broadcast cannot be used with LMCE", -EINVAL);
+                ret = -EINVAL;
                 break;
             }
             /* Ensure at most one CPU is specified. */
             if ( nr_cpu_ids > cpumask_next(cpumask_first(cpumap), cpumap) )
             {
-                ret = x86_mcerr("More than one CPU specified for LMCE",
-                                -EINVAL);
+                ret = -EINVAL;
                 break;
             }
             on_selected_cpus(cpumap, x86_mc_mceinject, NULL, 1);
             break;
 
         default:
-            ret = x86_mcerr("Wrong mca type\n", -EINVAL);
+            ret = -EINVAL;
             break;
         }
 
@@ -1610,9 +1637,13 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
     }
 
     default:
-        return x86_mcerr("do_mca: bad command", -EINVAL);
+        ret = -EINVAL;
+        break;
     }
 
+ out:
+    spin_unlock(&mca_lock);
+
     return ret;
 }
 
-- 
2.1.4


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

  parent reply	other threads:[~2018-01-04 20:22 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-04 20:21 [PATCH FAIRLY-RFC 00/44] x86: Prerequisite work for a Xen KAISER solution Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 01/44] passthrough/vtd: Don't DMA to the stack in queue_invalidate_wait() Andrew Cooper
2018-01-05  9:21   ` Jan Beulich
2018-01-05  9:33     ` Andrew Cooper
2018-01-16  6:41   ` Tian, Kevin
2018-01-04 20:21 ` [PATCH RFC 02/44] x86/idt: Factor out enabling and disabling of ISTs Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 03/44] x86/pv: Rename invalidate_shadow_ldt() to pv_destroy_ldt() Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 04/44] x86/boot: Introduce cpu_smpboot_bsp() to dynamically allocate BSP state Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 05/44] x86/boot: Move arch_init_memory() earlier in the boot sequence Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 06/44] x86/boot: Allocate percpu pagetables for the idle vcpus Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 07/44] x86/boot: Use " Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 08/44] x86/pv: Avoid an opencoded mov to %cr3 in toggle_guest_mode() Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 09/44] x86/mm: Track the current %cr3 in a per_cpu variable Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 10/44] x86/pt-shadow: Initial infrastructure for L4 PV pagetable shadowing Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 11/44] x86/pt-shadow: Always set _PAGE_ACCESSED on L4e updates Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 12/44] x86/fixmap: Temporarily add a percpu fixmap range Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 13/44] x86/pt-shadow: Shadow L4 tables from 64bit PV guests Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 14/44] x86/mm: Added safety checks that pagetables aren't shared Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 15/44] x86: Rearrange the virtual layout to introduce a PERCPU linear slot Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 16/44] xen/ipi: Introduce arch_ipi_param_ok() to check IPI parameters Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 17/44] x86/smp: Infrastructure for allocating and freeing percpu pagetables Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 18/44] x86/mm: Maintain the correct percpu mappings on context switch Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 19/44] x86/boot: Defer TSS/IST setup until later during boot on the BSP Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 20/44] x86/smp: Allocate a percpu linear range for the IDT Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 21/44] x86/smp: Switch to using the percpu IDT mappings Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 22/44] x86/mm: Track whether the current cr3 has a short or extended directmap Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 23/44] x86/smp: Allocate percpu resources for map_domain_page() to use Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 24/44] x86/mapcache: Reimplement map_domain_page() from scratch Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 25/44] x86/fixmap: Drop percpu fixmap range Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 26/44] x86/pt-shadow: Maintain a small cache of shadowed frames Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 27/44] x86/smp: Allocate a percpu linear range for the compat translation area Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 28/44] x86/xlat: Use the percpu " Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 29/44] x86/smp: Allocate percpu resources for the GDT and LDT Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 30/44] x86/pv: Break handle_ldt_mapping_fault() out of handle_gdt_ldt_mapping_fault() Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 31/44] x86/pv: Drop support for paging out the LDT Andrew Cooper
2018-01-24 11:04   ` Jan Beulich
2018-01-04 20:21 ` [PATCH RFC 32/44] x86: Always reload the LDT on vcpu context switch Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 33/44] x86/smp: Use the percpu GDT/LDT mappings Andrew Cooper
2018-01-04 20:21 ` [PATCH RFC 34/44] x86: Drop the PERDOMAIN mappings Andrew Cooper
2018-01-04 20:22 ` [PATCH RFC 35/44] x86/smp: Allocate the stack in the percpu range Andrew Cooper
2018-01-04 20:22 ` [PATCH RFC 36/44] x86/monitor: Capture Xen's intent to use monitor at boot time Andrew Cooper
2018-01-04 20:22 ` [PATCH RFC 37/44] x86/misc: Move some IPI parameters off the stack Andrew Cooper
2018-01-04 20:22 ` Andrew Cooper [this message]
2018-01-04 20:22 ` [PATCH RFC 39/44] x86/smp: Introduce get_smp_ipi_buf() and take more " Andrew Cooper
2018-01-04 20:22 ` [PATCH RFC 40/44] x86/boot: Switch the APs to the percpu pagetables before entering C Andrew Cooper
2018-01-04 20:22 ` [PATCH RFC 41/44] x86/smp: Switch to using the percpu stacks Andrew Cooper
2018-01-04 20:22 ` [PATCH RFC 42/44] x86/smp: Allocate a percpu linear range for the TSS Andrew Cooper
2018-01-04 20:22 ` [PATCH RFC 43/44] x86/smp: Use the percpu TSS mapping Andrew Cooper
2018-01-04 20:22 ` [PATCH RFC 44/44] misc debugging Andrew Cooper
2018-01-05  7:48 ` [PATCH FAIRLY-RFC 00/44] x86: Prerequisite work for a Xen KAISER solution Juergen Gross
2018-01-05  9:26   ` Andrew Cooper
2018-01-05  9:39     ` Juergen Gross
2018-01-05  9:56       ` Andrew Cooper
2018-01-05 14:11       ` George Dunlap
2018-01-05 14:17         ` Juergen Gross
2018-01-05 14:21           ` George Dunlap
2018-01-05 14:28             ` Jan Beulich
2018-01-05 14:27         ` Jan Beulich
2018-01-05 14:35           ` Andrew Cooper
2018-01-08 11:41             ` George Dunlap
2018-01-09 23:14   ` Stefano Stabellini

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=1515097329-31902-39-git-send-email-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=xen-devel@lists.xen.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).