Skip to contentSkip to conversation

KVM: s390: Add new reset vcpu API

PATCH Superseded Janosch Frank 4 participants 6 messages Dec 3, 2019 – Dec 4, 2019

Subsystems (3)

v2 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Janosch Frank

author maintainer
#0 lore raw

PATCH v2 1/1 KVM: s390: Add new reset vcpu API

The architecture states that we need to reset local IRQs for all CPU resets. Because the old reset interface did not support the normal CPU reset we never did that.

Now that we have a new interface, let's properly clear out local IRQs and let this commit be a reminder.

---
 arch/s390/kvm/kvm-s390.c | 13 +++++++++++++
 include/uapi/linux/kvm.h |  4 ++++
 2 files changed, 17 insertions(+)
arch/s390/kvm/kvm-s390.c +13 -0
index d9e6bf3d54f0..602214c5616c 100644
@@ -529,6 +529,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 	case KVM_CAP_S390_CMMA_MIGRATION:
 	case KVM_CAP_S390_AIS:
 	case KVM_CAP_S390_AIS_MIGRATION:
+	case KVM_CAP_S390_VCPU_RESETS:
 		r = 1;
 		break;
 	case KVM_CAP_S390_HPAGE_1M:
@@ -3287,6 +3288,13 @@ static int kvm_arch_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
 	return r;
 }
 
+static int kvm_arch_vcpu_ioctl_normal_reset(struct kvm_vcpu *vcpu)
+{
+	kvm_clear_async_pf_completion_queue(vcpu);
+	kvm_s390_clear_local_irqs(vcpu);
+	return 0;
+}
+
 static int kvm_arch_vcpu_ioctl_initial_reset(struct kvm_vcpu *vcpu)
 {
 	kvm_s390_vcpu_initial_reset(vcpu);
@@ -4363,7 +4371,12 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 		r = kvm_arch_vcpu_ioctl_set_initial_psw(vcpu, psw);
 		break;
 	}
+	case KVM_S390_NORMAL_RESET:
+		r = kvm_arch_vcpu_ioctl_normal_reset(vcpu);
+		break;
 	case KVM_S390_INITIAL_RESET:
+		/* fallthrough */
+	case KVM_S390_CLEAR_RESET:
 		r = kvm_arch_vcpu_ioctl_initial_reset(vcpu);
 		break;
 	case KVM_SET_ONE_REG:
include/uapi/linux/kvm.h +4 -0
index 52641d8ca9e8..f4fc865775a5 100644
@@ -1000,6 +1000,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_PMU_EVENT_FILTER 173
 #define KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 174
 #define KVM_CAP_HYPERV_DIRECT_TLBFLUSH 175
