git: 4057fb12a1d7 - stable/13 - arm64: fix db_read_bytes() for size == 8

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Mon, 22 Jan 2024 18:07:42 UTC
The branch stable/13 has been updated by mhorne:

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

commit 4057fb12a1d7147b85062ad9f3916138c3956cf3
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2024-01-17 16:45:41 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2024-01-22 18:05:27 +0000

    arm64: fix db_read_bytes() for size == 8
    
    There is a mistake in the cast, resulting in a truncated read to tmp64.
    Switch from int to uint64_t, and adjust the other casts for clarity.
    
    Add a comment explaining why we do this at all.
    
    Reported by:    dfr
    Reviewed by:    dfr, mmel, emaste, jhb (all a previous version)
    PR:             276406
    Fixes:          a67687fcd8f5 ("Use native-sized accesses when accessing memory from kdb")
    Differential Revision:  https://reviews.freebsd.org/D43479
    
    (cherry picked from commit 9c2e1a54f71a399fc4645c4b8bed044705629143)
---
 sys/arm64/arm64/db_interface.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/sys/arm64/arm64/db_interface.c b/sys/arm64/arm64/db_interface.c
index 0c369ba87709..65af5395500e 100644
--- a/sys/arm64/arm64/db_interface.c
+++ b/sys/arm64/arm64/db_interface.c
@@ -125,14 +125,20 @@ db_read_bytes(vm_offset_t addr, size_t size, char *data)
 
 	if (ret == 0) {
 		src = (const char *)addr;
+
+		/*
+		 * Perform a native-sized memory access, if possible. This
+		 * enables reading from MMIO devices that don't support single
+		 * byte access.
+		 */
 		if (size == 8 && (addr & 7) == 0) {
-			tmp64 = *((const int *)src);
+			tmp64 = *((const uint64_t *)src);
 			src = (const char *)&tmp64;
 		} else if (size == 4 && (addr & 3) == 0) {
-			tmp32 = *((const int *)src);
+			tmp32 = *((const uint32_t *)src);
 			src = (const char *)&tmp32;
 		} else if (size == 2 && (addr & 1) == 0) {
-			tmp16 = *((const short *)src);
+			tmp16 = *((const uint16_t *)src);
 			src = (const char *)&tmp16;
 		}
 		while (size-- > 0)