Skip to contentSkip to conversation

kvm: s390: pv: Mark mm as protected after the set secure parameters and improve cleanup

PATCH In review Janosch Frank 3 participants 7 messages Oct 30, 2020 – Nov 11, 2020

Subsystems (4)
lore
Share & tools
lore

Janosch Frank

author maintainer
#0 lore raw

PATCH 1/1 kvm: s390: pv: Mark mm as protected after the set secure parameters and improve cleanup

We can only have protected guest pages after a successful set secure parameters call as only then the UV allows imports and unpacks.

By moving the test we can now also check for it in s390_reset_acc() and do an early return if it is 0.

---
 arch/s390/kvm/kvm-s390.c | 2 +-
 arch/s390/kvm/pv.c       | 3 ++-
 arch/s390/mm/gmap.c      | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)
arch/s390/kvm/kvm-s390.c +1 -1
index 6b74b92c1a58..08ea6c4735cd 100644
@@ -2312,7 +2312,7 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd)
 		struct kvm_s390_pv_unp unp = {};
 
 		r = -EINVAL;
-		if (!kvm_s390_pv_is_protected(kvm))
+		if (!kvm_s390_pv_is_protected(kvm) || !mm_is_protected(kvm->mm))
 			break;
 
 		r = -EFAULT;
arch/s390/kvm/pv.c +2 -1
index eb99e2f95ebe..f5847f9dec7c 100644
@@ -208,7 +208,6 @@ int kvm_s390_pv_init_vm(struct kvm *kvm, u16 *rc, u16 *rrc)
 		return -EIO;
 	}
 	kvm->arch.gmap->guest_handle = uvcb.guest_handle;
-	atomic_set(&kvm->mm->context.is_protected, 1);
 	return 0;
 }
 
@@ -228,6 +227,8 @@ int kvm_s390_pv_set_sec_parms(struct kvm *kvm, void *hdr, u64 length, u16 *rc,
 	*rrc = uvcb.header.rrc;
 	KVM_UV_EVENT(kvm, 3, "PROTVIRT VM SET PARMS: rc %x rrc %x",
 		     *rc, *rrc);
+	if (!cc)
+		atomic_set(&kvm->mm->context.is_protected, 1);
 	return cc ? -EINVAL : 0;
 }
 
