Skip to contentSkip to conversation

dump: Arch info function pointer addition and cleanup

PATCH Superseded Janosch Frank 3 participants 10 messages Nov 7, 2023 – Nov 8, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover dump: Arch info function pointer addition and cleanup

Small cleanups/fixes to the dump info function pointer assignments as well as a new function pointer for cleanup of residual state.

This has come up because test managed to dump a s390 PV vm onto a disk that was too small for the dump. After the dump failed, the vm wasn't able to resume running since KVM was still in dump mode which blocks vcpu entry.

The new function pointer allows cleanup of such a situation.

Janosch Frank (4):
dump: Set dump info function pointers to NULL target/s390x/dump: Remove unneeded dump info function pointer init
dump: Add arch cleanup function
target/s390x/arch_dump: Add arch cleanup function for PV dumps

 dump/dump.c                |  8 ++++++++
 include/sysemu/dump-arch.h |  1 +
 target/s390x/arch_dump.c   | 21 +++++++++++++++++----
 3 files changed, 26 insertions(+), 4 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/4 dump: Set dump info function pointers to NULL

Better to not rely on the struct zeroing since NULL is not necessarily 0.

---
 dump/dump.c | 3 +++
 1 file changed, 3 insertions(+)
dump/dump.c +3 -0
index d355ada62e..1d38274925 100644
@@ -1706,6 +1706,9 @@ static void dump_state_prepare(DumpState *s)
 {
     /* zero the struct, setting status to active */
     *s = (DumpState) { .status = DUMP_STATUS_ACTIVE };
+    s->dump_info.arch_sections_add_fn = NULL;
+    s->dump_info.arch_sections_write_hdr_fn = NULL;
+    s->dump_info.arch_sections_write_fn = NULL;
 }
 
 bool qemu_system_dump_in_progress(void)
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/4] dump: Set dump info function pointers to NULL

Hi

Quoted 14 lines · Janosch Frank

Better to not rely on the struct zeroing since NULL is not necessarily 0.

---
 dump/dump.c | 3 +++
 1 file changed, 3 insertions(+)
dump/dump.c +0 -0
index d355ada62e..1d38274925 100644

dump/dump.c static void dump_state_prepare(DumpState *s) · line 1712

Quoted 7 lines
dump/dump.c +3 -0
@@ -1706,6 +1706,9 @@ static void dump_state_prepare(DumpState *s)
 {
     /* zero the struct, setting status to active */
     *s = (DumpState) { .status = DUMP_STATUS_ACTIVE };
+    s->dump_info.arch_sections_add_fn = NULL;
+    s->dump_info.arch_sections_write_hdr_fn = NULL;
+    s->dump_info.arch_sections_write_fn = NULL;
 }

I think we would be in trouble if NULL is not 0. Do you have a better argument?

Signature · 1 line
Marc-André Lureau
#3 lore raw

Re: [PATCH 1/4] dump: Set dump info function pointers to NULL

Quoted 12 lines · Marc-André Lureau

Hi

Quoted 9 lines · Janosch Frank

Better to not rely on the struct zeroing since NULL is not necessarily 0.

---
  dump/dump.c | 3 +++
  1 file changed, 3 insertions(+)
Quoted 15 lines

dump/dump.c static void dump_state_prepare(DumpState *s) · line 1712

Quoted 12 lines
dump/dump.c +3 -0
index d355ada62e..1d38274925 100644
@@ -1706,6 +1706,9 @@ static void dump_state_prepare(DumpState *s)
  {
      /* zero the struct, setting status to active */
      *s = (DumpState) { .status = DUMP_STATUS_ACTIVE };
+    s->dump_info.arch_sections_add_fn = NULL;
+    s->dump_info.arch_sections_write_hdr_fn = NULL;
+    s->dump_info.arch_sections_write_fn = NULL;
  }

I think we would be in trouble if NULL is not 0. Do you have a better argument?

I'm one of those people who likes to distinguish between pointers and non-pointers but I have no problem dropping this.

OT: On s390 0x0 is a valid address but the kernel maps & handles it in a way that it will result in a null pointer if read/written to.

#4 lore raw

PATCH 2/4 target/s390x/dump: Remove unneeded dump info function pointer init

In reply to Janosch Frank

dump_state_prepare() now sets the fucntion pointers to NULL so we only need to touch them if we're going to use them.

---
 target/s390x/arch_dump.c | 4 ----
 1 file changed, 4 deletions(-)
