Merge tag 'for-linus-4.9-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git...
[cascardo/linux.git] / arch / x86 / xen / enlighten.c
index a637f90..bdd8556 100644 (file)
@@ -118,7 +118,7 @@ DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu);
 DEFINE_PER_CPU(struct vcpu_info, xen_vcpu_info);
 
 /* Linux <-> Xen vCPU id mapping */
-DEFINE_PER_CPU(int, xen_vcpu_id) = -1;
+DEFINE_PER_CPU(uint32_t, xen_vcpu_id);
 EXPORT_PER_CPU_SYMBOL(xen_vcpu_id);
 
 enum xen_domain_type xen_domain_type = XEN_NATIVE;
@@ -1239,7 +1239,6 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
        .write_cr0 = xen_write_cr0,
 
        .read_cr4 = native_read_cr4,
-       .read_cr4_safe = native_read_cr4_safe,
        .write_cr4 = xen_write_cr4,
 
 #ifdef CONFIG_X86_64
@@ -1969,6 +1968,45 @@ static void xen_set_cpu_features(struct cpuinfo_x86 *c)
        }
 }
 
+static void xen_pin_vcpu(int cpu)
+{
+       static bool disable_pinning;
+       struct sched_pin_override pin_override;
+       int ret;
+
+       if (disable_pinning)
+               return;
+
+       pin_override.pcpu = cpu;
+       ret = HYPERVISOR_sched_op(SCHEDOP_pin_override, &pin_override);
+
+       /* Ignore errors when removing override. */
+       if (cpu < 0)
+               return;
+
+       switch (ret) {
+       case -ENOSYS:
+               pr_warn("Unable to pin on physical cpu %d. In case of problems consider vcpu pinning.\n",
+                       cpu);
+               disable_pinning = true;
+               break;
+       case -EPERM:
+               WARN(1, "Trying to pin vcpu without having privilege to do so\n");
+               disable_pinning = true;
+               break;
+       case -EINVAL:
+       case -EBUSY:
+               pr_warn("Physical cpu %d not available for pinning. Check Xen cpu configuration.\n",
+                       cpu);
+               break;
+       case 0:
+               break;
+       default:
+               WARN(1, "rc %d while trying to pin vcpu\n", ret);
+               disable_pinning = true;
+       }
+}
+
 const struct hypervisor_x86 x86_hyper_xen = {
        .name                   = "Xen",
        .detect                 = xen_platform,
@@ -1977,6 +2015,7 @@ const struct hypervisor_x86 x86_hyper_xen = {
 #endif
        .x2apic_available       = xen_x2apic_para_available,
        .set_cpu_features       = xen_set_cpu_features,
+       .pin_vcpu               = xen_pin_vcpu,
 };
 EXPORT_SYMBOL(x86_hyper_xen);