Skip to contentSkip to conversation

Introduce VCPUOP_reset_vcpu_info

RFC PATCH Superseded Vitaly Kuznetsov 2 participants 5 messages Aug 14, 2014 – Aug 15, 2014

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Introduce VCPUOP_reset_vcpu_info

The patch and guest code are based on the prototype by Konrad Rzeszutek Wilk.

VCPUOP_reset_vcpu_info is required to support kexec performed by smp pvhvm guest. It was tested with the following guest code:

arch/x86/xen/enlighten.c +16 -6
index 4fd979e..6e8021c 100644
@@ -183,8 +183,6 @@ static void xen_vcpu_setup(int cpu)
 	 * This path is called twice on PVHVM - first during bootup via
 	 * smp_init -> xen_hvm_cpu_notify, and then if the VCPU is being
 	 * hotplugged: cpu_up -> xen_hvm_cpu_notify.
-	 * As we can only do the VCPUOP_register_vcpu_info once lets
-	 * not over-write its result.
 	 *
 	 * For PV it is called during restore (xen_vcpu_restore) and bootup
 	 * (xen_setup_vcpu_info_placement). The hotplug mechanism does not
@@ -210,10 +208,6 @@ static void xen_vcpu_setup(int cpu)
 	/* Check to see if the hypervisor will put the vcpu_info
 	   structure where we want it, which allows direct access via
 	   a percpu-variable.
-	   N.B. This hypercall can _only_ be called once per CPU. Subsequent
-	   calls will error out with -EINVAL. This is due to the fact that
-	   hypervisor has no unregister variant and this hypercall does not
-	   allow to over-write info.mfn and info.offset.
 	 */
 	err = HYPERVISOR_vcpu_op(VCPUOP_register_vcpu_info, cpu, &info);
 
@@ -228,6 +222,22 @@ static void xen_vcpu_setup(int cpu)
 	}
 }
 
+void xen_teardown_vcpu_setup(int cpu)
+{
+	int err;
+
+	if (!have_vcpu_info_placement)
+		return;
+
+	err = HYPERVISOR_vcpu_op(VCPUOP_reset_vcpu_info, cpu, NULL);
+	if (err) {
+		xen_raw_printk("%s: VCPUOP_reset_vcpu_info rc: %d\n", __func__, err);
+		return;
+	}
+	if (cpu < MAX_VIRT_CPUS)
+		per_cpu(xen_vcpu, cpu) = &HYPERVISOR_shared_info->vcpu_info[cpu];
+}
+
 /*
  * On restore, set the vcpu placement up again.
  * If it fails, then we're in a bad state, since
arch/x86/xen/smp.c +14 -0
index bc5e897..7c39a38 100644
@@ -769,10 +769,24 @@ static void xen_hvm_cpu_die(unsigned int cpu)
 #ifdef CONFIG_KEXEC
 void xen_kexec_shutdown(void)
 {
+	int cpu;
+	cpumask_var_t cpu_offline_mask;
+
 	if (!kexec_in_progress)
 		return;
 
+	gnttab_suspend();
+
+	/* Stop all CPUs except for the first one */
+	disable_nonboot_cpus();
+
 	xen_hvm_reset_eventchannels();
+
+	cpumask_andnot(cpu_offline_mask, cpu_present_mask,
+		       cpu_online_mask);
+
+	for_each_cpu(cpu, cpu_offline_mask)
+		xen_teardown_vcpu_setup(cpu);
 }
 #endif
 
arch/x86/xen/xen-ops.h +1 -0
index d083e82..36dd380 100644
@@ -53,6 +53,7 @@ void xen_init_irq_ops(void);
 void xen_setup_timer(int cpu);
 void xen_setup_runstate_info(int cpu);
 void xen_teardown_timer(int cpu);
+void xen_teardown_vcpu_setup(int cpu);
 cycle_t xen_clocksource_read(void);
 void xen_setup_cpu_clockevents(void);
 void __init xen_init_time_ops(void);
include/xen/interface/vcpu.h +2 -0
index b05288c..a0a374c 100644
@@ -172,4 +172,6 @@ DEFINE_GUEST_HANDLE_STRUCT(vcpu_register_vcpu_info);
 
 /* Send an NMI to the specified VCPU. @extra_arg == NULL. */
 #define VCPUOP_send_nmi             11
