git: 069d7fa63b21 - stable/13 - minidump: Use provided msgbuf pointer

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Fri, 03 Dec 2021 14:53:42 UTC
The branch stable/13 has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=069d7fa63b219d526958b7e207d7843a7920d91c

commit 069d7fa63b219d526958b7e207d7843a7920d91c
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2021-11-17 15:34:13 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2021-12-03 14:02:03 +0000

    minidump: Use provided msgbuf pointer
    
    Don't assume we are dumping the global message buffer, but use the one
    provided by the state argument. While here, drop superfluous
    cast to char *.
    
    Reviewed by:    markj, jhb
    MFC after:      2 weeks
    Sponsored by:   Juniper Networks, Inc.
    Sponsored by:   Klara, Inc.
    Differential Revision:  https://reviews.freebsd.org/D31991
    
    (cherry picked from commit 1d2d1418b492359921716aaa41e93750969b6e1f)
---
 sys/amd64/amd64/minidump_machdep.c     |  8 +++++---
 sys/arm/arm/minidump_machdep.c         |  9 +++++----
 sys/arm64/arm64/minidump_machdep.c     |  9 +++++----
 sys/i386/i386/minidump_machdep_base.c  |  9 ++++++---
 sys/mips/mips/minidump_machdep.c       |  9 +++++----
 sys/powerpc/powerpc/minidump_machdep.c | 11 ++++++-----
 sys/riscv/riscv/minidump_machdep.c     |  9 +++++----
 7 files changed, 37 insertions(+), 27 deletions(-)

diff --git a/sys/amd64/amd64/minidump_machdep.c b/sys/amd64/amd64/minidump_machdep.c
index 975ae038cfdf..8d2bc3bca84a 100644
--- a/sys/amd64/amd64/minidump_machdep.c
+++ b/sys/amd64/amd64/minidump_machdep.c
@@ -171,6 +171,7 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 	int ii, j, k, n;
 	int retry_count;
 	struct minidumphdr mdhdr;
+	struct msgbuf *mbp;
 
 	retry_count = 0;
  retry:
@@ -252,8 +253,9 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 	}
 
 	/* Calculate dump size. */
+	mbp = state->msgbufp;
 	dumpsize = pmapsize;
