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 94AF7C83F1A for ; Mon, 21 Jul 2025 12:48:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 31D376B0095; Mon, 21 Jul 2025 08:48:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F53C6B0096; Mon, 21 Jul 2025 08:48:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20AA46B0098; Mon, 21 Jul 2025 08:48:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0F1896B0095 for ; Mon, 21 Jul 2025 08:48:12 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8B59E140630 for ; Mon, 21 Jul 2025 12:48:11 +0000 (UTC) X-FDA: 83688249582.30.B105DE3 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf27.hostedemail.com (Postfix) with ESMTP id CB8F840007 for ; Mon, 21 Jul 2025 12:48:09 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=R8evXuR+; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf27.hostedemail.com: domain of will@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=will@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1753102090; a=rsa-sha256; cv=none; b=d7TJsBanyYhTxxYjkDSrIO+AU36k7IU1xr5hFLmtUo47KI6OCJMQsTy4suCzdrqgZvbyfz 4sJarZUymho/kpxRxDsNh9Bi/eOnbrt73J3LkdbP6bZjEgmjjlRvpyCWufdU2QrE4E4yfH AB9K6Y0S7yxo5nSj/K3sjP7O1/YxELw= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=R8evXuR+; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf27.hostedemail.com: domain of will@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=will@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1753102090; 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=JNY/7LVwGObkKrkAzqd3rzEZ1tZqg3bLZxiEvapvi/A=; b=JBe852fkCtnlvrfZe3uGNIwUIHPoVx3WTTuZxFDdjJ27Miy/3Wv5U9UZwJrOcXCulQfxhr 5Y/HaE5Nu9PFnrfBofEaK5RnNA39ubykyDMjOCjbqIFEvK7O1yuYGIvO7VceLRtFVhX4f7 //7gxNYHilUn7uueR4mrL2gD9BmgQiQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 8073E43CF0; Mon, 21 Jul 2025 12:48:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2550C4CEED; Mon, 21 Jul 2025 12:47:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753102088; bh=fhUrUAac/iSii6E8bCY5/2OzAP/25KtTiniEKeJQXGA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=R8evXuR+wAan3GKqOPc31OKb0HXwT1fcr9RAvjn3iXq9AafrC9dr+uhqKKHXhydc/ ommMgMhlPSa10h8tXea70KugAvoZCogNM+Xt21kS9UmsttjWDnOELNHjux+Ju59MNY /URVoorMncYyCzvX9VeofQFk7WldoN/Ri5qk6rB1XFXfi+hA14lKHW1R2sRPlxfo/E LGLDW2D8KsMU/Gla3tq/bXrtgsgK9NPEPhMAYMtEgjB4rEKVqgNW9ZLANwHmFPzbv2 KyzNMpjT5XzFw+NFZx3vex8f/0R9leYdi3PuQeMO27/gBBOFaJYqsNHIsKj7h+b3pJ 6c41KggZR4CKg== Date: Mon, 21 Jul 2025 13:47:55 +0100 From: Will Deacon To: Ard Biesheuvel Cc: Kees Cook , Mike Rapoport , 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 , 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: References: <20250717231756.make.423-kees@kernel.org> <20250717232519.2984886-4-kees@kernel.org> <202507181541.B8CFAC7E@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: ieqp6g737weq5yb6har4uz8r97d1qbzi X-Rspam-User: X-Rspamd-Queue-Id: CB8F840007 X-Rspamd-Server: rspam02 X-HE-Tag: 1753102089-536613 X-HE-Meta: U2FsdGVkX1+Myqj3dzOXUwZ0Jv0oV6PqEK4AEaOS/doFIw4/hRfY5jmaCFqrLnM8mX4uL9luSOISZeIqjc6tDWg3/BblUbMoqY6DH+YQi3IweN8QT9aN3jyDVbeZuKBSMjuF8W1W7uzoS3DQqUjg7EZrecW1W0GuRa9xg1V0bPNx2Hc52XnEFVodIgxXvJ26iFjp3sDHp3TMPozcC0t6+tEwetQnVVhjjtyxBsypyYa/u27TzJ6mbiGw3WtEo4Pyppk9A/G2YdV3IwIuWhzEYfgNWd5UQqLRABqaWW+w+LkndhrrLywx5MirSfT+JZeZbtCdWB/BTw79Iq9FwAwWGP6QA8JIyz/1icjF0Ek3TM/4iwYm/VuWwi0mC2rbiTw42VMS3j4+rHcFgd6+/elHtHCgdKNLPqmb515wO5bib+ysfyCmjk70ZeMqdDUJhUVEXs5gWK2BRfEaiDePUGi44CfW3MDkBuCphHoyRJymqoDylyHvGZgF6qPJQe4Lt8lAVwBNhL/X/MXr0GpG+DCEEFuDBZrXeN6SokJTBXK1Yem3abPhvPJfXyeNUZ8jN13Pa/bdUpJ+v6/kgrYtlOEkMI+/DAFhRjWPAWu6S9STP5O05FWpHS1xOrOz1rDm1vAuBxDUvKR4q7FZNFic7/RECMCST0iMwG4ozBiOIN4ULEp0ZMeDE8mdnPgvy+v/2PTcIySqEEYOGbaLtYZGGyY1RPimHushvUqZBH8H33yMbfQlm7tn6nMWqm/fnGf83El7GQqojKfAkX0yyz7Q3fY/iZqiZe1ZWgVS8LUlXVPx+OGNi8aPghLxWqDObwBNRS5Ix/uGzBQE2DXB8K1kTqaIdXa3sD6mjK3bTrNFr1MtYXOEuCUZN15qmcEeamLsGqMsB5XkpTmT1M1rDC2sPwxgNis5J4ydPbESgGo57CWpOrflDgHKcxnv8M7QENa5VqSPZLjTyZyvIdhNdx1ZYt4 +vEHwukx GaUxn8xfWMseHJex2Jl3XYleHaNu8nOVXX50fuCe5DrF2ZXYM1VUeVc4kqZMJu7b3Gwu/wwmjR3Yr+Hi0uYqreSH2Est9xgeH4znArvZ6puyeu+NZ+VdKNa+hRm2z/1B4lKRJeZ+OaZC+zP4JmAv23kJaCxhQExc3JEk4yWtBfBXaK9ajvvhgabsD0Rfu/qtFkVxPub4YjNjxAYx7En1Pr/z3/fwHIflBTMlLab5JU1zJV8SXJsK3Hq6fdVSSTahFxTk/T9Lk8Qz5zfK5zT5xLnky1ipsjfLGjtokPz6lMCGgSxaAN550b37yZQdJkB3TMAAD5jY+lBsCGi7adW86CMwOMV+6fSKsh4wg70gNg9YMpBIdSYANNNGPsM9H6lVaeu1HVxO9sF+ILQo= 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 Sun, Jul 20, 2025 at 04:10:01PM +1000, Ard Biesheuvel wrote: > On Sat, 19 Jul 2025 at 08:51, Kees Cook wrote: > > On Fri, Jul 18, 2025 at 11:36:32AM +0300, Mike Rapoport wrote: > > > 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. Got it, thanks for the explanation! > > 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. > > > > Given that 'inline' is already a macro in the kernel, could we just > add __attribute__((__always_inline__)) to it when KCOV is enabled? That sounds like a more robust approach and, by the sounds of it, we could predicate it on GCC too. That would also provide a neat place for a comment describing the problem. Kees, would that work for you? Will