+#define KVM_CAP_S390_VCPU_RESETS 180
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -1461,6 +1462,9 @@ struct kvm_enc_region {
 /* Available with KVM_CAP_ARM_SVE */
 #define KVM_ARM_VCPU_FINALIZE	  _IOW(KVMIO,  0xc2, int)
 
+#define KVM_S390_NORMAL_RESET	_IO(KVMIO,   0xc3)
+#define KVM_S390_CLEAR_RESET    _IO(KVMIO,   0xc4)
+
 /* Secure Encrypted Virtualization command */
 enum sev_cmd_id {
 	/* Guest initialization commands */
Signature · 1 line
2.20.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 65 lines · Janosch Frank

The architecture states that we need to reset local IRQs for all CPU resets. Because the old reset interface did not support the normal CPU reset we never did that.

Now that we have a new interface, let's properly clear out local IRQs and let this commit be a reminder.

---
 arch/s390/kvm/kvm-s390.c | 13 +++++++++++++
 include/uapi/linux/kvm.h |  4 ++++
 2 files changed, 17 insertions(+)
arch/s390/kvm/kvm-s390.c +13 -0
index d9e6bf3d54f0..602214c5616c 100644
@@ -529,6 +529,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 	case KVM_CAP_S390_CMMA_MIGRATION:
 	case KVM_CAP_S390_AIS:
 	case KVM_CAP_S390_AIS_MIGRATION:
+	case KVM_CAP_S390_VCPU_RESETS:
 		r = 1;
 		break;
 	case KVM_CAP_S390_HPAGE_1M:
@@ -3287,6 +3288,13 @@ static int kvm_arch_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
 	return r;
 }
 
+static int kvm_arch_vcpu_ioctl_normal_reset(struct kvm_vcpu *vcpu)
+{
+	kvm_clear_async_pf_completion_queue(vcpu);
+	kvm_s390_clear_local_irqs(vcpu);
+	return 0;
+}
+
 static int kvm_arch_vcpu_ioctl_initial_reset(struct kvm_vcpu *vcpu)
 {
 	kvm_s390_vcpu_initial_reset(vcpu);
@@ -4363,7 +4371,12 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 		r = kvm_arch_vcpu_ioctl_set_initial_psw(vcpu, psw);
 		break;
 	}
+	case KVM_S390_NORMAL_RESET:
+		r = kvm_arch_vcpu_ioctl_normal_reset(vcpu);
+		break;
 	case KVM_S390_INITIAL_RESET:
+		/* fallthrough */
+	case KVM_S390_CLEAR_RESET:
 		r = kvm_arch_vcpu_ioctl_initial_reset(vcpu);
 		break;
 	case KVM_SET_ONE_REG:
include/uapi/linux/kvm.h +1 -0
index 52641d8ca9e8..f4fc865775a5 100644
@@ -1000,6 +1000,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_PMU_EVENT_FILTER 173
 #define KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 174
 #define KVM_CAP_HYPERV_DIRECT_TLBFLUSH 175
+#define KVM_CAP_S390_VCPU_RESETS 180
 
 #ifdef KVM_CAP_IRQ_ROUTING
 

include/uapi/linux/kvm.h struct kvm_enc_region { · line 1464

Quoted 3 lines
include/uapi/linux/kvm.h +0 -0
@@ -1461,6 +1462,9 @@ struct kvm_enc_region {
 /* Available with KVM_CAP_ARM_SVE */
 #define KVM_ARM_VCPU_FINALIZE	  _IOW(KVMIO,  0xc2, int)
 

Maybe also a comment like

"Available with KVM_CAP_S390_VCPU_RESETS" ?

include/uapi/linux/kvm.h struct kvm_enc_region { · line 1470

Quoted 7 lines
include/uapi/linux/kvm.h +3 -0
+#define KVM_S390_NORMAL_RESET	_IO(KVMIO,   0xc3)
+#define KVM_S390_CLEAR_RESET    _IO(KVMIO,   0xc4)
+
 /* Secure Encrypted Virtualization command */
 enum sev_cmd_id {
 	/* Guest initialization commands */
Signature · 3 lines
Thanks,

David / dhildenb
#2 lore raw
In reply to Janosch Frank
Quoted 6 lines · On Tue, 3 Dec 2019 11:20:55 -0500 Janosch Frank <[email protected]> wrote:

The architecture states that we need to reset local IRQs for all CPU resets. Because the old reset interface did not support the normal CPU reset we never did that.

Now that we have a new interface, let's properly clear out local IRQs and let this commit be a reminder.

Well, the new interface did not appear magically, this patch introduces it :) (The whole sentence is a bit confusing; what is this commit supposed to remind us of?)

Quoted 34 lines
---
 arch/s390/kvm/kvm-s390.c | 13 +++++++++++++
 include/uapi/linux/kvm.h |  4 ++++
 2 files changed, 17 insertions(+)
arch/s390/kvm/kvm-s390.c +8 -0
index d9e6bf3d54f0..602214c5616c 100644
@@ -529,6 +529,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 	case KVM_CAP_S390_CMMA_MIGRATION:
 	case KVM_CAP_S390_AIS:
 	case KVM_CAP_S390_AIS_MIGRATION:
+	case KVM_CAP_S390_VCPU_RESETS:
 		r = 1;
 		break;
 	case KVM_CAP_S390_HPAGE_1M:
@@ -3287,6 +3288,13 @@ static int kvm_arch_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
 	return r;
 }
 
+static int kvm_arch_vcpu_ioctl_normal_reset(struct kvm_vcpu *vcpu)
+{
+	kvm_clear_async_pf_completion_queue(vcpu);
+	kvm_s390_clear_local_irqs(vcpu);
+	return 0;
+}
+
 static int kvm_arch_vcpu_ioctl_initial_reset(struct kvm_vcpu *vcpu)
 {
 	kvm_s390_vcpu_initial_reset(vcpu);

arch/s390/kvm/kvm-s390.c long kvm_arch_vcpu_ioctl(struct file *filp, · line 4380

Quoted 10 lines
arch/s390/kvm/kvm-s390.c +5 -0
@@ -4363,7 +4371,12 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 		r = kvm_arch_vcpu_ioctl_set_initial_psw(vcpu, psw);
 		break;
 	}
+	case KVM_S390_NORMAL_RESET:
+		r = kvm_arch_vcpu_ioctl_normal_reset(vcpu);
+		break;
 	case KVM_S390_INITIAL_RESET:
+		/* fallthrough */
+	case KVM_S390_CLEAR_RESET:
 		r = kvm_arch_vcpu_ioctl_initial_reset(vcpu);

The cover letter probably should also mention that clear reset falls back to initial reset for now?

Quoted 15 lines
arch/s390/kvm/kvm-s390.c +0 -0
 		break;
 	case KVM_SET_ONE_REG:
include/uapi/linux/kvm.h +1 -0
index 52641d8ca9e8..f4fc865775a5 100644
@@ -1000,6 +1000,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_PMU_EVENT_FILTER 173
 #define KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 174
 #define KVM_CAP_HYPERV_DIRECT_TLBFLUSH 175
+#define KVM_CAP_S390_VCPU_RESETS 180
 
 #ifdef KVM_CAP_IRQ_ROUTING
 

include/uapi/linux/kvm.h struct kvm_enc_region { · line 1470

Quoted 9 lines
include/uapi/linux/kvm.h +3 -0
@@ -1461,6 +1462,9 @@ struct kvm_enc_region {
 /* Available with KVM_CAP_ARM_SVE */
 #define KVM_ARM_VCPU_FINALIZE	  _IOW(KVMIO,  0xc2, int)
 
+#define KVM_S390_NORMAL_RESET	_IO(KVMIO,   0xc3)
+#define KVM_S390_CLEAR_RESET    _IO(KVMIO,   0xc4)
+
 /* Secure Encrypted Virtualization command */
 enum sev_cmd_id {
 	/* Guest initialization commands */

Looks sane, but please also document the new ioctls and the new cap.

#3 lore raw
In reply to Janosch Frank
Quoted 41 lines · Janosch Frank

The architecture states that we need to reset local IRQs for all CPU resets. Because the old reset interface did not support the normal CPU reset we never did that.

Now that we have a new interface, let's properly clear out local IRQs and let this commit be a reminder.

---
 arch/s390/kvm/kvm-s390.c | 13 +++++++++++++
 include/uapi/linux/kvm.h |  4 ++++
 2 files changed, 17 insertions(+)
arch/s390/kvm/kvm-s390.c +8 -0
index d9e6bf3d54f0..602214c5616c 100644
@@ -529,6 +529,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 	case KVM_CAP_S390_CMMA_MIGRATION:
 	case KVM_CAP_S390_AIS:
 	case KVM_CAP_S390_AIS_MIGRATION:
+	case KVM_CAP_S390_VCPU_RESETS:
 		r = 1;
 		break;
 	case KVM_CAP_S390_HPAGE_1M:
@@ -3287,6 +3288,13 @@ static int kvm_arch_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
 	return r;
 }
 
+static int kvm_arch_vcpu_ioctl_normal_reset(struct kvm_vcpu *vcpu)
+{
+	kvm_clear_async_pf_completion_queue(vcpu);
+	kvm_s390_clear_local_irqs(vcpu);
+	return 0;
+}
+
 static int kvm_arch_vcpu_ioctl_initial_reset(struct kvm_vcpu *vcpu)
 {
 	kvm_s390_vcpu_initial_reset(vcpu);
@@ -4363,7 +4371,12 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 		r = kvm_arch_vcpu_ioctl_set_initial_psw(vcpu, psw);

arch/s390/kvm/kvm-s390.c long kvm_arch_vcpu_ioctl(struct file *filp, · line 4381

Quoted 10 lines
arch/s390/kvm/kvm-s390.c +5 -0
 		break;
 	}
+	case KVM_S390_NORMAL_RESET:
+		r = kvm_arch_vcpu_ioctl_normal_reset(vcpu);
+		break;
 	case KVM_S390_INITIAL_RESET:
+		/* fallthrough */
+	case KVM_S390_CLEAR_RESET:
 		r = kvm_arch_vcpu_ioctl_initial_reset(vcpu);
 		break;

Isn't clear reset supposed to do more than the initial reset? If so, I'd rather expect it the other way round:

	case KVM_S390_CLEAR_RESET:
		/* fallthrough */
	case KVM_S390_INITIAL_RESET:
		r = kvm_arch_vcpu_ioctl_initial_reset(vcpu);
		break;

... so you can later add the additional stuff before the "/* fallthrough */"?

Thomas

author maintainer
#4 lore raw
Quoted 47 lines · Thomas Huth
Quoted 46 lines · Janosch Frank

The architecture states that we need to reset local IRQs for all CPU resets. Because the old reset interface did not support the normal CPU reset we never did that.

Now that we have a new interface, let's properly clear out local IRQs and let this commit be a reminder.

---
 arch/s390/kvm/kvm-s390.c | 13 +++++++++++++
 include/uapi/linux/kvm.h |  4 ++++
 2 files changed, 17 insertions(+)
arch/s390/kvm/kvm-s390.c +11 -0
index d9e6bf3d54f0..602214c5616c 100644
@@ -529,6 +529,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 	case KVM_CAP_S390_CMMA_MIGRATION:
 	case KVM_CAP_S390_AIS:
 	case KVM_CAP_S390_AIS_MIGRATION:
+	case KVM_CAP_S390_VCPU_RESETS:
 		r = 1;
 		break;
 	case KVM_CAP_S390_HPAGE_1M:
@@ -3287,6 +3288,13 @@ static int kvm_arch_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
 	return r;
 }
 
+static int kvm_arch_vcpu_ioctl_normal_reset(struct kvm_vcpu *vcpu)
+{
+	kvm_clear_async_pf_completion_queue(vcpu);
+	kvm_s390_clear_local_irqs(vcpu);
+	return 0;
+}
+
 static int kvm_arch_vcpu_ioctl_initial_reset(struct kvm_vcpu *vcpu)
 {
 	kvm_s390_vcpu_initial_reset(vcpu);
@@ -4363,7 +4371,12 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 		r = kvm_arch_vcpu_ioctl_set_initial_psw(vcpu, psw);
 		break;
 	}
+	case KVM_S390_NORMAL_RESET:
+		r = kvm_arch_vcpu_ioctl_normal_reset(vcpu);
+		break;
Quoted 8 lines

arch/s390/kvm/kvm-s390.c long kvm_arch_vcpu_ioctl(struct file *filp, · line 4381

Quoted 5 lines
arch/s390/kvm/kvm-s390.c +2 -0
 	case KVM_S390_INITIAL_RESET:
+		/* fallthrough */
+	case KVM_S390_CLEAR_RESET:
 		r = kvm_arch_vcpu_ioctl_initial_reset(vcpu);
 		break;

Isn't clear reset supposed to do more than the initial reset? If so, I'd rather expect it the other way round:

In the PV patch I remove the fallthrough and add a function for the clear reset. I add the UV reset calls into the kvm_arch_vcpu_ioctl_*_reset() functions, therefore I can't fallthrough because the Ultravisor does currently not allow staged resets (i.e. first initial then clear if a clear reset is needed)

Quoted 12 lines
	case KVM_S390_CLEAR_RESET:
		/* fallthrough */
	case KVM_S390_INITIAL_RESET:
		r = kvm_arch_vcpu_ioctl_initial_reset(vcpu);
		break;

... so you can later add the additional stuff before the "/* fallthrough */"?

Thomas

#5 lore raw
Quoted 57 lines · Janosch Frank
Quoted 47 lines · Thomas Huth
Quoted 46 lines · Janosch Frank

The architecture states that we need to reset local IRQs for all CPU resets. Because the old reset interface did not support the normal CPU reset we never did that.

Now that we have a new interface, let's properly clear out local IRQs and let this commit be a reminder.

---
 arch/s390/kvm/kvm-s390.c | 13 +++++++++++++
 include/uapi/linux/kvm.h |  4 ++++
 2 files changed, 17 insertions(+)
arch/s390/kvm/kvm-s390.c +11 -0
index d9e6bf3d54f0..602214c5616c 100644
@@ -529,6 +529,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 	case KVM_CAP_S390_CMMA_MIGRATION:
 	case KVM_CAP_S390_AIS:
 	case KVM_CAP_S390_AIS_MIGRATION:
+	case KVM_CAP_S390_VCPU_RESETS:
 		r = 1;
 		break;
 	case KVM_CAP_S390_HPAGE_1M:
@@ -3287,6 +3288,13 @@ static int kvm_arch_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
 	return r;
 }
 
+static int kvm_arch_vcpu_ioctl_normal_reset(struct kvm_vcpu *vcpu)
+{
+	kvm_clear_async_pf_completion_queue(vcpu);
+	kvm_s390_clear_local_irqs(vcpu);
+	return 0;
+}
+
 static int kvm_arch_vcpu_ioctl_initial_reset(struct kvm_vcpu *vcpu)
 {
 	kvm_s390_vcpu_initial_reset(vcpu);
@@ -4363,7 +4371,12 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 		r = kvm_arch_vcpu_ioctl_set_initial_psw(vcpu, psw);
 		break;
 	}
+	case KVM_S390_NORMAL_RESET:
+		r = kvm_arch_vcpu_ioctl_normal_reset(vcpu);
+		break;
Quoted 8 lines

arch/s390/kvm/kvm-s390.c long kvm_arch_vcpu_ioctl(struct file *filp, · line 4381

Quoted 5 lines
arch/s390/kvm/kvm-s390.c +2 -0
 	case KVM_S390_INITIAL_RESET:
+		/* fallthrough */
+	case KVM_S390_CLEAR_RESET:
 		r = kvm_arch_vcpu_ioctl_initial_reset(vcpu);
 		break;

Isn't clear reset supposed to do more than the initial reset? If so, I'd rather expect it the other way round:

Quoted 5 lines

In the PV patch I remove the fallthrough and add a function for the clear reset. I add the UV reset calls into the kvm_arch_vcpu_ioctl_*_reset() functions, therefore I can't fallthrough because the Ultravisor does currently not allow staged resets (i.e. first initial then clear if a clear reset is needed)

Ok, then it's fine. But in case you respin your patch, it's maybe less confusing if you swap it.

Thomas