-	dumpsize += round_page(msgbufp->msg_size);
+	dumpsize += round_page(mbp->msg_size);
 	dumpsize += round_page(sizeof(dump_avail));
 	dumpsize += round_page(BITSET_SIZE(vm_page_dump_pages));
 	VM_PAGE_DUMP_FOREACH(pa) {
@@ -273,7 +275,7 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 	bzero(&mdhdr, sizeof(mdhdr));
 	strcpy(mdhdr.magic, MINIDUMP_MAGIC);
 	mdhdr.version = MINIDUMP_VERSION;
-	mdhdr.msgbufsize = msgbufp->msg_size;
+	mdhdr.msgbufsize = mbp->msg_size;
 	mdhdr.bitmapsize = round_page(BITSET_SIZE(vm_page_dump_pages));
 	mdhdr.pmapsize = pmapsize;
 	mdhdr.kernbase = VM_MIN_KERNEL_ADDRESS;
@@ -299,7 +301,7 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 		goto fail;
 
 	/* Dump msgbuf up front */
-	error = blk_write(di, (char *)msgbufp->msg_ptr, 0, round_page(msgbufp->msg_size));
+	error = blk_write(di, mbp->msg_ptr, 0, round_page(mbp->msg_size));
 	if (error)
 		goto fail;
 
diff --git a/sys/arm/arm/minidump_machdep.c b/sys/arm/arm/minidump_machdep.c
index e3bf37599d4a..76ce89f895e3 100644
--- a/sys/arm/arm/minidump_machdep.c
+++ b/sys/arm/arm/minidump_machdep.c
@@ -156,6 +156,7 @@ int
 cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 {
 	struct minidumphdr mdhdr;
+	struct msgbuf *mbp;
 	uint64_t dumpsize, *dump_avail_buf;
 	uint32_t ptesize;
 	uint32_t pa, prev_pa = 0, count = 0;
@@ -190,8 +191,9 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 	}
 
 	/* Calculate dump size. */
+	mbp = state->msgbufp;
 	dumpsize = ptesize;
-	dumpsize += round_page(msgbufp->msg_size);
+	dumpsize += round_page(mbp->msg_size);
 	dumpsize += round_page(nitems(dump_avail) * sizeof(uint64_t));
 	dumpsize += round_page(BITSET_SIZE(vm_page_dump_pages));
 	VM_PAGE_DUMP_FOREACH(pa) {
@@ -209,7 +211,7 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 	bzero(&mdhdr, sizeof(mdhdr));
 	strcpy(mdhdr.magic, MINIDUMP_MAGIC);
 	mdhdr.version = MINIDUMP_VERSION;
-	mdhdr.msgbufsize = msgbufp->msg_size;
+	mdhdr.msgbufsize = mbp->msg_size;
 	mdhdr.bitmapsize = round_page(BITSET_SIZE(vm_page_dump_pages));
 	mdhdr.ptesize = ptesize;
 	mdhdr.kernbase = KERNBASE;
@@ -235,8 +237,7 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 		goto fail;
 
 	/* Dump msgbuf up front */
-	error = blk_write(di, (char *)msgbufp->msg_ptr, 0,
-	    round_page(msgbufp->msg_size));
+	error = blk_write(di, mbp->msg_ptr, 0, round_page(mbp->msg_size));
 	if (error)
 		goto fail;
 
diff --git a/sys/arm64/arm64/minidump_machdep.c b/sys/arm64/arm64/minidump_machdep.c
index 5814cce632a9..5a935d3c379d 100644
--- a/sys/arm64/arm64/minidump_machdep.c
+++ b/sys/arm64/arm64/minidump_machdep.c
@@ -151,6 +151,7 @@ int
 cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 {
 	struct minidumphdr mdhdr;
+	struct msgbuf *mbp;
 	pd_entry_t *l0, *l1, l1e, *l2, l2e;
 	pt_entry_t *l3, l3e;
 	vm_offset_t va, kva_end;
@@ -209,8 +210,9 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 	}
 
 	/* Calculate dump size. */
+	mbp = state->msgbufp;
 	dumpsize = pmapsize;
-	dumpsize += round_page(msgbufp->msg_size);
+	dumpsize += round_page(mbp->msg_size);
 	dumpsize += round_page(sizeof(dump_avail));
 	dumpsize += round_page(BITSET_SIZE(vm_page_dump_pages));
 	VM_PAGE_DUMP_FOREACH(pa) {
@@ -227,7 +229,7 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 	bzero(&mdhdr, sizeof(mdhdr));
 	strcpy(mdhdr.magic, MINIDUMP_MAGIC);
 	mdhdr.version = MINIDUMP_VERSION;
-	mdhdr.msgbufsize = msgbufp->msg_size;
+	mdhdr.msgbufsize = mbp->msg_size;
 	mdhdr.bitmapsize = round_page(BITSET_SIZE(vm_page_dump_pages));
 	mdhdr.pmapsize = pmapsize;
 	mdhdr.kernbase = VM_MIN_KERNEL_ADDRESS;
@@ -254,8 +256,7 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 		goto fail;
 
 	/* Dump msgbuf up front */
-	error = blk_write(di, (char *)msgbufp->msg_ptr, 0,
-	    round_page(msgbufp->msg_size));
+	error = blk_write(di, mbp->msg_ptr, 0, round_page(mbp->msg_size));
 	if (error)
 		goto fail;
 
diff --git a/sys/i386/i386/minidump_machdep_base.c b/sys/i386/i386/minidump_machdep_base.c
index 9b036f0fd700..196c375bec56 100644
--- a/sys/i386/i386/minidump_machdep_base.c
+++ b/sys/i386/i386/minidump_machdep_base.c
@@ -164,6 +164,7 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 	pt_entry_t *pt, pte;
 	int j, k;
 	struct minidumphdr mdhdr;
+	struct msgbuf *mbp;
 
 	/* Snapshot the KVA upper bound in case it grows. */
 	kva_end = kernel_vm_end;
@@ -212,8 +213,9 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 	}
 
 	/* Calculate dump size. */
+	mbp = state->msgbufp;
 	dumpsize = ptesize;
-	dumpsize += round_page(msgbufp->msg_size);
+	dumpsize += round_page(mbp->msg_size);
 	dumpsize += round_page(sizeof(dump_avail));
 	dumpsize += round_page(BITSET_SIZE(vm_page_dump_pages));
 	VM_PAGE_DUMP_FOREACH(pa) {
@@ -232,7 +234,7 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 	bzero(&mdhdr, sizeof(mdhdr));
 	strcpy(mdhdr.magic, MINIDUMP_MAGIC);
 	mdhdr.version = MINIDUMP_VERSION;
-	mdhdr.msgbufsize = msgbufp->msg_size;
+	mdhdr.msgbufsize = mbp->msg_size;
 	mdhdr.bitmapsize = round_page(BITSET_SIZE(vm_page_dump_pages));
 	mdhdr.ptesize = ptesize;
 	mdhdr.kernbase = KERNBASE;
@@ -257,7 +259,8 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 		goto fail;
 
 	/* Dump msgbuf up front */
-	error = blk_write(di, (char *)msgbufp->msg_ptr, 0, round_page(msgbufp->msg_size));
+	error = blk_write(di, (char *)mbp->msg_ptr, 0,
+	    round_page(mbp->msg_size));
 	if (error)
 		goto fail;
 
diff --git a/sys/mips/mips/minidump_machdep.c b/sys/mips/mips/minidump_machdep.c
index 06a63834cab8..49a5ee3f15a7 100644
--- a/sys/mips/mips/minidump_machdep.c
+++ b/sys/mips/mips/minidump_machdep.c
@@ -109,6 +109,7 @@ int
 cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 {
 	struct minidumphdr mdhdr;
+	struct msgbuf *mbp;
 	uint64_t *dump_avail_buf;
 	uint32_t ptesize;
 	vm_paddr_t pa;
@@ -148,8 +149,9 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 	}
 
 	/* Calculate dump size. */
+	mbp = state->msgbufp;
 	dumpsize = ptesize;
-	dumpsize += round_page(msgbufp->msg_size);
+	dumpsize += round_page(mbp->msg_size);
 	dumpsize += round_page(nitems(dump_avail) * sizeof(uint64_t));
 	dumpsize += round_page(BITSET_SIZE(vm_page_dump_pages));
 	VM_PAGE_DUMP_FOREACH(pa) {
@@ -167,7 +169,7 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 	bzero(&mdhdr, sizeof(mdhdr));
 	strcpy(mdhdr.magic, MINIDUMP_MAGIC);
 	mdhdr.version = MINIDUMP_VERSION;
-	mdhdr.msgbufsize = msgbufp->msg_size;
+	mdhdr.msgbufsize = mbp->msg_size;
 	mdhdr.bitmapsize = round_page(BITSET_SIZE(vm_page_dump_pages));
 	mdhdr.ptesize = ptesize;
 	mdhdr.kernbase = VM_MIN_KERNEL_ADDRESS;
@@ -191,8 +193,7 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 		goto fail;
 
 	/* Dump msgbuf up front */
-	error = write_buffer(di, (char *)msgbufp->msg_ptr, 
-	    round_page(msgbufp->msg_size));
+	error = write_buffer(di, mbp->msg_ptr, round_page(mbp->msg_size));
 	if (error)
 		goto fail;
 
diff --git a/sys/powerpc/powerpc/minidump_machdep.c b/sys/powerpc/powerpc/minidump_machdep.c
index e6a0f3918883..c7e8d1965b98 100644
--- a/sys/powerpc/powerpc/minidump_machdep.c
+++ b/sys/powerpc/powerpc/minidump_machdep.c
@@ -195,6 +195,7 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 	int error, retry_count;
 	uint32_t pmapsize;
 	struct minidumphdr mdhdr;
+	struct msgbuf *mbp;
 
 	retry_count = 0;
 retry:
@@ -210,8 +211,9 @@ retry:
 	}
 
 	/* Calculate dump size */
+	mbp = state->msgbufp;
 	dumpsize = PAGE_SIZE;				/* header */
-	dumpsize += round_page(msgbufp->msg_size);
+	dumpsize += round_page(mbp->msg_size);
 	dumpsize += round_page(sizeof(dump_avail));
 	dumpsize += round_page(BITSET_SIZE(vm_page_dump_pages));
 	dumpsize += pmapsize;
@@ -229,7 +231,7 @@ retry:
 	strcpy(mdhdr.magic, MINIDUMP_MAGIC);
 	strncpy(mdhdr.mmu_name, pmap_mmu_name(), sizeof(mdhdr.mmu_name) - 1);
 	mdhdr.version = MINIDUMP_VERSION;
-	mdhdr.msgbufsize = msgbufp->msg_size;
+	mdhdr.msgbufsize = mbp->msg_size;
 	mdhdr.bitmapsize = round_page(BITSET_SIZE(vm_page_dump_pages));
 	mdhdr.pmapsize = pmapsize;
 	mdhdr.kernbase = VM_MIN_KERNEL_ADDRESS;
@@ -260,9 +262,8 @@ retry:
 	dump_total("header", PAGE_SIZE);
 
 	/* Dump msgbuf up front */
-	error = blk_write(di, (char *)msgbufp->msg_ptr, 0,
-	    round_page(msgbufp->msg_size));
-	dump_total("msgbuf", round_page(msgbufp->msg_size));
+	error = blk_write(di, mbp->msg_ptr, 0, round_page(mbp->msg_size));
+	dump_total("msgbuf", round_page(mbp->msg_size));
 
 	/* Dump dump_avail */
 	_Static_assert(sizeof(dump_avail) <= sizeof(pgbuf),
diff --git a/sys/riscv/riscv/minidump_machdep.c b/sys/riscv/riscv/minidump_machdep.c
index 8f5a4a4d1289..814c2dd00697 100644
--- a/sys/riscv/riscv/minidump_machdep.c
+++ b/sys/riscv/riscv/minidump_machdep.c
@@ -158,6 +158,7 @@ cpu_minidumpsys(struct dumperinfo *di, const struct minidumpstate *state)
 	pd_entry_t *l1, *l2, l2e;
 	pt_entry_t *l3, l3e;
 	struct minidumphdr mdhdr;
+	struct msgbuf *mbp;
 	uint32_t pmapsize;
 	vm_offset_t va, kva_max;
 	vm_paddr_t pa;
@@ -211,8 +212,9 @@ retry:
 	}
 
 	/* Calculate dump size */
+	mbp = state->msgbufp;
 	dumpsize = pmapsize;
-	dumpsize += round_page(msgbufp->msg_size);
+	dumpsize += round_page(mbp->msg_size);
 	dumpsize += round_page(sizeof(dump_avail));
 	dumpsize += round_page(BITSET_SIZE(vm_page_dump_pages));
 	VM_PAGE_DUMP_FOREACH(pa) {
@@ -230,7 +232,7 @@ retry:
 	bzero(&mdhdr, sizeof(mdhdr));
 	strcpy(mdhdr.magic, MINIDUMP_MAGIC);
 	mdhdr.version = MINIDUMP_VERSION;
-	mdhdr.msgbufsize = msgbufp->msg_size;
+	mdhdr.msgbufsize = mbp->msg_size;
 	mdhdr.bitmapsize = round_page(BITSET_SIZE(vm_page_dump_pages));
 	mdhdr.pmapsize = pmapsize;
 	mdhdr.kernbase = KERNBASE;
@@ -257,8 +259,7 @@ retry:
 		goto fail;
 
 	/* Dump msgbuf up front */
-	error = blk_write(di, (char *)msgbufp->msg_ptr, 0,
-	    round_page(msgbufp->msg_size));
+	error = blk_write(di, mbp->msg_ptr, 0, round_page(mbp->msg_size));
 	if (error)
 		goto fail;