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 B0FC5C83F34 for ; Fri, 18 Jul 2025 22:51:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D0C46B008A; Fri, 18 Jul 2025 18:51:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3815E6B0092; Fri, 18 Jul 2025 18:51:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 270346B0093; Fri, 18 Jul 2025 18:51:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 126036B008A for ; Fri, 18 Jul 2025 18:51:32 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A80DF801AA for ; Fri, 18 Jul 2025 22:51:31 +0000 (UTC) X-FDA: 83678883582.23.7E1F2D0 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf03.hostedemail.com (Postfix) with ESMTP id 0B40B20009 for ; Fri, 18 Jul 2025 22:51:29 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=VmiVcikE; spf=pass (imf03.hostedemail.com: domain of kees@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=kees@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752879090; a=rsa-sha256; cv=none; b=WVAxjGxPqQRJoMwxfqbbvWxcpQlqbd5CrOHWdU+lKeTTibUJkwAGCejmNUXAj0/8D0E3dB zaPBi5FUgFdwXnbMhaEQHpz+f/HUhZSryPB2DsNDnuI7y5k72Kk9wAI9ngeRoWOfLYyuju HNBNmEy5GNyPM6S2AAlVaGxajeFJuP0= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=VmiVcikE; spf=pass (imf03.hostedemail.com: domain of kees@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=kees@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1752879090; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TiUhvpXDad+ClqTl7bM8rtEMRDTcE9fVcXdDCASyHwQ=; b=2nTltjO0alsBqwmPfBnNT9oBPA9J9eMZLVocEwEr178PbXrDGqpYR+SCd2ycdS2354rcqf ejXZnd4Y/qbL7dK78olSOI3LJGK0fotRMVc+XjgQevvJMIrW9o9o4Lnu+3LUZFJh8l756f Uru1HUXDoPP9WBaihSJjEj4yRngjg2Q= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 1C057A57714; Fri, 18 Jul 2025 22:51:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A58ABC4CEEB; Fri, 18 Jul 2025 22:51:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752879088; bh=9wq1gPYvCplHPaY4Wm5XgoLMe+aODde2O7VcmHcmk98=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VmiVcikElcqZk72BFs7/zWioNVg/RlBsEZTqUIs6HsScTtVwOS6j7B3ua7R/5a+8f B/Xx/QRZM/EQh/lO2RicrfWNUj4TspYI7v5C1esxaGnMy5qNgSFrlaLuHCW1KuRQE/ vwjy0/1yadEDESYc6Jup2r2d1g6hRKk98N3uI9FiR3pIjtw/6N8d9/1A9DF/kI7Ptp /KtF2y8xo3+DKYzmZGh9ileKlyQIK4tsMmB+vc1VQguKTRnI0Md6sJRL9kCLGWssqH x60/sDs7wvwXbxMyYV4GlknlF8akcqkSZPz9pRU1nNtV+O7XtlJK1/hNvPy3K6SwqK vqLjSPHvQBQpQ== Date: Fri, 18 Jul 2025 15:51:28 -0700 From: Kees Cook To: Mike Rapoport , Will Deacon Cc: Arnd Bergmann , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Paolo Bonzini , Vitaly Kuznetsov , Henrique de Moraes Holschuh , Hans de Goede , Ilpo =?iso-8859-1?Q?J=E4rvinen?= , "Rafael J. Wysocki" , Len Brown , Masami Hiramatsu , Ard Biesheuvel , Michal Wilczynski , Juergen Gross , Andy Shevchenko , "Kirill A. Shutemov" , Roger Pau Monne , David Woodhouse , Usama Arif , "Guilherme G. Piccoli" , Thomas Huth , Brian Gerst , kvm@vger.kernel.org, ibm-acpi-devel@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-acpi@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-efi@vger.kernel.org, linux-mm@kvack.org, Ingo Molnar , "Gustavo A. R. Silva" , Christoph Hellwig , Andrey Konovalov , Andrey Ryabinin , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Nick Desaulniers , Bill Wendling , Justin Stitt , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-hardening@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kselftest@vger.kernel.org, sparclinux@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH v3 04/13] x86: Handle KCOV __init vs inline mismatches Message-ID: <202507181541.B8CFAC7E@keescook> References: <20250717231756.make.423-kees@kernel.org> <20250717232519.2984886-4-kees@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 0B40B20009 X-Stat-Signature: ckzx8zayasowksuxadqpqbygppnk5uge X-HE-Tag: 1752879089-821903 X-HE-Meta: U2FsdGVkX18Ts77iKoMThMtgWJJrpOjQZdTHzcfGZeISlpiFrcYHMQ1fEDS/4Glir3M2Er4dMXDj5l3dG+t1WKu9hLRxnpsjAqYCXCgP1dPrukuu4iImzIA0elK1CV7yxmVc6sY90FcivjG/Q6AZXwXbqiJvawfyN3wAahPzlzyd8USz9iwdXvgiuGW3zQXu5HI/Aop0OjVQjD2js0B1vKDij5x1A+tU7rUoIvjwBSQSGNkvEcdV+skSpid2gUSn60S3MmjJb0hF3HYzP04ipXvSIgYrn3PVqTUVFOdsSTn2ZVUAYoiDzQnYezj9xtz78p/Z44re6REB2iZ2us1P/MsryJe91Fwj8tkhpDUQ7qF9RP8AshcGYqJkchZlPq3855fQBzRSR9mbb3XamGBZcym4Fsr67FUvwuR3Z2P7bYoVmrN7jgemVqA2apu4hJCJDsTLNyXfCSW4T45Ql4E3tb+IT4lZSzeM/vABm69LVLKIlrLUPPdzGcTPWbDO2+T2Q4sgpC3V2il2AJg/3ELu5HEsgN0f1XBkojuSlStdaKJFxQVQ5JMmMB/1uhHC0k6ghQz4SrhtvjQG1erdwJqw7ZFLwqrivi7vqMBACKGAE6EqtW7hZ1sKEM2Kmy/ul+HCBN1FMo36Y74MLFp+K8a8/icP7mhMDNYPIdvZVlxlwgtPhVgg/CYL4BQQJjceo6BoI0YWukfV/YmXjkPQGSMEAfwb29BRyeyBRuebZ0EzP8Obk8l4PBW9oCiSgoig2HVb84kqFNxlPt2AH3wy5oz9UhDxl7pFzA07w1+QNeAAR6Jc1CG5OOa8zxcpat5wx9KmUT3VtY8VziR7MtK0BdlqVj37/6fgeSYkKvhi0jwkTZCEgiAhmEag2D7PRqmUg07EmzYV16hkUfe2IFeXD9dR7SnoyxKEDOWd+G4PK6v3RhB6/+UH11URixjNrERCSDw+b6wIM4A2K5QjONah6uk jSpawsOr FLzf8kiETeB31BYGbFisZ665rcyy10I0I6WyN9uNsbfyEqYxiAP/vpnBn4aLqRvGr2UTmzRLF36YTha//g5+8Rg79dpY2W0QbifGjhf3uSVjhB4VCYdaosY9YR75Y00X0HpAnvvdwnLBC0M0vscQ+LbCfkirUSKnGWt3b0dd06VinV5/sChQ6RpNCToifq8pfr82KKTfUtdStlYDwh6BlmStYGwwzNZ42t2YKXk3vqe9Lsgdz2CjyBDZsMbmLqkxtS+DZG0aXVV0qoDEzlC0R9uv77OIp/e4tUM7Q5jfCCjkNwZENsrcivzeYXqT1A9ufbXxSIWejgHcRd2JvJq2xGiy8Z8xXMQG+7exINjLJEcM9J69JfYJ7q+aX1s2Gg0Z1eXMiG/S0oIK0Mj0= 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: On Fri, Jul 18, 2025 at 11:36:32AM +0300, Mike Rapoport wrote: > Hi Kees, > > On Thu, Jul 17, 2025 at 04:25:09PM -0700, Kees Cook wrote: > > When KCOV is enabled all functions get instrumented, unless the > > __no_sanitize_coverage attribute is used. To prepare for > > __no_sanitize_coverage being applied to __init functions, we have to > > handle differences in how GCC's inline optimizations get resolved. For > > x86 this means forcing several functions to be inline with > > __always_inline. > > > > Signed-off-by: Kees Cook > > ... > > > diff --git a/include/linux/memblock.h b/include/linux/memblock.h > > index bb19a2534224..b96746376e17 100644 > > --- a/include/linux/memblock.h > > +++ b/include/linux/memblock.h > > @@ -463,7 +463,7 @@ static inline void *memblock_alloc_raw(phys_addr_t size, > > NUMA_NO_NODE); > > } > > > > -static inline void *memblock_alloc_from(phys_addr_t size, > > +static __always_inline void *memblock_alloc_from(phys_addr_t size, > > phys_addr_t align, > > phys_addr_t min_addr) > > I'm curious why from all memblock_alloc* wrappers this is the only one that > needs to be __always_inline? Thread-merge[1], adding Will Deacon, who was kind of asking the same question. Based on what I can tell, GCC has kind of fragile inlining logic, in the sense that it can change whether or not it inlines something based on optimizations. It looks like the kcov instrumentation being added (or in this case, removed) from a function changes the optimization results, and some functions marked "inline" are _not_ inlined. In that case, we end up with __init code calling a function not marked __init, and we get the build warnings I'm trying to eliminate. So, to Will's comment, yes, the problem is somewhat fragile (though using either __always_inline or __init will deterministically solve it). We've tripped over this before with GCC and the solution has usually been to just use __always_inline and move on. For memblock_alloc*, it appears to be that the heuristic GCC uses resulted in only memblock_alloc_from() being a problem in this case. I can certainly mark them all as __always_inline if that is preferred. Some maintainers have wanted things marked __init, some have wanted __always_inline. I opted for __always_inline since that was basically the intent of marking a function "inline" in the first place. I am happy to do whatever. :) -Kees [1] https://lore.kernel.org/lkml/aHouXI5-tyQw78Ht@willie-the-truck/ -- Kees Cook