Skip to contentSkip to conversation

s390: uv: small UV fixes

PATCH Superseded Janosch Frank 5 participants 15 messages Jan 19, 2021 – Jan 20, 2021

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Janosch Frank

author maintainer
#0 lore raw

cover s390: uv: small UV fixes

Two small fixes:
* Handle 3d PGMs where the address space id is not known
* Clean up the UV query VCPU number field naming (it's N-1 not N as number in this context means ID)

Janosch Frank (2):
s390: uv: Fix sysfs max number of VCPUs reporting
s390: mm: Fix secure storage access exception handling

 arch/s390/boot/uv.c        |  2 +-
 arch/s390/include/asm/uv.h |  4 ++--
 arch/s390/kernel/uv.c      |  2 +-
 arch/s390/mm/fault.c       | 14 ++++++++++++++
 4 files changed, 18 insertions(+), 4 deletions(-)
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH 1/2 s390: uv: Fix sysfs max number of VCPUs reporting

The number reported by the query is N-1 and I think people reading the sysfs file would expect N instead. For users creating VMs there's no actual difference because KVM's limit is currently below the UV's limit.

The naming of the field is a bit misleading. Number in this context is used like ID and starts at 0. The query field denotes the maximum number that can be put into the VCPU number field in the "create secure CPU" UV call.

Fixes a0f60f8431999 ("s390/protvirt: Add sysfs firmware interface for Ultravisor information")
---
 arch/s390/boot/uv.c        | 2 +-
 arch/s390/include/asm/uv.h | 4 ++--
 arch/s390/kernel/uv.c      | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
arch/s390/boot/uv.c +1 -1
index a15c033f53ca..afb721082989 100644
@@ -35,7 +35,7 @@ void uv_query_info(void)
 		uv_info.guest_cpu_stor_len = uvcb.cpu_stor_len;
 		uv_info.max_sec_stor_addr = ALIGN(uvcb.max_guest_stor_addr, PAGE_SIZE);
 		uv_info.max_num_sec_conf = uvcb.max_num_sec_conf;
-		uv_info.max_guest_cpus = uvcb.max_guest_cpus;
+		uv_info.max_guest_cpu_id = uvcb.max_guest_cpu_num;
 	}
 
 #ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
arch/s390/include/asm/uv.h +2 -2
index 0325fc0469b7..c484c95ea142 100644
@@ -96,7 +96,7 @@ struct uv_cb_qui {
 	u32 max_num_sec_conf;
 	u64 max_guest_stor_addr;
 	u8  reserved88[158 - 136];
-	u16 max_guest_cpus;
+	u16 max_guest_cpu_num;
 	u8  reserveda0[200 - 160];
 } __packed __aligned(8);
 
@@ -273,7 +273,7 @@ struct uv_info {
 	unsigned long guest_cpu_stor_len;
 	unsigned long max_sec_stor_addr;
 	unsigned int max_num_sec_conf;
-	unsigned short max_guest_cpus;
+	unsigned short max_guest_cpu_id;
 };
 
 extern struct uv_info uv_info;
arch/s390/kernel/uv.c +1 -1
index 883bfed9f5c2..b2d2ad153067 100644
@@ -368,7 +368,7 @@ static ssize_t uv_query_max_guest_cpus(struct kobject *kobj,
 				       struct kobj_attribute *attr, char *page)
 {
 	return scnprintf(page, PAGE_SIZE, "%d\n",
-			uv_info.max_guest_cpus);
+			uv_info.max_guest_cpu_id + 1);
 }
 
 static struct kobj_attribute uv_query_max_guest_cpus_attr =
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 1/2] s390: uv: Fix sysfs max number of VCPUs reporting

Quoted 37 lines · Janosch Frank

The number reported by the query is N-1 and I think people reading the sysfs file would expect N instead. For users creating VMs there's no actual difference because KVM's limit is currently below the UV's limit.