+
+#define VCPUOP_reset_vcpu_info      14
 #endif /* __XEN_PUBLIC_VCPU_H__ */

Vitaly Kuznetsov (1):
Introduce VCPUOP_reset_vcpu_info

 xen/arch/x86/hvm/hvm.c    |  1 +
 xen/common/domain.c       | 61 +++++++++++++++++++++++++++++++++++++++++++++++
 xen/include/public/vcpu.h | 14 +++++++++++
 3 files changed, 76 insertions(+)
Signature · 1 line
1.9.3
#1 lore raw

RFC PATCH v2 1/1 Introduce VCPUOP_reset_vcpu_info

When an SMP guest performs kexec/kdump it tries issuing VCPUOP_register_vcpu_info. This fails due to vcpu_info already being registered. Introduce new vcpu operation to reset vcpu_info to its default state.

Based on the original patch by Konrad Rzeszutek Wilk.

---
Changes from RFCv1:
- Don't use unsuitable unmap_vcpu_info(), rewrite [Jan Beulich]
- Require FIFO ABI being in 2-level mode
- Describe limitations in include/public/vcpu.h [Jan Beulich]

---
 xen/arch/x86/hvm/hvm.c    |  1 +
 xen/common/domain.c       | 61 +++++++++++++++++++++++++++++++++++++++++++++++
 xen/include/public/vcpu.h | 14 +++++++++++
 3 files changed, 76 insertions(+)
