Skip to contentSkip to conversation

target/s390x/tcg: SPX: check validity of new prefix

PATCH Superseded Janis Schoetterl-Glausch 2 participants 4 messages Jun 27, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/s390x/tcg: SPX: check validity of new prefix

According to the architecture, SET PREFIX must try to access the new prefix area and recognize an addressing exception if the area is not accessible.
For qemu this check prevents a crash in cpu_map_lowcore after an inaccessible prefix area has been set.

---

Is there a stricter check to see if the memory is accessible?

 target/s390x/tcg/misc_helper.c | 4 ++++
 1 file changed, 4 insertions(+)
target/s390x/tcg/misc_helper.c +4 -0
index aab9c47747..c8447b36fc 100644
@@ -158,6 +158,10 @@ void HELPER(spx)(CPUS390XState *env, uint64_t a1)
     if (prefix == old_prefix) {
         return;
     }
+    if (!mmu_absolute_addr_valid(prefix, true) ||
+        !mmu_absolute_addr_valid(prefix + TARGET_PAGE_SIZE, true)) {
+        tcg_s390_program_interrupt(env, PGM_ADDRESSING, GETPC());
+    }
 
     env->psa = prefix;
     HELPER_LOG("prefix: %#x\n", prefix);

base-commit: 3a821c52e1a30ecd9a436f2c67cc66b5628c829f

Signature · 1 line
2.36.1
#1 lore raw
Quoted 5 lines · Janis Schoetterl-Glausch

According to the architecture, SET PREFIX must try to access the new prefix area and recognize an addressing exception if the area is not accessible.
For qemu this check prevents a crash in cpu_map_lowcore after an inaccessible prefix area has been set.

I don't think that's possible. Our memory increments are 1 MiB and one would have to cross a 1~MiB range with the second page to trigger that. IIRC that's impossible with SPX address alignment requirements?

Quoted 28 lines

---

Is there a stricter check to see if the memory is accessible?

 target/s390x/tcg/misc_helper.c | 4 ++++
 1 file changed, 4 insertions(+)
target/s390x/tcg/misc_helper.c +4 -0
index aab9c47747..c8447b36fc 100644
@@ -158,6 +158,10 @@ void HELPER(spx)(CPUS390XState *env, uint64_t a1)
     if (prefix == old_prefix) {
         return;
     }
+    if (!mmu_absolute_addr_valid(prefix, true) ||
+        !mmu_absolute_addr_valid(prefix + TARGET_PAGE_SIZE, true)) {
+        tcg_s390_program_interrupt(env, PGM_ADDRESSING, GETPC());
+    }
 
     env->psa = prefix;
     HELPER_LOG("prefix: %#x\n", prefix);

base-commit: 3a821c52e1a30ecd9a436f2c67cc66b5628c829f

Signature · 3 lines
Thanks,

David / dhildenb
Reviewed-by
#3 lore raw
In reply to Janis Schoetterl-Glausch
Quoted 8 lines · Janis Schoetterl-Glausch
Quoted 7 lines · David Hildenbrand
Quoted 5 lines · Janis Schoetterl-Glausch

According to the architecture, SET PREFIX must try to access the new prefix area and recognize an addressing exception if the area is not accessible.
For qemu this check prevents a crash in cpu_map_lowcore after an inaccessible prefix area has been set.

Quoted 5 lines
Quoted 4 lines

I don't think that's possible. Our memory increments are 1 MiB and one would have to cross a 1~MiB range with the second page to trigger that. IIRC that's impossible with SPX address alignment requirements?

Are you saying that checking the first page is sufficient?

Yes, unless I'm wrong. :)

/* Due to alignment and QEMU memory sizes, it's sufficient to check the first page only. */

Quoted 2 lines

I'm not sure that this the case for the architecture in general, but I guess it is true for tcg. Do you want me to remove the second check?

Should have been clearer (and I somehow thought we'd be checking the first page already :))

Signature · 3 lines
Thanks,

David / dhildenb
#2 lore raw
In reply to David Hildenbrand
Quoted 11 lines · David Hildenbrand
Quoted 5 lines · Janis Schoetterl-Glausch

According to the architecture, SET PREFIX must try to access the new prefix area and recognize an addressing exception if the area is not accessible.
For qemu this check prevents a crash in cpu_map_lowcore after an inaccessible prefix area has been set.

I don't think that's possible. Our memory increments are 1 MiB and one would have to cross a 1~MiB range with the second page to trigger that. IIRC that's impossible with SPX address alignment requirements?

Are you saying that checking the first page is sufficient?
I'm not sure that this the case for the architecture in general, but I guess it is true for tcg. Do you want me to remove the second check?

Quoted 31 lines
Quoted 29 lines

---

Is there a stricter check to see if the memory is accessible?

 target/s390x/tcg/misc_helper.c | 4 ++++
 1 file changed, 4 insertions(+)
target/s390x/tcg/misc_helper.c +4 -0
index aab9c47747..c8447b36fc 100644
@@ -158,6 +158,10 @@ void HELPER(spx)(CPUS390XState *env, uint64_t a1)
     if (prefix == old_prefix) {
         return;
     }
+    if (!mmu_absolute_addr_valid(prefix, true) ||
+        !mmu_absolute_addr_valid(prefix + TARGET_PAGE_SIZE, true)) {
+        tcg_s390_program_interrupt(env, PGM_ADDRESSING, GETPC());
+    }
 
     env->psa = prefix;
     HELPER_LOG("prefix: %#x\n", prefix);

base-commit: 3a821c52e1a30ecd9a436f2c67cc66b5628c829f