Skip to contentSkip to conversation

iomem: Adjust address width for 64-bit addresses

PATCH In review Lingxiang Zheng 2 participants 2 messages May 11, 2023 – May 14, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iomem: Adjust address width for 64-bit addresses

Modify the address width determination in /proc/iomem output to better handle 64-bit addresses. The previous implementation did not correctly account for 64-bit address space, as it would limit the address width to 8 hexadecimal characters. This change adjusts the address width according to the following conditions:

1. If the resource's end address is less than 0x10000, set the width to 4.
2. If the resource's end address is greater than 0xFFFFFFFF, set the width to 16.
3. For other cases, set the width to 8.

---
 kernel/resource.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/resource.c +1 -1
index b1763b2fd7ef..d8f977d628f5 100644
@@ -110,7 +110,7 @@ static int r_show(struct seq_file *m, void *v)
 	struct resource *root = pde_data(file_inode(m->file));
 	struct resource *r = v, *p;
 	unsigned long long start, end;
-	int width = root->end < 0x10000 ? 4 : 8;
+	int width = root->end < 0x10000 ? 4 : root->end > 0xFFFFFFFF ? 16 : 8;
 	int depth;
 
 	for (depth = 0, p = r; depth < MAX_IORES_LEVEL; depth++, p = p->parent)
Signature · 1 line
2.17.1
#1 lore raw
Quoted 5 lines · Lingxiang Zheng

Modify the address width determination in /proc/iomem output to better handle 64-bit addresses. The previous implementation did not correctly account for 64-bit address space, as it would limit the address width to 8 hexadecimal characters.

Note that the width is the *minimum* number of characters to print (with zero padding due to the zero in front in the printf format). Not the maximum.

I do not believe we actually want to expand the width to be 16 characters wide, just because it's above the 4GB area. That would make the numbers huge.

The main reason for the 4/8 split is actually for the IO port cases, ie we do *not* want to show IO ports (that are limited to 16 bits) as 8 hex-char wide.

So think of the 4/8 as a visual distinction between the iomem and ioports files.

And yes, I'm aware that some platforms have IO ports that are larger than 16 bits, and on those platforms as a result the iomem and ioports files will have similar visual behavior.

Linus