Skip to content

Commit e3f269e

Browse files
AntonAltaparmakovIngo Molnar
authored andcommitted
x86/pm: Work around false positive kmemleak report in msr_build_context()
Since: 7ee18d6 ("x86/power: Make restore_processor_context() sane") kmemleak reports this issue: unreferenced object 0xf68241e0 (size 32): comm "swapper/0", pid 1, jiffies 4294668610 (age 68.432s) hex dump (first 32 bytes): 00 cc cc cc 29 10 01 c0 00 00 00 00 00 00 00 00 ....)........... 00 42 82 f6 cc cc cc cc cc cc cc cc cc cc cc cc .B.............. backtrace: [<461c1d50>] __kmem_cache_alloc_node+0x106/0x260 [<ea65e13b>] __kmalloc+0x54/0x160 [<c3858cd2>] msr_build_context.constprop.0+0x35/0x100 [<46635aff>] pm_check_save_msr+0x63/0x80 [<6b6bb938>] do_one_initcall+0x41/0x1f0 [<3f3add60>] kernel_init_freeable+0x199/0x1e8 [<3b538fde>] kernel_init+0x1a/0x110 [<938ae2b2>] ret_from_fork+0x1c/0x28 Which is a false positive. Reproducer: - Run rsync of whole kernel tree (multiple times if needed). - start a kmemleak scan - Note this is just an example: a lot of our internal tests hit these. The root cause is similar to the fix in: b0b592c x86/pm: Fix false positive kmemleak report in msr_build_context() ie. the alignment within the packed struct saved_context which has everything unaligned as there is only "u16 gs;" at start of struct where in the past there were four u16 there thus aligning everything afterwards. The issue is with the fact that Kmemleak only searches for pointers that are aligned (see how pointers are scanned in kmemleak.c) so when the struct members are not aligned it doesn't see them. Testing: We run a lot of tests with our CI, and after applying this fix we do not see any kmemleak issues any more whilst without it we see hundreds of the above report. From a single, simple test run consisting of 416 individual test cases on kernel 5.10 x86 with kmemleak enabled we got 20 failures due to this, which is quite a lot. With this fix applied we get zero kmemleak related failures. Fixes: 7ee18d6 ("x86/power: Make restore_processor_context() sane") Signed-off-by: Anton Altaparmakov <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Acked-by: "Rafael J. Wysocki" <[email protected]> Cc: [email protected] Cc: Linus Torvalds <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fc7f27c commit e3f269e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

arch/x86/include/asm/suspend_32.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212

1313
/* image of the saved processor state */
1414
struct saved_context {
15-
/*
16-
* On x86_32, all segment registers except gs are saved at kernel
17-
* entry in pt_regs.
18-
*/
19-
u16 gs;
2015
unsigned long cr0, cr2, cr3, cr4;
2116
u64 misc_enable;
2217
struct saved_msrs saved_msrs;
@@ -27,6 +22,11 @@ struct saved_context {
2722
unsigned long tr;
2823
unsigned long safety;
2924
unsigned long return_address;
25+
/*
26+
* On x86_32, all segment registers except gs are saved at kernel
27+
* entry in pt_regs.
28+
*/
29+
u16 gs;
3030
bool misc_enable_saved;
3131
} __attribute__((packed));
3232

0 commit comments

Comments
 (0)