arch/s390/mm/gmap.c +2 -0
index cfb0017f33a7..64795d034926 100644
@@ -2690,6 +2690,8 @@ static const struct mm_walk_ops reset_acc_walk_ops = {
 #include <linux/sched/mm.h>
 void s390_reset_acc(struct mm_struct *mm)
 {
+	if (!mm_is_protected(mm))
+		return;
 	/*
 	 * we might be called during
 	 * reset:                             we walk the pages and clear
Signature · 1 line
2.25.1
#1 lore raw
Quoted 7 lines · Janosch Frank

We can only have protected guest pages after a successful set secure parameters call as only then the UV allows imports and unpacks.

By moving the test we can now also check for it in s390_reset_acc() and do an early return if it is 0.

Can we check this into devel to give it some test coverage?

Quoted 54 lines
---
 arch/s390/kvm/kvm-s390.c | 2 +-
 arch/s390/kvm/pv.c       | 3 ++-
 arch/s390/mm/gmap.c      | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)
arch/s390/kvm/kvm-s390.c +1 -1
index 6b74b92c1a58..08ea6c4735cd 100644
@@ -2312,7 +2312,7 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd)
 		struct kvm_s390_pv_unp unp = {};
 
 		r = -EINVAL;
-		if (!kvm_s390_pv_is_protected(kvm))
+		if (!kvm_s390_pv_is_protected(kvm) || !mm_is_protected(kvm->mm))
 			break;
 
 		r = -EFAULT;
arch/s390/kvm/pv.c +2 -1
index eb99e2f95ebe..f5847f9dec7c 100644
@@ -208,7 +208,6 @@ int kvm_s390_pv_init_vm(struct kvm *kvm, u16 *rc, u16 *rrc)
 		return -EIO;
 	}
 	kvm->arch.gmap->guest_handle = uvcb.guest_handle;
-	atomic_set(&kvm->mm->context.is_protected, 1);
 	return 0;
 }
 
@@ -228,6 +227,8 @@ int kvm_s390_pv_set_sec_parms(struct kvm *kvm, void *hdr, u64 length, u16 *rc,
 	*rrc = uvcb.header.rrc;
 	KVM_UV_EVENT(kvm, 3, "PROTVIRT VM SET PARMS: rc %x rrc %x",
 		     *rc, *rrc);
+	if (!cc)
+		atomic_set(&kvm->mm->context.is_protected, 1);
 	return cc ? -EINVAL : 0;
 }
 
arch/s390/mm/gmap.c +2 -0
index cfb0017f33a7..64795d034926 100644
@@ -2690,6 +2690,8 @@ static const struct mm_walk_ops reset_acc_walk_ops = {
 #include <linux/sched/mm.h>
 void s390_reset_acc(struct mm_struct *mm)
 {
+	if (!mm_is_protected(mm))
+		return;
 	/*
 	 * we might be called during
 	 * reset:                             we walk the pages and clear
author maintainer
#2 lore raw
Quoted 10 lines · Christian Borntraeger
Quoted 7 lines · Janosch Frank

We can only have protected guest pages after a successful set secure parameters call as only then the UV allows imports and unpacks.

By moving the test we can now also check for it in s390_reset_acc() and do an early return if it is 0.

Can we check this into devel to give it some test coverage?

I think this also lacks:

Fixes 29b40f105ec8 ("KVM: s390: protvirt: Add initial vm and cpu

lifecycle handling")

Quoted 55 lines
Quoted 55 lines
---
 arch/s390/kvm/kvm-s390.c | 2 +-
 arch/s390/kvm/pv.c       | 3 ++-
 arch/s390/mm/gmap.c      | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)
arch/s390/kvm/kvm-s390.c +1 -1
index 6b74b92c1a58..08ea6c4735cd 100644
@@ -2312,7 +2312,7 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd)
 		struct kvm_s390_pv_unp unp = {};
 
 		r = -EINVAL;
-		if (!kvm_s390_pv_is_protected(kvm))
+		if (!kvm_s390_pv_is_protected(kvm) || !mm_is_protected(kvm->mm))
 			break;
 
 		r = -EFAULT;
arch/s390/kvm/pv.c +2 -1
index eb99e2f95ebe..f5847f9dec7c 100644
@@ -208,7 +208,6 @@ int kvm_s390_pv_init_vm(struct kvm *kvm, u16 *rc, u16 *rrc)
 		return -EIO;
 	}
 	kvm->arch.gmap->guest_handle = uvcb.guest_handle;
-	atomic_set(&kvm->mm->context.is_protected, 1);
 	return 0;
 }
 
@@ -228,6 +227,8 @@ int kvm_s390_pv_set_sec_parms(struct kvm *kvm, void *hdr, u64 length, u16 *rc,
 	*rrc = uvcb.header.rrc;
 	KVM_UV_EVENT(kvm, 3, "PROTVIRT VM SET PARMS: rc %x rrc %x",
 		     *rc, *rrc);
+	if (!cc)
+		atomic_set(&kvm->mm->context.is_protected, 1);
 	return cc ? -EINVAL : 0;
 }
 
arch/s390/mm/gmap.c +2 -0
index cfb0017f33a7..64795d034926 100644
@@ -2690,6 +2690,8 @@ static const struct mm_walk_ops reset_acc_walk_ops = {
 #include <linux/sched/mm.h>
 void s390_reset_acc(struct mm_struct *mm)
 {
+	if (!mm_is_protected(mm))
+		return;
 	/*
 	 * we might be called during
 	 * reset:                             we walk the pages and clear
#3 lore raw
Quoted 8 lines · Janosch Frank
Quoted 7 lines · Christian Borntraeger
Quoted 6 lines · Janosch Frank

We can only have protected guest pages after a successful set secure parameters call as only then the UV allows imports and unpacks.

By moving the test we can now also check for it in s390_reset_acc() and do an early return if it is 0.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Can we check this into devel to give it some test coverage?

I think this also lacks:

Fixes 29b40f105ec8 ("KVM: s390: protvirt: Add initial vm and cpu

lifecycle handling")

Yes, it does. I will schedule for kvm/master.

Reviewed-by on v1 1/1
#4 lore raw
In reply to Janosch Frank
Quoted 7 lines · Janosch Frank

We can only have protected guest pages after a successful set secure parameters call as only then the UV allows imports and unpacks.

By moving the test we can now also check for it in s390_reset_acc() and do an early return if it is 0.

Looks sane.

As said in my other mail lets give it some days for the CI to test this.

Quoted 54 lines
---
 arch/s390/kvm/kvm-s390.c | 2 +-
 arch/s390/kvm/pv.c       | 3 ++-
 arch/s390/mm/gmap.c      | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)
arch/s390/kvm/kvm-s390.c +1 -1
index 6b74b92c1a58..08ea6c4735cd 100644
@@ -2312,7 +2312,7 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd)
 		struct kvm_s390_pv_unp unp = {};
 
 		r = -EINVAL;
-		if (!kvm_s390_pv_is_protected(kvm))
+		if (!kvm_s390_pv_is_protected(kvm) || !mm_is_protected(kvm->mm))
 			break;
 
 		r = -EFAULT;
arch/s390/kvm/pv.c +2 -1
index eb99e2f95ebe..f5847f9dec7c 100644
@@ -208,7 +208,6 @@ int kvm_s390_pv_init_vm(struct kvm *kvm, u16 *rc, u16 *rrc)
 		return -EIO;
 	}
 	kvm->arch.gmap->guest_handle = uvcb.guest_handle;
-	atomic_set(&kvm->mm->context.is_protected, 1);
 	return 0;
 }
 
@@ -228,6 +227,8 @@ int kvm_s390_pv_set_sec_parms(struct kvm *kvm, void *hdr, u64 length, u16 *rc,
 	*rrc = uvcb.header.rrc;
 	KVM_UV_EVENT(kvm, 3, "PROTVIRT VM SET PARMS: rc %x rrc %x",
 		     *rc, *rrc);
+	if (!cc)
+		atomic_set(&kvm->mm->context.is_protected, 1);
 	return cc ? -EINVAL : 0;
 }
 
arch/s390/mm/gmap.c +2 -0
index cfb0017f33a7..64795d034926 100644
@@ -2690,6 +2690,8 @@ static const struct mm_walk_ops reset_acc_walk_ops = {
 #include <linux/sched/mm.h>
 void s390_reset_acc(struct mm_struct *mm)
 {
+	if (!mm_is_protected(mm))
+		return;
 	/*
 	 * we might be called during
 	 * reset:                             we walk the pages and clear
author maintainer
#5 lore raw
Quoted 4 lines · Christian Borntraeger
Quoted 3 lines · Janosch Frank

We can only have protected guest pages after a successful set secure parameters call as only then the UV allows imports and unpacks.

Quoted 8 lines
Quoted 4 lines

By moving the test we can now also check for it in s390_reset_acc() and do an early return if it is 0.

Looks sane.

Thanks

Quoted 2 lines

As said in my other mail lets give it some days for the CI to test this.

Sure, I'll push it in a minute

Quoted 55 lines
Quoted 55 lines
---
 arch/s390/kvm/kvm-s390.c | 2 +-
 arch/s390/kvm/pv.c       | 3 ++-
 arch/s390/mm/gmap.c      | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)
arch/s390/kvm/kvm-s390.c +1 -1
index 6b74b92c1a58..08ea6c4735cd 100644
@@ -2312,7 +2312,7 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd)
 		struct kvm_s390_pv_unp unp = {};
 
 		r = -EINVAL;
-		if (!kvm_s390_pv_is_protected(kvm))
+		if (!kvm_s390_pv_is_protected(kvm) || !mm_is_protected(kvm->mm))
 			break;
 
 		r = -EFAULT;
arch/s390/kvm/pv.c +2 -1
index eb99e2f95ebe..f5847f9dec7c 100644
@@ -208,7 +208,6 @@ int kvm_s390_pv_init_vm(struct kvm *kvm, u16 *rc, u16 *rrc)
 		return -EIO;
 	}
 	kvm->arch.gmap->guest_handle = uvcb.guest_handle;
-	atomic_set(&kvm->mm->context.is_protected, 1);
 	return 0;
 }
 
@@ -228,6 +227,8 @@ int kvm_s390_pv_set_sec_parms(struct kvm *kvm, void *hdr, u64 length, u16 *rc,
 	*rrc = uvcb.header.rrc;
 	KVM_UV_EVENT(kvm, 3, "PROTVIRT VM SET PARMS: rc %x rrc %x",
 		     *rc, *rrc);
+	if (!cc)
+		atomic_set(&kvm->mm->context.is_protected, 1);
 	return cc ? -EINVAL : 0;
 }
 
arch/s390/mm/gmap.c +2 -0
index cfb0017f33a7..64795d034926 100644
@@ -2690,6 +2690,8 @@ static const struct mm_walk_ops reset_acc_walk_ops = {
 #include <linux/sched/mm.h>
 void s390_reset_acc(struct mm_struct *mm)
 {
+	if (!mm_is_protected(mm))
+		return;
 	/*
 	 * we might be called during
 	 * reset:                             we walk the pages and clear
Reviewed-by on v1 1/1
#6 lore raw
In reply to Janosch Frank
Quoted 6 lines · On Fri, 30 Oct 2020 10:01:41 -0400 Janosch Frank <[email protected]> wrote:

We can only have protected guest pages after a successful set secure parameters call as only then the UV allows imports and unpacks.

By moving the test we can now also check for it in s390_reset_acc() and do an early return if it is 0.

Quoted 6 lines
---
 arch/s390/kvm/kvm-s390.c | 2 +-
 arch/s390/kvm/pv.c       | 3 ++-
 arch/s390/mm/gmap.c      | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)

Seems reasonable to me. I assume it has been given some coverage by now?