Skip to contentSkip to conversation

s390/mm: add missing secure storage access fixups for donated memory

PATCH In review Janosch Frank 4 participants 6 messages Mar 10 – Mar 11

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 s390/mm: add missing secure storage access fixups for donated memory

There are special cases where secure storage access exceptions happen in a kernel context for pages that don't have the PG_arch_1 bit set. That bit is set for non-exported guest secure storage (memory) but is absent on storage donated to the Ultravisor since the kernel isn't allowed to export donated pages.

Prior to this patch we would try to export the page by calling arch_make_folio_accessible() which would instantly return since the arch bit is absent signifying that the page was already exported and no further action is necessary. This leads to secure storage access exception loops which can never be resolved.

With this patch we unconditionally try to export and if that fails we fixup.

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

---

Changed fault error handling to nolock. (Heiko) Added PG_arch_1 cleanup requested off-list. (Claudio)

---
 arch/s390/mm/fault.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
arch/s390/mm/fault.c +9 -2
index a52aa7a99b6b..191cc53caead 100644
@@ -441,10 +441,17 @@ void do_secure_storage_access(struct pt_regs *regs)
 		folio = phys_to_folio(addr);
 		if (unlikely(!folio_try_get(folio)))
 			return;
-		rc = arch_make_folio_accessible(folio);
+		rc = uv_convert_from_secure(folio_to_phys(folio));
+		if (!rc)
+			clear_bit(PG_arch_1, &folio->flags.f);
 		folio_put(folio);
+		/*
+		 * There are some valid fixup types for kernel
+		 * accesses to donated secure memory. zeropad is one
+		 * of them.
+		 */
 		if (rc)
