git: 3dba010e4902 - main - memdesc: Replace md_opaque with a union of type-specific fields.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Fri, 14 Jul 2023 18:41:04 UTC
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=3dba010e4902b2e9106f1cc52967c5c71fcc25ab

commit 3dba010e4902b2e9106f1cc52967c5c71fcc25ab
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2023-07-14 18:30:57 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2023-07-14 18:32:21 +0000

    memdesc: Replace md_opaque with a union of type-specific fields.
    
    Reviewed by:    imp, markj
    Sponsored by:   Chelsio Communications
    Differential Revision:  https://reviews.freebsd.org/D41027
---
 sys/kern/subr_bus_dma.c |  8 ++++----
 sys/kern/subr_msan.c    |  4 ++--
 sys/sys/memdesc.h       | 13 ++++++++-----
 3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/sys/kern/subr_bus_dma.c b/sys/kern/subr_bus_dma.c
index bfaad30b37d3..329887affc99 100644
--- a/sys/kern/subr_bus_dma.c
+++ b/sys/kern/subr_bus_dma.c
@@ -557,19 +557,19 @@ bus_dmamap_load_mem(bus_dma_tag_t dmat, bus_dmamap_t map,
 	switch (mem->md_type) {
 	case MEMDESC_VADDR:
 		error = _bus_dmamap_load_buffer(dmat, map, mem->u.md_vaddr,
-		    mem->md_opaque, kernel_pmap, flags, NULL, &nsegs);
+		    mem->md_len, kernel_pmap, flags, NULL, &nsegs);
 		break;
 	case MEMDESC_PADDR:
 		error = _bus_dmamap_load_phys(dmat, map, mem->u.md_paddr,
-		    mem->md_opaque, flags, NULL, &nsegs);
+		    mem->md_len, flags, NULL, &nsegs);
 		break;
 	case MEMDESC_VLIST:
 		error = _bus_dmamap_load_vlist(dmat, map, mem->u.md_list,
-		    mem->md_opaque, kernel_pmap, &nsegs, flags, 0, SIZE_T_MAX);
+		    mem->md_nseg, kernel_pmap, &nsegs, flags, 0, SIZE_T_MAX);
 		break;
 	case MEMDESC_PLIST:
 		error = _bus_dmamap_load_plist(dmat, map, mem->u.md_list,
-		    mem->md_opaque, &nsegs, flags);
+		    mem->md_nseg, &nsegs, flags);
 		break;
 	case MEMDESC_BIO:
 		error = _bus_dmamap_load_bio(dmat, map, mem->u.md_bio,
diff --git a/sys/kern/subr_msan.c b/sys/kern/subr_msan.c
index 756d1fca4910..ec2492773243 100644
--- a/sys/kern/subr_msan.c
+++ b/sys/kern/subr_msan.c
@@ -1505,7 +1505,7 @@ kmsan_bus_dmamap_sync(struct memdesc *desc, bus_dmasync_op_t op)
 	    BUS_DMASYNC_PREWRITE) {
 		switch (desc->md_type) {
 		case MEMDESC_VADDR:
-			kmsan_check(desc->u.md_vaddr, desc->md_opaque,
+			kmsan_check(desc->u.md_vaddr, desc->md_len,
 			    "dmasync");
 			break;
 		case MEMDESC_BIO:
@@ -1524,7 +1524,7 @@ kmsan_bus_dmamap_sync(struct memdesc *desc, bus_dmasync_op_t op)
 	if ((op & BUS_DMASYNC_POSTREAD) != 0) {
 		switch (desc->md_type) {
 		case MEMDESC_VADDR:
-			kmsan_mark(desc->u.md_vaddr, desc->md_opaque,
+			kmsan_mark(desc->u.md_vaddr, desc->md_len,
 			    KMSAN_STATE_INITED);
 			break;
 		case MEMDESC_BIO:
diff --git a/sys/sys/memdesc.h b/sys/sys/memdesc.h
index 1c92ae5b1eb5..58aafb2a1f1b 100644
--- a/sys/sys/memdesc.h
+++ b/sys/sys/memdesc.h
@@ -50,7 +50,10 @@ struct memdesc {
 		struct uio		*md_uio;
 		struct mbuf		*md_mbuf;
 	} u;
-	size_t		md_opaque;	/* type specific data. */
+	union {				/* type specific data. */
+		size_t		md_len;	/* VADDR, PADDR */
+		int		md_nseg; /* VLIST, PLIST */
+	};
 	uint32_t	md_type;	/* Type of memory. */
 };
 
@@ -68,7 +71,7 @@ memdesc_vaddr(void *vaddr, size_t len)
 	struct memdesc mem;
 
 	mem.u.md_vaddr = vaddr;
-	mem.md_opaque = len;
+	mem.md_len = len;
 	mem.md_type = MEMDESC_VADDR;
 
 	return (mem);
@@ -80,7 +83,7 @@ memdesc_paddr(vm_paddr_t paddr, size_t len)
 	struct memdesc mem;
 
 	mem.u.md_paddr = paddr;
-	mem.md_opaque = len;
+	mem.md_len = len;
 	mem.md_type = MEMDESC_PADDR;
 
 	return (mem);
@@ -92,7 +95,7 @@ memdesc_vlist(struct bus_dma_segment *vlist, int sglist_cnt)
 	struct memdesc mem;
 
 	mem.u.md_list = vlist;
-	mem.md_opaque = sglist_cnt;
+	mem.md_nseg = sglist_cnt;
 	mem.md_type = MEMDESC_VLIST;
 
 	return (mem);
@@ -104,7 +107,7 @@ memdesc_plist(struct bus_dma_segment *plist, int sglist_cnt)
 	struct memdesc mem;
 
 	mem.u.md_list = plist;
-	mem.md_opaque = sglist_cnt;
+	mem.md_nseg = sglist_cnt;
 	mem.md_type = MEMDESC_PLIST;
 
 	return (mem);