target/s390x/arch_dump.c +0 -4
index 51a2116515..bdb0bfa0e7 100644
@@ -448,10 +448,6 @@ int cpu_get_dump_info(ArchDumpInfo *info,
         info->arch_sections_add_fn = *arch_sections_add;
         info->arch_sections_write_hdr_fn = *arch_sections_write_hdr;
         info->arch_sections_write_fn = *arch_sections_write;
-    } else {
-        info->arch_sections_add_fn = NULL;
-        info->arch_sections_write_hdr_fn = NULL;
-        info->arch_sections_write_fn = NULL;
     }
     return 0;
 }
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH 2/4] target/s390x/dump: Remove unneeded dump info function pointer init

Quoted 4 lines · On Tue, 7 Nov 2023 14:20:46 +0000 Janosch Frank <[email protected]> wrote:

dump_state_prepare() now sets the fucntion pointers to NULL so we only need to touch them if we're going to use them.

I would merge this and the previous patch

Quoted 19 lines
---
 target/s390x/arch_dump.c | 4 ----
 1 file changed, 4 deletions(-)
target/s390x/arch_dump.c +0 -4
index 51a2116515..bdb0bfa0e7 100644
@@ -448,10 +448,6 @@ int cpu_get_dump_info(ArchDumpInfo *info,
         info->arch_sections_add_fn = *arch_sections_add;
         info->arch_sections_write_hdr_fn = *arch_sections_write_hdr;
         info->arch_sections_write_fn = *arch_sections_write;
-    } else {
-        info->arch_sections_add_fn = NULL;
-        info->arch_sections_write_hdr_fn = NULL;
-        info->arch_sections_write_fn = NULL;
     }
     return 0;
 }
Reviewed-by on v1 2/4
#6 lore raw

Re: [PATCH 2/4] target/s390x/dump: Remove unneeded dump info function pointer init

In reply to Janosch Frank

Hi

Quoted 2 lines · Janosch Frank

dump_state_prepare() now sets the fucntion pointers to NULL so we only

function

Quoted 3 lines

need to touch them if we're going to use them.

regardless if the previous patch is applied, this patch lgtm

Quoted 23 lines
---
 target/s390x/arch_dump.c | 4 ----
 1 file changed, 4 deletions(-)
target/s390x/arch_dump.c +0 -5
index 51a2116515..bdb0bfa0e7 100644
@@ -448,10 +448,6 @@ int cpu_get_dump_info(ArchDumpInfo *info,
         info->arch_sections_add_fn = *arch_sections_add;
         info->arch_sections_write_hdr_fn = *arch_sections_write_hdr;
         info->arch_sections_write_fn = *arch_sections_write;
-    } else {
-        info->arch_sections_add_fn = NULL;
-        info->arch_sections_write_hdr_fn = NULL;
-        info->arch_sections_write_fn = NULL;
     }
     return 0;
 }
--

2.34.1

Signature · 1 line
Marc-André Lureau
#7 lore raw

PATCH 3/4 dump: Add arch cleanup function

In reply to Janosch Frank

Some architectures (s390x) need to cleanup after a failed dump to be able to continue to run the vm. Add a cleanup function pointer and call it if it's set.

---
 dump/dump.c                | 5 +++++
 include/sysemu/dump-arch.h | 1 +
 2 files changed, 6 insertions(+)
dump/dump.c +5 -0
index 1d38274925..5c4e405ad2 100644
@@ -96,6 +96,10 @@ uint64_t cpu_to_dump64(DumpState *s, uint64_t val)
 
 static int dump_cleanup(DumpState *s)
 {
+    if (s->dump_info.arch_cleanup_fn) {
+        s->dump_info.arch_cleanup_fn(s);
+    }
+
     guest_phys_blocks_free(&s->guest_phys_blocks);
     memory_mapping_list_free(&s->list);
     close(s->fd);
@@ -1709,6 +1713,7 @@ static void dump_state_prepare(DumpState *s)
     s->dump_info.arch_sections_add_fn = NULL;
     s->dump_info.arch_sections_write_hdr_fn = NULL;
     s->dump_info.arch_sections_write_fn = NULL;
+    s->dump_info.arch_cleanup_fn = NULL;
 }
 
 bool qemu_system_dump_in_progress(void)
