From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2F33C54E67 for ; Thu, 14 Mar 2024 14:27:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5706A800B2; Thu, 14 Mar 2024 10:27:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F6D3800A9; Thu, 14 Mar 2024 10:27:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3BE7A800B2; Thu, 14 Mar 2024 10:27:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2541B800A9 for ; Thu, 14 Mar 2024 10:27:53 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id EC2BCA1B45 for ; Thu, 14 Mar 2024 14:27:52 +0000 (UTC) X-FDA: 81895873584.18.88D3C2D Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf22.hostedemail.com (Postfix) with ESMTP id E8C0AC0019 for ; Thu, 14 Mar 2024 14:27:49 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (strict), No valid DKIM" header.from=tuxera.com (policy=none); spf=pass (imf22.hostedemail.com: domain of "SRS0=xxXR=KU=tuxera.com=anton@kernel.org" designates 145.40.73.55 as permitted sender) smtp.mailfrom="SRS0=xxXR=KU=tuxera.com=anton@kernel.org" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710426470; a=rsa-sha256; cv=none; b=0Yf61WX4BpqKut7DwgvOHiYIufylqSaHNoAhEkDHoqKExywUxVrxz/76OTTP0LKhBc9DTb vzUCcV8T7Pb9w0K7+ojUYq42+PDcwZBqT4ZC6alTX5fuagpnhPGvidBvOjdFvvsq1gtW/z FE/GQkgV+lhwWzXlqsLpRhNuhPTlU0k= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (strict), No valid DKIM" header.from=tuxera.com (policy=none); spf=pass (imf22.hostedemail.com: domain of "SRS0=xxXR=KU=tuxera.com=anton@kernel.org" designates 145.40.73.55 as permitted sender) smtp.mailfrom="SRS0=xxXR=KU=tuxera.com=anton@kernel.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710426470; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=yNzBwKGRaBD8rVpq5ZTaJKJiEU4cHFKwEqI507BGMUI=; b=wMZUIxUJyv29OWEARkTPRT2AICpzml5DPM19UCJqs/TCodqvBVyqV6T0EOXG+go2kZS79X A4+TWioeF8oq8z8wfAfDBC9OgOYi7BftbDmycZP9j1KDbpGmY/4/VgQawpNuHNXqhUIpJM ZAB3tQccX+Ux2NKAD9I0pH/byr8Dv1o= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 48A8BCE1BB9; Thu, 14 Mar 2024 14:27:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0086C433C7; Thu, 14 Mar 2024 14:27:41 +0000 (UTC) From: Anton Altaparmakov To: "Rafael J . Wysocki" , Pavel Machek , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Chen Yu Cc: Pawan Gupta , Catalin Marinas , linux-mm@kvack.org, Matthieu Baerts , Mat Martineau , "Rafael J . Wysocki" , Ingo Molnar , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Anton Altaparmakov , stable@vger.kernel.org Subject: [PATCH] x86/pm: Fix false positive kmemleak report in msr_build_context(). Date: Thu, 14 Mar 2024 14:26:56 +0000 Message-Id: <20240314142656.17699-1-anton@tuxera.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: E8C0AC0019 X-Stat-Signature: if3h6pciyqah3og8opng67q9zzwzkdjq X-Rspam-User: X-HE-Tag: 1710426469-858361 X-HE-Meta: U2FsdGVkX19LXV5yPXJeHODodybA+v4CZ8x8nm4vmRNnAnIFuxbUluUXlyNfUo2ENR0yazeposv6hDt2MDZjU9E8X0voNMW+1c0+cv3fCbL5rpvMG3tgBUK9KrlSqvnxX89cmR0Dzali/LL2ZudTw+cgXFJlMX/EldFuqj1XWMTHVpI5OFOspK7q5rWXAerBROp9JcUjtqdYm0RUgRP9iKNhfF3XFGik+XiKOk/dxBz4llV4xRTdIUO8xBmpD30uHgPQfu4sZaDiQcwNxnxBoyOmStd33bQTIlhcJMI7uXTxUNHqPiCCAgCgrp8qRaaK9KbnGDpIJejuM16LAc8d3nLV6L81TtUSAoz52yAOZ9icJcuLYwAc6ElFwblfYJJOQ2XIVtM+0K062HLET6GTlHPPyV/pvoXiLxeBXkK3A3YKx0GH/AYn2uQAbBBlJNcCsye8eyYobTDkEHWJQGt3rDWFEpFMDsVqt3APetDcW0Wl+QUtNafNSdgQ7wRgmDj0mAtW9l+mlVA/Mk/CwSZ1tmbHpg9vB8U3Y5XLekuOAK5XEbEnDX5U75ILxGcchz914eIbNJnsAu/wlmyZqhQTJp06E0ntpWkwXyHoC6RUCHoxilQzteWDfoYOOQhjEA4qnBL+Fd0uy9cL1R06dBlvvbi60SphC3IUdXaoQAg7kBCo1EejcokHyU84CYhn8iDGI/Dgq2Ft5KUF7Z8WtYD9Gcm0Gm/9PcS0D1AXp4dpT+8dYy2L7s8kJifuh3Kg7gcUWF6ZsfPQSXPmq7tO6MB4Tp0kZNVrAb9vCkmvn1KoKcvoywek89u525zE8uoymKrQR6KHbyPKKp1wr3/2RZ/RC6eLmAU0ra6BFLrx/UazhecIWQlCnxpueK50WSD6slnNIXLt5xUZMJEjU+wqS9U3W6jbZyA0kFIw6+fH9epus17McR5LP95a9fYKAQMm+X2AM2UMyO5OojXf/Ml/bon jq2kVk+k AfEqhzZNiWdbY4a8MuqvOANdfDKh8gEFO52hYDtPeySjOpvEwOZQ2izQN7iE+wPmuhVMpyezo0XtDJqFrUmc5gD84aHneg15ctYEb0DC6NAfjdHeWrxqD87IaePDpcedyUrOMKh9zxoFyW/GKz5IymuPt3TSXdIF3gfhIQF7YZUYAsLoPMwEfSMcPSejLIMH8M3fv X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Since 7ee18d677989 ("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 [] __kmalloc+0x54/0x160 [] 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 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 we expect the same as the equivalent fix in commit b0b592cf0836, i.e. 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. Note we have picked this up on 5.4, 6.1 and 6.6 kernels but we expect it is the same on all kernels >= 4.15 as the commit 7ee18d677989 which changed from having four u16 to a single u16 at the start of the struct was introduced in 4.15. Fixes: 7ee18d677989 ("x86/power: Make restore_processor_context() sane") Signed-off-by: Anton Altaparmakov Cc: stable@vger.kernel.org --- arch/x86/include/asm/suspend_32.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/suspend_32.h b/arch/x86/include/asm/suspend_32.h index a800abb1a992..d8416b3bf832 100644 --- a/arch/x86/include/asm/suspend_32.h +++ b/arch/x86/include/asm/suspend_32.h @@ -12,11 +12,6 @@ /* image of the saved processor state */ struct saved_context { - /* - * On x86_32, all segment registers except gs are saved at kernel - * entry in pt_regs. - */ - u16 gs; unsigned long cr0, cr2, cr3, cr4; u64 misc_enable; struct saved_msrs saved_msrs; @@ -27,6 +22,11 @@ struct saved_context { unsigned long tr; unsigned long safety; unsigned long return_address; + /* + * On x86_32, all segment registers except gs are saved at kernel + * entry in pt_regs. + */ + u16 gs; bool misc_enable_saved; } __attribute__((packed)); -- 2.39.3 (Apple Git-146)