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 C4728C83F22 for ; Sun, 20 Jul 2025 06:10:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 03EE96B009E; Sun, 20 Jul 2025 02:10:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 016B36B009F; Sun, 20 Jul 2025 02:10:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E6E066B00A0; Sun, 20 Jul 2025 02:10:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D5DCF6B009E for ; Sun, 20 Jul 2025 02:10:23 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4A1A4590D8 for ; Sun, 20 Jul 2025 06:10:23 +0000 (UTC) X-FDA: 83683618326.12.437B708 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf12.hostedemail.com (Postfix) with ESMTP id 3DBB540003 for ; Sun, 20 Jul 2025 06:10:21 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HcocEkaA; spf=pass (imf12.hostedemail.com: domain of ardb@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=ardb@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=1752991821; 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=t2QvY3fOBT8/ZYLhOHy9kLcm/GpPoBHvrrqhkIbhsag=; b=TOUtpm/jGCcHaMWANV8ZOaOHa2j4cOqyTYPL8ThKzIBqUSSFcI8h9C20CPuSrWZjbZ5H2u aEPRLQQdZNubNnqSGmO62zH9sw1PO7AmpQd9hexAFhO4qbWJ+fAl/oWRh7ReIJUwZYsP+X 7yDlPPG9y2houaJKJe8Lfz3MiWclPUA= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HcocEkaA; spf=pass (imf12.hostedemail.com: domain of ardb@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=ardb@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752991821; a=rsa-sha256; cv=none; b=YcrURIsvGzozjOcQFxWchicMc5+K75eZJbXmnr5A1/lnsoZWgNKf9Uj0lXpfr7DVlBle2r 6avnyMi+pkLwILBFoufksVCxNfNZAKeK6whHXzHwagM5BsvlLCADHfV8cJ3N8d5lrmsu3W RJJJS+VlA/fJYT8Hl2vGVI/Giujinos= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id DDB2243989 for ; Sun, 20 Jul 2025 06:10:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 987DDC4CEF8 for ; Sun, 20 Jul 2025 06:10:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752991819; bh=ombXy5J9mN5+Ko6iFhW8NndKJFf3Fpi4o6CQRaezi3g=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=HcocEkaAHqoiHoBCIs5ZO1zgy5A6mlv32UCcJW8LJrNOH9xTJsjCjR+0l+k+rDugt FfJRK0wuMhP1+l40qQ4Zsqb2kNgofBEYfXVrDcz5S49YWRrNZuwLyidR4kwpzmO+j+ 2Ti22ok5s651Cl0DKENNJulslvkPPeDYInLV6/E1rLq+3JS2kHByx10FDPlWtaaYoO zbBEeae5MrdFJ4uyBR+eocuvKJFVtcaQkoastPWeZ1nTyt+lAAqN/K7z9f9MgU77QF ns3N6LeIPgbEVfylgBuIAeVsTpY9WQPioWqB+bD85jLB/SdJceatFgmEgi7I3n/vBJ jDFV6fT3ykiRg== Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-5561ab55c4dso3448917e87.2 for ; Sat, 19 Jul 2025 23:10:19 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCW5jZzIXjaDqW/dFe4sdpVfzlfI85uE2F30jwn2LMfLKI2ibnzYtb0gk8IVh6uHHn8oltGSSfkIzg==@kvack.org X-Gm-Message-State: AOJu0YwBnP8s20Ur+CLoJLvWT+wD9VH0At8tM1oYy8GQn3x8rwGz3XVt Dv0T5PARphWXSCN4wg94wd2cG91jAv7hFi2Ny0tmUpTgBHPUvtfLOGVeUZ70sibMRFTTgA0A9ja neXUxbLPTdEFrwaBplFQrFudhaiD3sZU= X-Google-Smtp-Source: AGHT+IGzW7z8MZyh/6NVryj0xIRWvZtmGLwUiyHXGC4Qk/FYdRSLZqwcI4BFS0lrRzeksvOsF0eTUUFywEq3kCkPty0= X-Received: by 2002:a05:6512:2301:b0:553:5176:48a with SMTP id 2adb3069b0e04-55a31843110mr2007807e87.21.1752991817889; Sat, 19 Jul 2025 23:10:17 -0700 (PDT) MIME-Version: 1.0 References: <20250717231756.make.423-kees@kernel.org> <20250717232519.2984886-4-kees@kernel.org> <202507181541.B8CFAC7E@keescook> In-Reply-To: <202507181541.B8CFAC7E@keescook> From: Ard Biesheuvel Date: Sun, 20 Jul 2025 16:10:01 +1000 X-Gmail-Original-Message-ID: X-Gm-Features: Ac12FXxx6bD_QGQsGFgOANxpcIEdVmgITnXc8yZmdE0EdDE9cBbQCb787bRnEwA Message-ID: Subject: Re: [PATCH v3 04/13] x86: Handle KCOV __init vs inline mismatches To: Kees Cook Cc: Mike Rapoport , Will Deacon , 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 , =?UTF-8?Q?Ilpo_J=C3=A4rvinen?= , "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 Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: beiw3xy85homimc8qbb3z5etzgtdqeyy X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 3DBB540003 X-Rspam-User: X-HE-Tag: 1752991821-940522 X-HE-Meta: U2FsdGVkX1/aYR8uGV/WEZlenJu9vm+10lYT1eH5sGSDDgOgp6/4NyY830DMziLr5CiZB2pzpIl/k9Kg6A7SptPrU4SEFFqdze65YGbC+u4qUtN5OxpVwBEy2d3NmMj0UHeOyru2yu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TJnoYTOgHSgrTLtmC1HufNf70VitrbF1acqdMd4dFy/DY28DMP6nfgCHnyzo9mjY1jXzjfd9RYt4UOqrKWmP+zSrtF8Uu7Ws+awuROC55Hre4Ro51MyTxp053jSr79ASBsmnl4LjTixuggZ859m9sYqHJkbP0LwkEhQEWcG3qToYqEqbTFulbvMvFCIbas= 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 Sat, 19 Jul 2025 at 08:51, Kees Cook wrote: > > 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. > Given that 'inline' is already a macro in the kernel, could we just add __attribute__((__always_inline__)) to it when KCOV is enabled?