Skip to contentSkip to conversation

target/s390x/mmu_helper: Do not ignore address_space_rw() errors

PATCH In review Philippe Mathieu-Daudé 2 participants 5 messages Oct 8, 2025 – Oct 16, 2025

lore
Share & tools
lore
#0 lore raw

v2 cover target/s390x/mmu_helper: Do not ignore address_space_rw() errors

v2: Addressed Thomas' review comment

Philippe Mathieu-Daudé (2):
target/s390x/mmu_helper: Simplify s390_cpu_virt_mem_rw() logic target/s390x/mmu_helper: Do not ignore address_space_rw() errors

 target/s390x/mmu_helper.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH v2 1/2 target/s390x/mmu_helper: Simplify s390_cpu_virt_mem_rw() logic

In order to simplify the next commit, move the trigger_access_exception() call after the address_space_rw() calls. No logical change intended.

---
 target/s390x/mmu_helper.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
target/s390x/mmu_helper.c +4 -3
index 487c41bf933..22d3d4a97df 100644
@@ -541,9 +541,7 @@ int s390_cpu_virt_mem_rw(S390CPU *cpu, vaddr laddr, uint8_t ar, void *hostbuf,
     pages = g_malloc(nr_pages * sizeof(*pages));
 
     ret = translate_pages(cpu, laddr, nr_pages, pages, is_write, &tec);
-    if (ret) {
-        trigger_access_exception(&cpu->env, ret, tec);
-    } else if (hostbuf != NULL) {
+    if (ret == 0 && hostbuf != NULL) {
         AddressSpace *as = CPU(cpu)->as;
 
         /* Copy data by stepping through the area page by page */
@@ -556,6 +554,9 @@ int s390_cpu_virt_mem_rw(S390CPU *cpu, vaddr laddr, uint8_t ar, void *hostbuf,
             len -= currlen;
         }
     }
+    if (ret) {
+        trigger_access_exception(&cpu->env, ret, tec);
+    }
 
     g_free(pages);
     return ret;
Signature · 1 line
2.51.0
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] target/s390x/mmu_helper: Simplify s390_cpu_virt_mem_rw() logic

Quoted 25 lines · Philippe Mathieu-Daudé

In order to simplify the next commit, move the trigger_access_exception() call after the address_space_rw() calls. No logical change intended.

---
  target/s390x/mmu_helper.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
target/s390x/mmu_helper.c +1 -3
index 487c41bf933..22d3d4a97df 100644
@@ -541,9 +541,7 @@ int s390_cpu_virt_mem_rw(S390CPU *cpu, vaddr laddr, uint8_t ar, void *hostbuf,
      pages = g_malloc(nr_pages * sizeof(*pages));
 
      ret = translate_pages(cpu, laddr, nr_pages, pages, is_write, &tec);
-    if (ret) {
-        trigger_access_exception(&cpu->env, ret, tec);
-    } else if (hostbuf != NULL) {
+    if (ret == 0 && hostbuf != NULL) {
          AddressSpace *as = CPU(cpu)->as;
 
          /* Copy data by stepping through the area page by page */

target/s390x/mmu_helper.c int s390_cpu_virt_mem_rw(S390CPU *cpu, vaddr laddr, uint8_t ar, void *hostbuf, · line 562

Quoted 9 lines
target/s390x/mmu_helper.c +3 -0
@@ -556,6 +554,9 @@ int s390_cpu_virt_mem_rw(S390CPU *cpu, vaddr laddr, uint8_t ar, void *hostbuf,
              len -= currlen;
          }
      }
+    if (ret) {
+        trigger_access_exception(&cpu->env, ret, tec);
+    }
 
      g_free(pages);
      return ret;
#3 lore raw

PATCH v2 2/2 target/s390x/mmu_helper: Do not ignore address_space_rw() errors

In reply to Philippe Mathieu-Daudé

If a address_space_rw() call ever fails, break the loop and return the PGM_ADDRESSING error (after triggerring an access exception).

---
 target/s390x/mmu_helper.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
target/s390x/mmu_helper.c +8 -2
index 22d3d4a97df..3b1e75f7833 100644
@@ -546,9 +546,15 @@ int s390_cpu_virt_mem_rw(S390CPU *cpu, vaddr laddr, uint8_t ar, void *hostbuf,
 
         /* Copy data by stepping through the area page by page */
         for (i = 0; i < nr_pages; i++) {
+            MemTxResult res;
+
             currlen = MIN(len, TARGET_PAGE_SIZE - (laddr % TARGET_PAGE_SIZE));
-            address_space_rw(as, pages[i] | (laddr & ~TARGET_PAGE_MASK),
-                             attrs, hostbuf, currlen, is_write);
+            res = address_space_rw(as, pages[i] | (laddr & ~TARGET_PAGE_MASK),
+                                   attrs, hostbuf, currlen, is_write);
+            if (res != MEMTX_OK) {
+                ret = PGM_ADDRESSING;
+                break;
+            }
             laddr += currlen;
             hostbuf += currlen;
             len -= currlen;
Signature · 1 line
2.51.0
Reviewed-by on v2 2/2
#4 lore raw
Quoted 21 lines · Philippe Mathieu-Daudé

If a address_space_rw() call ever fails, break the loop and return the PGM_ADDRESSING error (after triggerring an access exception).

---
  target/s390x/mmu_helper.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
target/s390x/mmu_helper.c +2 -1
index 22d3d4a97df..3b1e75f7833 100644
@@ -546,9 +546,15 @@ int s390_cpu_virt_mem_rw(S390CPU *cpu, vaddr laddr, uint8_t ar, void *hostbuf,
 
          /* Copy data by stepping through the area page by page */
          for (i = 0; i < nr_pages; i++) {
+            MemTxResult res;
+
              currlen = MIN(len, TARGET_PAGE_SIZE - (laddr % TARGET_PAGE_SIZE));
-            address_space_rw(as, pages[i] | (laddr & ~TARGET_PAGE_MASK),

target/s390x/mmu_helper.c int s390_cpu_virt_mem_rw(S390CPU *cpu, vaddr laddr, uint8_t ar, void *hostbuf, · line 560

Quoted 10 lines
target/s390x/mmu_helper.c +6 -1
-                             attrs, hostbuf, currlen, is_write);
+            res = address_space_rw(as, pages[i] | (laddr & ~TARGET_PAGE_MASK),
+                                   attrs, hostbuf, currlen, is_write);
+            if (res != MEMTX_OK) {
+                ret = PGM_ADDRESSING;
+                break;
+            }
              laddr += currlen;
              hostbuf += currlen;
              len -= currlen;