git: e48770de6831 - main - arm64: Use void pointers for arguments to arm64_get_writable_addr

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Fri, 15 Mar 2024 17:10:41 UTC
The branch main has been updated by jhb:

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

commit e48770de6831dc152aaeb2c0b70fcfb2a346bb89
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2024-03-15 17:10:24 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-03-15 17:10:24 +0000

    arm64: Use void pointers for arguments to arm64_get_writable_addr
    
    No functional change, but this reduces diffs with CheriBSD downstream.
    
    Reviewed by:    andrew
    Sponsored by:   University of Cambridge, Google, Inc.
    Differential Revision:  https://reviews.freebsd.org/D44344
---
 sys/arm64/arm64/db_interface.c         |  6 +++---
 sys/arm64/arm64/machdep.c              | 11 ++++++-----
 sys/arm64/include/cpufunc.h            |  2 +-
 sys/cddl/dev/fbt/aarch64/fbt_isa.c     |  4 ++--
 sys/cddl/dev/kinst/aarch64/kinst_isa.c |  4 ++--
 5 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/sys/arm64/arm64/db_interface.c b/sys/arm64/arm64/db_interface.c
index 1aaec9665550..79e81b210f49 100644
--- a/sys/arm64/arm64/db_interface.c
+++ b/sys/arm64/arm64/db_interface.c
@@ -155,7 +155,7 @@ int
 db_write_bytes(vm_offset_t addr, size_t size, char *data)
 {
 	jmp_buf jb;
-	void *prev_jb;
+	void *prev_jb, *kaddr;
 	char *dst;
 	size_t i;
 	int ret;
@@ -163,7 +163,7 @@ db_write_bytes(vm_offset_t addr, size_t size, char *data)
 	prev_jb = kdb_jmpbuf(jb);
 	ret = setjmp(jb);
 	if (ret == 0) {
-		if (!arm64_get_writable_addr(addr, &addr)) {
+		if (!arm64_get_writable_addr((void *)addr, &kaddr)) {
 			ret = 1;
 		} else {
 			dst = (char *)addr;
@@ -175,7 +175,7 @@ db_write_bytes(vm_offset_t addr, size_t size, char *data)
 			 * Ensure the I & D cache are in sync if we wrote
 			 * to executable memory.
 			 */
-			cpu_icache_sync_range((void *)addr, (vm_size_t)size);
+			cpu_icache_sync_range(kaddr, size);
 		}
 	}
 	(void)kdb_jmpbuf(prev_jb);
diff --git a/sys/arm64/arm64/machdep.c b/sys/arm64/arm64/machdep.c
index 2716182ca442..50b2cd15df3f 100644
--- a/sys/arm64/arm64/machdep.c
+++ b/sys/arm64/arm64/machdep.c
@@ -424,12 +424,12 @@ init_proc0(vm_offset_t kstack)
  * read-only, e.g. to patch kernel code.
  */
 bool
-arm64_get_writable_addr(vm_offset_t addr, vm_offset_t *out)
+arm64_get_writable_addr(void *addr, void **out)
 {
 	vm_paddr_t pa;
 
 	/* Check if the page is writable */
-	if (PAR_SUCCESS(arm64_address_translate_s1e1w(addr))) {
+	if (PAR_SUCCESS(arm64_address_translate_s1e1w((vm_offset_t)addr))) {
 		*out = addr;
 		return (true);
 	}
@@ -437,7 +437,7 @@ arm64_get_writable_addr(vm_offset_t addr, vm_offset_t *out)
 	/*
 	 * Find the physical address of the given page.
 	 */
-	if (!pmap_klookup(addr, &pa)) {
+	if (!pmap_klookup((vm_offset_t)addr, &pa)) {
 		return (false);
 	}
 
@@ -445,8 +445,9 @@ arm64_get_writable_addr(vm_offset_t addr, vm_offset_t *out)
 	 * If it is within the DMAP region and is writable use that.
 	 */
 	if (PHYS_IN_DMAP(pa)) {
-		addr = PHYS_TO_DMAP(pa);
-		if (PAR_SUCCESS(arm64_address_translate_s1e1w(addr))) {
+		addr = (void *)PHYS_TO_DMAP(pa);
+		if (PAR_SUCCESS(arm64_address_translate_s1e1w(
+		    (vm_offset_t)addr))) {
 			*out = addr;
 			return (true);
 		}
diff --git a/sys/arm64/include/cpufunc.h b/sys/arm64/include/cpufunc.h
index 1903af965a68..ba712f48b262 100644
--- a/sys/arm64/include/cpufunc.h
+++ b/sys/arm64/include/cpufunc.h
@@ -191,7 +191,7 @@ int arm64_icache_sync_range_checked(void *, vm_size_t);
 void arm64_dcache_wbinv_range(void *, vm_size_t);
 void arm64_dcache_inv_range(void *, vm_size_t);
 void arm64_dcache_wb_range(void *, vm_size_t);
-bool arm64_get_writable_addr(vm_offset_t, vm_offset_t *);
+bool arm64_get_writable_addr(void *, void **);
 
 #endif	/* _KERNEL */
 #endif	/* _MACHINE_CPUFUNC_H_ */
diff --git a/sys/cddl/dev/fbt/aarch64/fbt_isa.c b/sys/cddl/dev/fbt/aarch64/fbt_isa.c
index 30117202f8e7..4f6d28c2f32b 100644
--- a/sys/cddl/dev/fbt/aarch64/fbt_isa.c
+++ b/sys/cddl/dev/fbt/aarch64/fbt_isa.c
@@ -71,9 +71,9 @@ fbt_invop(uintptr_t addr, struct trapframe *frame, uintptr_t rval)
 void
 fbt_patch_tracepoint(fbt_probe_t *fbt, fbt_patchval_t val)
 {
-	vm_offset_t addr;
+	void *addr;
 
-	if (!arm64_get_writable_addr((vm_offset_t)fbt->fbtp_patchpoint, &addr))
+	if (!arm64_get_writable_addr(fbt->fbtp_patchpoint, &addr))
 		panic("%s: Unable to write new instruction", __func__);
 
 	*(fbt_patchval_t *)addr = val;
diff --git a/sys/cddl/dev/kinst/aarch64/kinst_isa.c b/sys/cddl/dev/kinst/aarch64/kinst_isa.c
index 0e5d5eee2979..20ca26219a55 100644
--- a/sys/cddl/dev/kinst/aarch64/kinst_isa.c
+++ b/sys/cddl/dev/kinst/aarch64/kinst_isa.c
@@ -235,9 +235,9 @@ kinst_invop(uintptr_t addr, struct trapframe *frame, uintptr_t scratch)
 void
 kinst_patch_tracepoint(struct kinst_probe *kp, kinst_patchval_t val)
 {
-	vm_offset_t addr;
+	void *addr;
 
-	if (!arm64_get_writable_addr((vm_offset_t)kp->kp_patchpoint, &addr))
+	if (!arm64_get_writable_addr(kp->kp_patchpoint, &addr))
 		panic("%s: Unable to write new instruction", __func__);
 	*(kinst_patchval_t *)addr = val;
 	cpu_icache_sync_range(kp->kp_patchpoint, INSN_SIZE);