The naming of the field is a bit misleading. Number in this context is used like ID and starts at 0. The query field denotes the maximum number that can be put into the VCPU number field in the "create secure CPU" UV call.

Fixes a0f60f8431999 ("s390/protvirt: Add sysfs firmware interface for Ultravisor information")
---
 arch/s390/boot/uv.c        | 2 +-
 arch/s390/include/asm/uv.h | 4 ++--
 arch/s390/kernel/uv.c      | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
arch/s390/boot/uv.c +1 -1
index a15c033f53ca..afb721082989 100644
@@ -35,7 +35,7 @@ void uv_query_info(void)
 		uv_info.guest_cpu_stor_len = uvcb.cpu_stor_len;
 		uv_info.max_sec_stor_addr = ALIGN(uvcb.max_guest_stor_addr, PAGE_SIZE);
 		uv_info.max_num_sec_conf = uvcb.max_num_sec_conf;
-		uv_info.max_guest_cpus = uvcb.max_guest_cpus;
+		uv_info.max_guest_cpu_id = uvcb.max_guest_cpu_num;
 	}
 
 #ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
arch/s390/include/asm/uv.h +0 -0
index 0325fc0469b7..c484c95ea142 100644

arch/s390/include/asm/uv.h struct uv_cb_qui { · line 99

Quoted 5 lines
arch/s390/include/asm/uv.h +1 -1
@@ -96,7 +96,7 @@ struct uv_cb_qui {
 	u32 max_num_sec_conf;
 	u64 max_guest_stor_addr;
 	u8  reserved88[158 - 136];
-	u16 max_guest_cpus;
+	u16 max_guest_cpu_num;

I think it would read better if we name this also max_guest_cpu_id. Otherwise this looks good.

author maintainer
#3 lore raw

Re: [PATCH 1/2] s390: uv: Fix sysfs max number of VCPUs reporting

Quoted 34 lines · Christian Borntraeger
Quoted 31 lines · Janosch Frank

The number reported by the query is N-1 and I think people reading the sysfs file would expect N instead. For users creating VMs there's no actual difference because KVM's limit is currently below the UV's limit.

The naming of the field is a bit misleading. Number in this context is used like ID and starts at 0. The query field denotes the maximum number that can be put into the VCPU number field in the "create secure CPU" UV call.

Fixes a0f60f8431999 ("s390/protvirt: Add sysfs firmware interface for Ultravisor information")
---
 arch/s390/boot/uv.c        | 2 +-
 arch/s390/include/asm/uv.h | 4 ++--
 arch/s390/kernel/uv.c      | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
arch/s390/boot/uv.c +1 -1
index a15c033f53ca..afb721082989 100644
@@ -35,7 +35,7 @@ void uv_query_info(void)
 		uv_info.guest_cpu_stor_len = uvcb.cpu_stor_len;
 		uv_info.max_sec_stor_addr = ALIGN(uvcb.max_guest_stor_addr, PAGE_SIZE);
 		uv_info.max_num_sec_conf = uvcb.max_num_sec_conf;
-		uv_info.max_guest_cpus = uvcb.max_guest_cpus;
+		uv_info.max_guest_cpu_id = uvcb.max_guest_cpu_num;
 	}
 
Quoted 15 lines

arch/s390/include/asm/uv.h struct uv_cb_qui { · line 99

Quoted 11 lines
arch/s390/boot/uv.c +0 -0
 #ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
arch/s390/include/asm/uv.h +1 -1
index 0325fc0469b7..c484c95ea142 100644
@@ -96,7 +96,7 @@ struct uv_cb_qui {
 	u32 max_num_sec_conf;
 	u64 max_guest_stor_addr;
 	u8  reserved88[158 - 136];
-	u16 max_guest_cpus;
+	u16 max_guest_cpu_num;

I think it would read better if we name this also max_guest_cpu_id. Otherwise this looks good.

Yes, but I wanted to have the same name as in the specification. So, what do we value more?

#4 lore raw

Re: [PATCH 1/2] s390: uv: Fix sysfs max number of VCPUs reporting

Quoted 51 lines · Janosch Frank
Quoted 34 lines · Christian Borntraeger
Quoted 31 lines · Janosch Frank

The number reported by the query is N-1 and I think people reading the sysfs file would expect N instead. For users creating VMs there's no actual difference because KVM's limit is currently below the UV's limit.

The naming of the field is a bit misleading. Number in this context is used like ID and starts at 0. The query field denotes the maximum number that can be put into the VCPU number field in the "create secure CPU" UV call.

Fixes a0f60f8431999 ("s390/protvirt: Add sysfs firmware interface for Ultravisor information")
---
 arch/s390/boot/uv.c        | 2 +-
 arch/s390/include/asm/uv.h | 4 ++--
 arch/s390/kernel/uv.c      | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
arch/s390/boot/uv.c +1 -1
index a15c033f53ca..afb721082989 100644
@@ -35,7 +35,7 @@ void uv_query_info(void)
 		uv_info.guest_cpu_stor_len = uvcb.cpu_stor_len;
 		uv_info.max_sec_stor_addr = ALIGN(uvcb.max_guest_stor_addr, PAGE_SIZE);
 		uv_info.max_num_sec_conf = uvcb.max_num_sec_conf;
-		uv_info.max_guest_cpus = uvcb.max_guest_cpus;
+		uv_info.max_guest_cpu_id = uvcb.max_guest_cpu_num;
 	}
 
Quoted 15 lines

arch/s390/include/asm/uv.h struct uv_cb_qui { · line 99

Quoted 11 lines
arch/s390/boot/uv.c +0 -0
 #ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
arch/s390/include/asm/uv.h +1 -1
index 0325fc0469b7..c484c95ea142 100644
@@ -96,7 +96,7 @@ struct uv_cb_qui {
 	u32 max_num_sec_conf;
 	u64 max_guest_stor_addr;
 	u8  reserved88[158 - 136];
-	u16 max_guest_cpus;
+	u16 max_guest_cpu_num;

I think it would read better if we name this also max_guest_cpu_id. Otherwise this looks good.

Quoted 2 lines

Yes, but I wanted to have the same name as in the specification. So, what do we value more?

I think readability is more important. Maybe add a comment in the structure definition that explains it?

maintainer Reviewed-by on v1 1/2
#5 lore raw

Re: [PATCH 1/2] s390: uv: Fix sysfs max number of VCPUs reporting

In reply to Janosch Frank
Quoted 9 lines · On Tue, 19 Jan 2021 05:04:01 -0500 Janosch Frank <[email protected]> wrote:

The number reported by the query is N-1 and I think people reading the sysfs file would expect N instead. For users creating VMs there's no actual difference because KVM's limit is currently below the UV's limit.

The naming of the field is a bit misleading. Number in this context is used like ID and starts at 0. The query field denotes the maximum number that can be put into the VCPU number field in the "create secure CPU" UV call.

once you address Christian's comments:

Quoted 58 lines
Fixes a0f60f8431999 ("s390/protvirt: Add sysfs firmware interface

for Ultravisor information") Cc: [email protected]

---
 arch/s390/boot/uv.c        | 2 +-
 arch/s390/include/asm/uv.h | 4 ++--
 arch/s390/kernel/uv.c      | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
arch/s390/boot/uv.c +0 -0
index a15c033f53ca..afb721082989 100644
@@ -35,7 +35,7 @@ void uv_query_info(void)
 		uv_info.guest_cpu_stor_len = uvcb.cpu_stor_len;
 		uv_info.max_sec_stor_addr =

ALIGN(uvcb.max_guest_stor_addr, PAGE_SIZE); uv_info.max_num_sec_conf = uvcb.max_num_sec_conf;

arch/s390/boot/uv.c +1 -1
-		uv_info.max_guest_cpus = uvcb.max_guest_cpus;
+		uv_info.max_guest_cpu_id = uvcb.max_guest_cpu_num;
 	}
 
 #ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
arch/s390/include/asm/uv.h +2 -2
index 0325fc0469b7..c484c95ea142 100644
@@ -96,7 +96,7 @@ struct uv_cb_qui {
 	u32 max_num_sec_conf;
 	u64 max_guest_stor_addr;
 	u8  reserved88[158 - 136];
-	u16 max_guest_cpus;
+	u16 max_guest_cpu_num;
 	u8  reserveda0[200 - 160];
 } __packed __aligned(8);
 
@@ -273,7 +273,7 @@ struct uv_info {
 	unsigned long guest_cpu_stor_len;
 	unsigned long max_sec_stor_addr;
 	unsigned int max_num_sec_conf;
-	unsigned short max_guest_cpus;
+	unsigned short max_guest_cpu_id;
 };
 
 extern struct uv_info uv_info;
arch/s390/kernel/uv.c +1 -1
index 883bfed9f5c2..b2d2ad153067 100644
@@ -368,7 +368,7 @@ static ssize_t uv_query_max_guest_cpus(struct
 kobject *kobj, struct kobj_attribute *attr, char *page)
 {
 	return scnprintf(page, PAGE_SIZE, "%d\n",
-			uv_info.max_guest_cpus);
+			uv_info.max_guest_cpu_id + 1);
 }
 
 static struct kobj_attribute uv_query_max_guest_cpus_attr =
Acked-by on v1 1/2
#6 lore raw

Re: [PATCH 1/2] s390: uv: Fix sysfs max number of VCPUs reporting

In reply to Janosch Frank
Quoted 10 lines · On Tue, 19 Jan 2021 05:04:01 -0500 Janosch Frank <[email protected]> wrote:

The number reported by the query is N-1 and I think people reading the sysfs file would expect N instead. For users creating VMs there's no actual difference because KVM's limit is currently below the UV's limit.

The naming of the field is a bit misleading. Number in this context is used like ID and starts at 0. The query field denotes the maximum number that can be put into the VCPU number field in the "create secure CPU" UV call.

Quoted 8 lines
Fixes a0f60f8431999 ("s390/protvirt: Add sysfs firmware interface for Ultravisor information")
---
 arch/s390/boot/uv.c        | 2 +-
 arch/s390/include/asm/uv.h | 4 ++--
 arch/s390/kernel/uv.c      | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
author maintainer
#7 lore raw

PATCH 2/2 s390: mm: Fix secure storage access exception handling

In reply to Janosch Frank

Turns out that the bit 61 in the TEID is not always 1 and if that's the case the address space ID and the address are unpredictable. Without an address and it's address space ID we can't export memory and hence we can only send a SIGSEGV to the process or panic the kernel depending on who caused the exception.

Fixes 084ea4d611a3d ("s390/mm: add (non)secure page access exceptions handlers")
---
 arch/s390/mm/fault.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/s390/mm/fault.c +14 -0
index e30c7c781172..5442937e5b4b 100644
@@ -791,6 +791,20 @@ void do_secure_storage_access(struct pt_regs *regs)
 	struct page *page;
 	int rc;
 
+	/* There are cases where we don't have a TEID. */
+	if (!(regs->int_parm_long & 0x4)) {
+		/*
+		 * Userspace could for example try to execute secure
+		 * storage and trigger this. We should tell it that it
+		 * shouldn't do that.
+		 */
+		if (user_mode(regs)) {
+			send_sig(SIGSEGV, current, 0);
+			return;
+		} else
+			panic("Unexpected PGM 0x3d with TEID bit 61=0");
+	}
+
 	switch (get_fault_type(regs)) {
 	case USER_FAULT:
 		mm = current->mm;
Signature · 1 line
2.25.1
Reviewed-by on v1 2/2
#8 lore raw

Re: [PATCH 2/2] s390: mm: Fix secure storage access exception handling

Quoted 9 lines · Janosch Frank

Turns out that the bit 61 in the TEID is not always 1 and if that's the case the address space ID and the address are unpredictable. Without an address and it's address space ID we can't export memory and hence we can only send a SIGSEGV to the process or panic the kernel depending on who caused the exception.

Fixes 084ea4d611a3d ("s390/mm: add (non)secure page access exceptions handlers")

some small things to consider (or to reject)

Quoted 9 lines
---
 arch/s390/mm/fault.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/s390/mm/fault.c +0 -0
index e30c7c781172..5442937e5b4b 100644

arch/s390/mm/fault.c void do_secure_storage_access(struct pt_regs *regs) · line 799

Quoted 9 lines
arch/s390/mm/fault.c +6 -0
@@ -791,6 +791,20 @@ void do_secure_storage_access(struct pt_regs *regs)
 	struct page *page;
 	int rc;
 
+	/* There are cases where we don't have a TEID. */
+	if (!(regs->int_parm_long & 0x4)) {
+		/*
+		 * Userspace could for example try to execute secure
+		 * storage and trigger this. We should tell it that it
+		 * shouldn't do that.

Maybe something like
/*
* when this happens, userspace did something that it
* was not supposed to do, e.g. branching into secure
* secure memory. Trigger a segmentation fault.

arch/s390/mm/fault.c void do_secure_storage_access(struct pt_regs *regs) · line 805

Quoted 6 lines
arch/s390/mm/fault.c +6 -0
+		 */
+		if (user_mode(regs)) {
+			send_sig(SIGSEGV, current, 0);
+			return;
+		} else
+			panic("Unexpected PGM 0x3d with TEID bit 61=0");

use BUG instead of panic? That would kill this process, but it allows people to maybe save unaffected data.

author maintainer
#9 lore raw

Re: [PATCH 2/2] s390: mm: Fix secure storage access exception handling

Quoted 9 lines · Christian Borntraeger
Quoted 6 lines · Janosch Frank

Turns out that the bit 61 in the TEID is not always 1 and if that's the case the address space ID and the address are unpredictable. Without an address and it's address space ID we can't export memory and hence we can only send a SIGSEGV to the process or panic the kernel depending on who caused the exception.

Quoted 5 lines
Quoted 3 lines
Fixes 084ea4d611a3d ("s390/mm: add (non)secure page access exceptions handlers")

Thanks!

Quoted 27 lines

some small things to consider (or to reject)

Quoted 9 lines
---
 arch/s390/mm/fault.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/s390/mm/fault.c +0 -0
index e30c7c781172..5442937e5b4b 100644

arch/s390/mm/fault.c void do_secure_storage_access(struct pt_regs *regs) · line 799

Quoted 9 lines
arch/s390/mm/fault.c +6 -0
@@ -791,6 +791,20 @@ void do_secure_storage_access(struct pt_regs *regs)
 	struct page *page;
 	int rc;
 
+	/* There are cases where we don't have a TEID. */
+	if (!(regs->int_parm_long & 0x4)) {
+		/*
+		 * Userspace could for example try to execute secure
+		 * storage and trigger this. We should tell it that it
+		 * shouldn't do that.

Maybe something like
/*
* when this happens, userspace did something that it
* was not supposed to do, e.g. branching into secure
* secure memory. Trigger a segmentation fault.

Quoted 1 line

arch/s390/mm/fault.c void do_secure_storage_access(struct pt_regs *regs) · line 800

Quoted 1 line
arch/s390/mm/fault.c +1 -0
+		 */

Sounds good

Quoted 8 lines

arch/s390/mm/fault.c void do_secure_storage_access(struct pt_regs *regs) · line 805

Quoted 5 lines
arch/s390/mm/fault.c +5 -0
+		if (user_mode(regs)) {
+			send_sig(SIGSEGV, current, 0);
+			return;
+		} else
+			panic("Unexpected PGM 0x3d with TEID bit 61=0");

use BUG instead of panic? That would kill this process, but it allows people to maybe save unaffected data.

That would make sense, will do

Reviewed-by
#10 lore raw

Re: [PATCH 2/2] s390: mm: Fix secure storage access exception handling

Quoted 10 lines · On Tue, 19 Jan 2021 11:38:10 +0100 Janosch Frank <[email protected]> wrote:
Quoted 9 lines · Christian Borntraeger
Quoted 6 lines · Janosch Frank

Turns out that the bit 61 in the TEID is not always 1 and if that's the case the address space ID and the address are unpredictable. Without an address and it's address space ID we can't export memory and hence we can only send a SIGSEGV to the process or panic the kernel depending on who caused the exception.

Quoted 33 lines
Quoted 5 lines
Quoted 3 lines
Fixes 084ea4d611a3d ("s390/mm: add (non)secure page access exceptions handlers")

Thanks!

Quoted 25 lines

some small things to consider (or to reject)

Quoted 9 lines
---
 arch/s390/mm/fault.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/s390/mm/fault.c +0 -0
index e30c7c781172..5442937e5b4b 100644

arch/s390/mm/fault.c void do_secure_storage_access(struct pt_regs *regs) · line 799

Quoted 9 lines
arch/s390/mm/fault.c +6 -0
@@ -791,6 +791,20 @@ void do_secure_storage_access(struct pt_regs *regs)
 	struct page *page;
 	int rc;
 
+	/* There are cases where we don't have a TEID. */
+	if (!(regs->int_parm_long & 0x4)) {
+		/*
+		 * Userspace could for example try to execute secure
+		 * storage and trigger this. We should tell it that it
+		 * shouldn't do that.  

Maybe something like

		/*
		 * when this happens, userspace did something that it

s/when/When/ :)

Quoted 15 lines
Quoted 3 lines

* was not supposed to do, e.g. branching into secure
* secure memory. Trigger a segmentation fault.

arch/s390/mm/fault.c void do_secure_storage_access(struct pt_regs *regs) · line 800

Quoted 1 line
arch/s390/mm/fault.c +1 -0
+		 */  

Sounds good

Quoted 8 lines

arch/s390/mm/fault.c void do_secure_storage_access(struct pt_regs *regs) · line 805

Quoted 5 lines
arch/s390/mm/fault.c +5 -0
+		if (user_mode(regs)) {
+			send_sig(SIGSEGV, current, 0);
+			return;
+		} else
+			panic("Unexpected PGM 0x3d with TEID bit 61=0");  

use BUG instead of panic? That would kill this process, but it allows people to maybe save unaffected data.

Quoted 1 line

That would make sense, will do

With BUG():

maintainer
#11 lore raw

Re: [PATCH 2/2] s390: mm: Fix secure storage access exception handling

In reply to Christian Borntraeger
Quoted 8 lines · Christian Borntraeger

arch/s390/mm/fault.c void do_secure_storage_access(struct pt_regs *regs) · line 805

Quoted 5 lines
arch/s390/mm/fault.c +5 -0
+		if (user_mode(regs)) {
+			send_sig(SIGSEGV, current, 0);
+			return;
+		} else
+			panic("Unexpected PGM 0x3d with TEID bit 61=0");

use BUG instead of panic? That would kill this process, but it allows people to maybe save unaffected data.

It would kill the process, and most likely lead to deadlock'ed system. But with all the "good" debug information being lost, which wouldn't be the case with panic().
I really don't think this is a good idea.

#12 lore raw

Re: [PATCH 2/2] s390: mm: Fix secure storage access exception handling

Quoted 10 lines · Heiko Carstens
Quoted 8 lines · Christian Borntraeger

arch/s390/mm/fault.c void do_secure_storage_access(struct pt_regs *regs) · line 805

Quoted 5 lines
arch/s390/mm/fault.c +5 -0
+		if (user_mode(regs)) {
+			send_sig(SIGSEGV, current, 0);
+			return;
+		} else
+			panic("Unexpected PGM 0x3d with TEID bit 61=0");

use BUG instead of panic? That would kill this process, but it allows people to maybe save unaffected data.

Quoted 5 lines

It would kill the process, and most likely lead to deadlock'ed system. But with all the "good" debug information being lost, which wouldn't be the case with panic().
I really don't think this is a good idea.

My understanding is that Linus hates panic for anything that might be able to continue to run. With BUG the admin can decide via panic_on_oops if debugging data or runtime data is more important. But mm is more on your side, so if you insist on panic we can keep it.

maintainer
#13 lore raw

Re: [PATCH 2/2] s390: mm: Fix secure storage access exception handling

Quoted 17 lines · Christian Borntraeger
Quoted 10 lines · Heiko Carstens
Quoted 8 lines · Christian Borntraeger

arch/s390/mm/fault.c void do_secure_storage_access(struct pt_regs *regs) · line 805

Quoted 5 lines
arch/s390/mm/fault.c +5 -0
+		if (user_mode(regs)) {
+			send_sig(SIGSEGV, current, 0);
+			return;
+		} else
+			panic("Unexpected PGM 0x3d with TEID bit 61=0");

use BUG instead of panic? That would kill this process, but it allows people to maybe save unaffected data.

Quoted 5 lines

It would kill the process, and most likely lead to deadlock'ed system. But with all the "good" debug information being lost, which wouldn't be the case with panic().
I really don't think this is a good idea.

Quoted 4 lines

My understanding is that Linus hates panic for anything that might be able to continue to run. With BUG the admin can decide via panic_on_oops if debugging data or runtime data is more important. But mm is more on your side, so if you insist on panic we can keep it.

I prefer to have good debug data - and when we are reaching this panic, then we _most_ likely have data corruption anywhere (wrong pointer?). So it seems to be best to me to shutdown the machine immediately in order to avoid any further corruption instead of hoping that the system stays somehow alive.

Furthermore a panic is easily detectable by a watchdog, while a BUG may put the system into a limbo state where the real workload doesn't work anymore, but the keepalive process does. I don't think this is desirable.

maintainer Reviewed-by on v1 2/2
#14 lore raw

Re: [PATCH 2/2] s390: mm: Fix secure storage access exception handling

In reply to Janosch Frank
Quoted 3 lines · On Tue, 19 Jan 2021 05:04:02 -0500 Janosch Frank <[email protected]> wrote:

Turns out that the bit 61 in the TEID is not always 1 and if that's the case the address space ID and the address are unpredictable. Without an address and it's address space ID we can't

*its

Quoted 37 lines

export memory and hence we can only send a SIGSEGV to the process or panic the kernel depending on who caused the exception.

Fixes 084ea4d611a3d ("s390/mm: add (non)secure page access

exceptions handlers") Cc: [email protected]

---
 arch/s390/mm/fault.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/s390/mm/fault.c +5 -0
index e30c7c781172..5442937e5b4b 100644
@@ -791,6 +791,20 @@ void do_secure_storage_access(struct pt_regs
 *regs) struct page *page;
 	int rc;
 
+	/* There are cases where we don't have a TEID. */
+	if (!(regs->int_parm_long & 0x4)) {
+		/*
+		 * Userspace could for example try to execute secure
+		 * storage and trigger this. We should tell it that

it

arch/s390/mm/fault.c +7 -0
+		 * shouldn't do that.
+		 */
+		if (user_mode(regs)) {
+			send_sig(SIGSEGV, current, 0);
+			return;
+		} else
+			panic("Unexpected PGM 0x3d with TEID bit

61=0");

arch/s390/mm/fault.c +2 -0
+	}
+
 	switch (get_fault_type(regs)) {
 	case USER_FAULT:
 		mm = current->mm;