Skip to contentSkip to conversation

mm/alloc_tag: account for reserved tag ids in the kernel tag check

PATCH Applied Hao Ge 2 participants 2 messages Sep 16 – Sep 18

Subsystems (3)
lore
Share & tools
lore

Hao Ge

author reviewer
#0 lore raw

PATCH 1/1 mm/alloc_tag: account for reserved tag ids in the kernel tag check

The tag ids stored in the page flags include two reserved markers. Id 0 means the page has no tag and id 1 means the tag was cleared, so real tags start at CODETAG_ID_FIRST. The kernel-side check in alloc_tag_sec_init() compared kernel_tags.count alone against the addressable limit, so with the count at or just under the limit the last tag ids wrapped into those markers. Pages allocated through them then look the same as untagged pages on free, nothing is ever subtracted from the real tag and /proc/allocinfo shows that memory as still allocated.

Add the missing CODETAG_ID_FIRST, same as tags_addressable().

Fixes 4835f747d3ed ("alloc_tag: support for page allocation tag compression")
---
 mm/alloc_tag.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/alloc_tag.c +1 -1
index cfa0fc84b68f..cf100e7a852f 100644
@@ -629,7 +629,7 @@ void __init alloc_tag_sec_init(void)
 	kernel_tags.count = last_codetag - kernel_tags.first_tag;
 
 	/* Check if kernel tags fit into page flags */
-	if (kernel_tags.count > (1UL << NR_UNUSED_PAGEFLAG_BITS)) {
+	if (CODETAG_ID_FIRST + kernel_tags.count > (1UL << NR_UNUSED_PAGEFLAG_BITS)) {
 		shutdown_mem_profiling(false); /* allocinfo file does not exist yet */
 		pr_err("%lu allocation tags cannot be references using %d available page flag bits. Memory allocation profiling is disabled!\n",
 			kernel_tags.count, NR_UNUSED_PAGEFLAG_BITS);
Signature · 1 line
2.25.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Hao Ge

The tag ids stored in the page flags include two reserved markers. Id 0 means the page has no tag and id 1 means the tag was cleared, so real tags start at CODETAG_ID_FIRST. The kernel-side check in alloc_tag_sec_init() compared kernel_tags.count alone against the addressable limit, so with the count at or just under the limit the last tag ids wrapped into those markers. Pages allocated through them then look the same as untagged pages on free, nothing is ever subtracted from the real tag and /proc/allocinfo shows that memory as still allocated.

Quoted 5 lines

Add the missing CODETAG_ID_FIRST, same as tags_addressable().

Fixes 4835f747d3ed ("alloc_tag: support for page allocation tag compression")

Nice catch!

Quoted 20 lines
---
 mm/alloc_tag.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/alloc_tag.c +1 -2
index cfa0fc84b68f..cf100e7a852f 100644
@@ -629,7 +629,7 @@ void __init alloc_tag_sec_init(void)
        kernel_tags.count = last_codetag - kernel_tags.first_tag;
 
        /* Check if kernel tags fit into page flags */
-       if (kernel_tags.count > (1UL << NR_UNUSED_PAGEFLAG_BITS)) {
+       if (CODETAG_ID_FIRST + kernel_tags.count > (1UL << NR_UNUSED_PAGEFLAG_BITS)) {
                shutdown_mem_profiling(false); /* allocinfo file does not exist yet */
                pr_err("%lu allocation tags cannot be references using %d available page flag bits. Memory allocation profiling is disabled!\n",
                        kernel_tags.count, NR_UNUSED_PAGEFLAG_BITS);
--

2.25.1