xen/arch/x86/hvm/hvm.c +1 -0
index 216c3f2..7917272 100644
@@ -3332,6 +3332,7 @@ static long hvm_vcpu_op(
     case VCPUOP_set_singleshot_timer:
     case VCPUOP_stop_singleshot_timer:
     case VCPUOP_register_vcpu_info:
+    case VCPUOP_reset_vcpu_info:
     case VCPUOP_register_vcpu_time_memory_area:
         rc = do_vcpu_op(cmd, vcpuid, arg);
         break;
xen/common/domain.c +61 -0

67 lines not on this page · raw message

xen/include/public/vcpu.h +14 -0
index e888daf..81bc1b9 100644
@@ -227,6 +227,20 @@ struct vcpu_register_time_memory_area {
 typedef struct vcpu_register_time_memory_area vcpu_register_time_memory_area_t;
 DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
 
+/*
+ * Reset all of the vcpu_info information from their previous location
+ * to the default one used at bootup. The following prerequisites should be met:
+ *  1. VCPU should be switched off. This means the operation is unsupported for
+ *     boot VCPU.
+ *  2. Domain should not be using FIFO-based event channel ABI. In case it is in
+ *     use domain is supposed to switch back to 2-level ABI with EVTCHNOP_reset.
+ *
+ * After the call vcpu_info is reset to its default state: first
+ * XEN_LEGACY_MAX_VCPUS VCPUs will get it switched to shared_info and all other
+ * VCPUs will get dummy_vcpu_info.
+ */
+#define VCPUOP_reset_vcpu_info   14
+
 #endif /* __XEN_PUBLIC_VCPU_H__ */
 
 /*
Signature · 1 line
1.9.3
#2 lore raw
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 14.08.14 at 10:28, <[email protected]> wrote:

Changes from RFCv1:
- Don't use unsuitable unmap_vcpu_info(), rewrite [Jan Beulich]

I don't think I said that - you now basically open code most what is in that function. Instead I was rather hinting towards adding a flag to the function to adjust the function's behavior to the then two different purposes.

xen/include/public/vcpu.h struct vcpu_register_time_memory_area { · line 234

Quoted 11 lines
xen/include/public/vcpu.h +5 -0
@@ -227,6 +227,20 @@ struct vcpu_register_time_memory_area {
 typedef struct vcpu_register_time_memory_area vcpu_register_time_memory_area_t;
 DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
 
+/*
+ * Reset all of the vcpu_info information from their previous location
+ * to the default one used at bootup. The following prerequisites should be met:
+ *  1. VCPU should be switched off. This means the operation is unsupported for
+ *     boot VCPU.

Boot vCPU? I don't think this should be written more restrictively than it is. Just the one CPU doing the resets can't be resetting itself. With some effort I think one could even get a reset for all of them working.

xen/include/public/vcpu.h struct vcpu_register_time_memory_area { · line 236

Quoted 2 lines
xen/include/public/vcpu.h +2 -0
+ *  2. Domain should not be using FIFO-based event channel ABI. In case it is in
+ *     use domain is supposed to switch back to 2-level ABI with EVTCHNOP_reset.

I'd prefer this to be worded more generically: Avoid mentioning the FIFO ABI, and just require resetting _any_ (current or future) non-default event channel ABI to be switched back to 2-level.

Jan

#3 lore raw
Quoted 9 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 14.08.14 at 10:28, <[email protected]> wrote:

Changes from RFCv1:
- Don't use unsuitable unmap_vcpu_info(), rewrite [Jan Beulich]

I don't think I said that - you now basically open code most what is in that function. Instead I was rather hinting towards adding a flag to the function to adjust the function's behavior to the then two different purposes.

Sorry I misunderstood.. I'll rewrite and send as first non-RFC.

Quoted 6 lines
Quoted 6 lines
xen/include/public/vcpu.h +0 -0
@@ -227,6 +227,20 @@ struct vcpu_register_time_memory_area {
 typedef struct vcpu_register_time_memory_area vcpu_register_time_memory_area_t;
 DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
 
Quoted 10 lines

xen/include/public/vcpu.h struct vcpu_register_time_memory_area { · line 234

Quoted 5 lines
xen/include/public/vcpu.h +5 -0
+/*
+ * Reset all of the vcpu_info information from their previous location
+ * to the default one used at bootup. The following prerequisites should be met:
+ *  1. VCPU should be switched off. This means the operation is unsupported for
+ *     boot VCPU.

Boot vCPU? I don't think this should be written more restrictively than it is. Just the one CPU doing the resets can't be resetting itself. With some effort I think one could even get a reset for all of them working.

I thought about something simillar to what we have in map_vcpu_info:
allow the operation for all offline VCPUs and the current one. But then I realized that boot VCPU doesn't perform VCPUOP_register_vcpu_info in current linux kernel so there is no need to unregister atm..

I'll play with it a bit more.

Quoted 7 lines

xen/include/public/vcpu.h struct vcpu_register_time_memory_area { · line 236

Quoted 3 lines
xen/include/public/vcpu.h +2 -0
+ *  2. Domain should not be using FIFO-based event channel ABI. In case it is in
+ *     use domain is supposed to switch back to 2-level ABI with EVTCHNOP_reset.

I'd prefer this to be worded more generically: Avoid mentioning the FIFO ABI, and just require resetting _any_ (current or future) non-default event channel ABI to be switched back to 2-level.

Sure, thanks!

Quoted 2 lines

Jan

Signature · 1 line
  Vitaly
#4 lore raw
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 15.08.14 at 11:55, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 14.08.14 at 10:28, <[email protected]> wrote:
xen/include/public/vcpu.h +0 -0
@@ -227,6 +227,20 @@ struct vcpu_register_time_memory_area {
 typedef struct vcpu_register_time_memory_area vcpu_register_time_memory_area_t;
 DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
 
Quoted 10 lines

xen/include/public/vcpu.h struct vcpu_register_time_memory_area { · line 234

Quoted 5 lines
xen/include/public/vcpu.h +5 -0
+/*
+ * Reset all of the vcpu_info information from their previous location
+ * to the default one used at bootup. The following prerequisites should be met:
+ *  1. VCPU should be switched off. This means the operation is unsupported for
+ *     boot VCPU.

Boot vCPU? I don't think this should be written more restrictively than it is. Just the one CPU doing the resets can't be resetting itself. With some effort I think one could even get a reset for all of them working.

Quoted 4 lines

I thought about something simillar to what we have in map_vcpu_info:
allow the operation for all offline VCPUs and the current one. But then I realized that boot VCPU doesn't perform VCPUOP_register_vcpu_info in current linux kernel so there is no need to unregister atm..

But you always ought to remember that when your changing hypervisor code or the public interface (including comments) that nothing here should b Linux-centric, i.e. you want to describe abstract behavior here, not how Linux might be making use of it.

Jan