include/sysemu/dump-arch.h +1 -0
index 59bbc9be38..743916e46c 100644
@@ -24,6 +24,7 @@ typedef struct ArchDumpInfo {
     void (*arch_sections_add_fn)(DumpState *s);
     uint64_t (*arch_sections_write_hdr_fn)(DumpState *s, uint8_t *buff);
     int (*arch_sections_write_fn)(DumpState *s, uint8_t *buff);
+    void (*arch_cleanup_fn)(DumpState *s);
 } ArchDumpInfo;
 
 struct GuestPhysBlockList; /* memory_mapping.h */
Signature · 1 line
2.34.1
#8 lore raw

PATCH 4/4 target/s390x/arch_dump: Add arch cleanup function for PV dumps

In reply to Janosch Frank

PV dumps block vcpu runs until dump end is reached. If there's an error between PV dump init and PV dump end the vm will never be able to run again. One example of such an error is insufficient disk space for the dump file.

Let's add a cleanup function that tries to do a dump end. The dump completion data is discarded but there's no point in writing it to a file anyway if there's a possibility that other PV dump data is missing.

---
 target/s390x/arch_dump.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
target/s390x/arch_dump.c +17 -0
index bdb0bfa0e7..70146d7e84 100644
@@ -433,6 +433,22 @@ static int arch_sections_write(DumpState *s, uint8_t *buff)
     return 0;
 }
 
+static void arch_cleanup(DumpState *s)
+{
+    uint8_t *buff = g_malloc(kvm_s390_pv_dmp_get_size_completion_data());
+    int rc;
+
+    if (!pv_dump_initialized || !buff) {
+        return;
+    }
+
+    rc = kvm_s390_dump_completion_data(buff);
+    if (!rc) {
+            pv_dump_initialized = false;
+    }
+    g_free(buff);
+}
+
 int cpu_get_dump_info(ArchDumpInfo *info,
                       const struct GuestPhysBlockList *guest_phys_blocks)
 {
@@ -448,6 +464,7 @@ int cpu_get_dump_info(ArchDumpInfo *info,
         info->arch_sections_add_fn = *arch_sections_add;
         info->arch_sections_write_hdr_fn = *arch_sections_write_hdr;
         info->arch_sections_write_fn = *arch_sections_write;
+        info->arch_cleanup_fn = *arch_cleanup;
     }
     return 0;
 }
Signature · 1 line
2.34.1
#9 lore raw

Re: [PATCH 4/4] target/s390x/arch_dump: Add arch cleanup function for PV dumps

Hi

Quoted 21 lines · Janosch Frank

PV dumps block vcpu runs until dump end is reached. If there's an error between PV dump init and PV dump end the vm will never be able to run again. One example of such an error is insufficient disk space for the dump file.

Let's add a cleanup function that tries to do a dump end. The dump completion data is discarded but there's no point in writing it to a file anyway if there's a possibility that other PV dump data is missing.

---
 target/s390x/arch_dump.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
target/s390x/arch_dump.c +0 -0
index bdb0bfa0e7..70146d7e84 100644

target/s390x/arch_dump.c static int arch_sections_write(DumpState *s, uint8_t *buff) · line 441

Quoted 9 lines
target/s390x/arch_dump.c +6 -0
@@ -433,6 +433,22 @@ static int arch_sections_write(DumpState *s, uint8_t *buff)
     return 0;
 }
 
+static void arch_cleanup(DumpState *s)
+{
+    uint8_t *buff = g_malloc(kvm_s390_pv_dmp_get_size_completion_data());
+    int rc;
+
+    if (!pv_dump_initialized || !buff) {

this may leak if bluff != NULL && !pv_dump_initialized

Better use g_autofree.

No need to check bluff != NULL. (g_malloc abort() if it failed)

Quoted 22 lines
target/s390x/arch_dump.c +11 -1
+        return;
+    }
+
+    rc = kvm_s390_dump_completion_data(buff);
+    if (!rc) {
+            pv_dump_initialized = false;
+    }
+    g_free(buff);
+}
+
 int cpu_get_dump_info(ArchDumpInfo *info,
                       const struct GuestPhysBlockList *guest_phys_blocks)
 {
@@ -448,6 +464,7 @@ int cpu_get_dump_info(ArchDumpInfo *info,
         info->arch_sections_add_fn = *arch_sections_add;
         info->arch_sections_write_hdr_fn = *arch_sections_write_hdr;
         info->arch_sections_write_fn = *arch_sections_write;
+        info->arch_cleanup_fn = *arch_cleanup;
     }
     return 0;
 }
--
Quoted 3 lines

2.34.1

otherwise, seems ok

Signature · 1 line
Marc-André Lureau