-			BUG();
+			return handle_fault_error_nolock(regs, 0);
 	} else {
 		if (faulthandler_disabled())
 			return handle_fault_error_nolock(regs, 0);
Signature · 1 line
2.51.0
reviewer Tested-by on v2 1/1
#1 lore raw

Am 10.03.26 um 16:02 schrieb Janosch Frank:

Quoted 12 lines

There are special cases where secure storage access exceptions happen in a kernel context for pages that don't have the PG_arch_1 bit set. That bit is set for non-exported guest secure storage (memory) but is absent on storage donated to the Ultravisor since the kernel isn't allowed to export donated pages.

Prior to this patch we would try to export the page by calling arch_make_folio_accessible() which would instantly return since the arch bit is absent signifying that the page was already exported and no further action is necessary. This leads to secure storage access exception loops which can never be resolved.

Quoted 7 lines

With this patch we unconditionally try to export and if that fails we fixup.

Fixes 084ea4d611a3 ("s390/mm: add (non)secure page access exceptions handlers")
Reviewed-by on v2 1/1
#2 lore raw
In reply to Janosch Frank
Quoted 12 lines · On Tue, 10 Mar 2026 15:02:42 +0000 Janosch Frank <[email protected]> wrote:

There are special cases where secure storage access exceptions happen in a kernel context for pages that don't have the PG_arch_1 bit set. That bit is set for non-exported guest secure storage (memory) but is absent on storage donated to the Ultravisor since the kernel isn't allowed to export donated pages.

Prior to this patch we would try to export the page by calling arch_make_folio_accessible() which would instantly return since the arch bit is absent signifying that the page was already exported and no further action is necessary. This leads to secure storage access exception loops which can never be resolved.

Quoted 7 lines

With this patch we unconditionally try to export and if that fails we fixup.

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

---

Changed fault error handling to nolock. (Heiko) Added PG_arch_1 cleanup requested off-list. (Claudio)

---
 arch/s390/mm/fault.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
arch/s390/mm/fault.c +9 -2
index a52aa7a99b6b..191cc53caead 100644
@@ -441,10 +441,17 @@ void do_secure_storage_access(struct pt_regs *regs)
 		folio = phys_to_folio(addr);
 		if (unlikely(!folio_try_get(folio)))
 			return;
-		rc = arch_make_folio_accessible(folio);
+		rc = uv_convert_from_secure(folio_to_phys(folio));
+		if (!rc)
+			clear_bit(PG_arch_1, &folio->flags.f);
 		folio_put(folio);
+		/*
+		 * There are some valid fixup types for kernel
+		 * accesses to donated secure memory. zeropad is one
+		 * of them.
+		 */
 		if (rc)
-			BUG();
+			return handle_fault_error_nolock(regs, 0);
 	} else {
 		if (faulthandler_disabled())
 			return handle_fault_error_nolock(regs, 0);
maintainer
#3 lore raw
In reply to Janosch Frank
Quoted 33 lines · Janosch Frank

There are special cases where secure storage access exceptions happen in a kernel context for pages that don't have the PG_arch_1 bit set. That bit is set for non-exported guest secure storage (memory) but is absent on storage donated to the Ultravisor since the kernel isn't allowed to export donated pages.

Prior to this patch we would try to export the page by calling arch_make_folio_accessible() which would instantly return since the arch bit is absent signifying that the page was already exported and no further action is necessary. This leads to secure storage access exception loops which can never be resolved.

With this patch we unconditionally try to export and if that fails we fixup.

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

---

Changed fault error handling to nolock. (Heiko) Added PG_arch_1 cleanup requested off-list. (Claudio)

---
 arch/s390/mm/fault.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
arch/s390/mm/fault.c +0 -0
index a52aa7a99b6b..191cc53caead 100644

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

Quoted 8 lines
arch/s390/mm/fault.c +3 -1
@@ -441,10 +441,17 @@ void do_secure_storage_access(struct pt_regs *regs)
 		folio = phys_to_folio(addr);
 		if (unlikely(!folio_try_get(folio)))
 			return;
-		rc = arch_make_folio_accessible(folio);
+		rc = uv_convert_from_secure(folio_to_phys(folio));
+		if (!rc)
+			clear_bit(PG_arch_1, &folio->flags.f);
 		folio_put(folio);

Isn't the clear_bit() racy? That is: another CPU could make the page secure again, set (the still set) PG_arch_1, and then clear_bit() removes the bit, and we end up with a secure page where PG_arch_1 is not set? Which in turn would arch_make_folio_accessible() al

Or is that not possible?

Just wondering, since __make_folio_secure() requires the folio to be locked when setting PG_arch_1, while clearing happens unlocked. But chances are high that I don't understand the code.

#4 lore raw
Quoted 48 lines · Heiko Carstens
Quoted 33 lines · Janosch Frank

There are special cases where secure storage access exceptions happen in a kernel context for pages that don't have the PG_arch_1 bit set. That bit is set for non-exported guest secure storage (memory) but is absent on storage donated to the Ultravisor since the kernel isn't allowed to export donated pages.

Prior to this patch we would try to export the page by calling arch_make_folio_accessible() which would instantly return since the arch bit is absent signifying that the page was already exported and no further action is necessary. This leads to secure storage access exception loops which can never be resolved.

With this patch we unconditionally try to export and if that fails we fixup.

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

---

Changed fault error handling to nolock. (Heiko) Added PG_arch_1 cleanup requested off-list. (Claudio)

---
  arch/s390/mm/fault.c | 11 +++++++++--
  1 file changed, 9 insertions(+), 2 deletions(-)
arch/s390/mm/fault.c +0 -0
index a52aa7a99b6b..191cc53caead 100644

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

Quoted 8 lines
arch/s390/mm/fault.c +3 -1
@@ -441,10 +441,17 @@ void do_secure_storage_access(struct pt_regs *regs)
  		folio = phys_to_folio(addr);
  		if (unlikely(!folio_try_get(folio)))
  			return;
-		rc = arch_make_folio_accessible(folio);
+		rc = uv_convert_from_secure(folio_to_phys(folio));
+		if (!rc)
+			clear_bit(PG_arch_1, &folio->flags.f);
  		folio_put(folio);

Isn't the clear_bit() racy? That is: another CPU could make the page secure again, set (the still set) PG_arch_1, and then clear_bit() removes the bit, and we end up with a secure page where PG_arch_1 is not set? Which in turn would arch_make_folio_accessible() al

Quoted 6 lines

Or is that not possible?

Just wondering, since __make_folio_secure() requires the folio to be locked when setting PG_arch_1, while clearing happens unlocked. But chances are high that I don't understand the code.

__make_folio_secure() checks the refcount and if the comments hold true, it should protect us from a flag being set as long as we have the extra reference which we should have gotten via folio_try_get().

It does not protect us from a double clear.

maintainer
#5 lore raw
Quoted 18 lines · Janosch Frank
Quoted 11 lines

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

Quoted 5 lines
arch/s390/mm/fault.c +3 -1
-		rc = arch_make_folio_accessible(folio);
+		rc = uv_convert_from_secure(folio_to_phys(folio));
+		if (!rc)
+			clear_bit(PG_arch_1, &folio->flags.f);
  		folio_put(folio);

Isn't the clear_bit() racy? That is: another CPU could make the page secure again, set (the still set) PG_arch_1, and then clear_bit() removes the bit, and we end up with a secure page where PG_arch_1 is not set? Which in turn would arch_make_folio_accessible() al

Quoted 6 lines

Or is that not possible?

Just wondering, since __make_folio_secure() requires the folio to be locked when setting PG_arch_1, while clearing happens unlocked. But chances are high that I don't understand the code.

Quoted 5 lines

__make_folio_secure() checks the refcount and if the comments hold true, it should protect us from a flag being set as long as we have the extra reference which we should have gotten via folio_try_get().

It does not protect us from a double clear.

Ok, then it should work. Thanks for explaining!