public inbox for iommu@lists.linux-foundation.org
 help / color / mirror / Atom feed
* [PATCH 0/1] iommu/generic_pt: disable GCOV for iommu_amdv1.o
@ 2026-04-02 14:10 Konstantin Khorenko
  2026-04-02 14:10 ` [PATCH] " Konstantin Khorenko
  2026-04-09 17:01 ` [PATCH v2 0/1] iommu/generic_pt: fix GCOV build failure for amdv1 Konstantin Khorenko
  0 siblings, 2 replies; 7+ messages in thread
From: Konstantin Khorenko @ 2026-04-02 14:10 UTC (permalink / raw)
  To: Joerg Roedel, Will Deacon, Jason Gunthorpe
  Cc: Robin Murphy, Kevin Tian, Peter Oberparleiter, Mikhail Zaslonko,
	iommu, linux-kernel, Konstantin Khorenko, Pavel Tikhomirov,
	Vasileios Almpanis, Thomas Weißschuh

This patch fixes a build failure in drivers/iommu/generic_pt/fmt/iommu_amdv1.o
when -fprofile-update=atomic is added to global CFLAGS_GCOV.

This is part of a larger effort to add -fprofile-update=atomic to
global CFLAGS_GCOV to fix GCOV counter races that cause crashes on SMP
(posted earlier as a combined series):
  https://lore.kernel.org/lkml/20260401142020.1434243-1-khorenko@virtuozzo.com/T/#t

That combined series was split per subsystem as requested by reviewers.
The companion patches are:

 - net: fix skb_ext BUILD_BUG_ON failures (sent to netdev)
 - gcov: add -fprofile-update=atomic globally (sent to gcov/kbuild
   maintainers, depends on this patch and the net patches)

FIELD_PREP() compile-time checks fail because the entire call chain is
__always_inline functions generated by PT_MAKE_LEVELS(), and GCC's
.constprop cloning creates new profiled function bodies that bypass
__no_profile.  Disabling GCOV for the file is the only viable fix.

Konstantin Khorenko (1):
  iommu/generic_pt: disable GCOV for iommu_amdv1.o

 drivers/iommu/generic_pt/fmt/Makefile | 2 ++
 1 file changed, 2 insertions(+)

-- 
2.43.5

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] iommu/generic_pt: disable GCOV for iommu_amdv1.o
  2026-04-02 14:10 [PATCH 0/1] iommu/generic_pt: disable GCOV for iommu_amdv1.o Konstantin Khorenko
@ 2026-04-02 14:10 ` Konstantin Khorenko
  2026-04-03 16:07   ` Jason Gunthorpe
  2026-04-09 17:01 ` [PATCH v2 0/1] iommu/generic_pt: fix GCOV build failure for amdv1 Konstantin Khorenko
  1 sibling, 1 reply; 7+ messages in thread
From: Konstantin Khorenko @ 2026-04-02 14:10 UTC (permalink / raw)
  To: Joerg Roedel, Will Deacon, Jason Gunthorpe
  Cc: Robin Murphy, Kevin Tian, Peter Oberparleiter, Mikhail Zaslonko,
	iommu, linux-kernel, Konstantin Khorenko, Pavel Tikhomirov,
	Vasileios Almpanis, Thomas Weißschuh

With -fprofile-update=atomic in global CFLAGS_GCOV, GCC cannot
constant-fold FIELD_PREP() expressions inside deeply inlined page table
walker functions.  GCC creates .constprop clones of the inline level
functions, which get their own GCOV instrumentation that prevents
constant evaluation of compile-time checks.

__no_profile cannot be used here because the entire call chain is
__always_inline functions generated by PT_MAKE_LEVELS() macro, and GCC's
constprop cloning creates new profiled function bodies that bypass the
attribute.

Disable GCOV for iommu_amdv1.o to allow BUILD_BUG_ON / FIELD_PREP
compile-time checks to succeed.

Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 drivers/iommu/generic_pt/fmt/Makefile | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/iommu/generic_pt/fmt/Makefile b/drivers/iommu/generic_pt/fmt/Makefile
index 976b49ec97dc..0305f7fb9e35 100644
--- a/drivers/iommu/generic_pt/fmt/Makefile
+++ b/drivers/iommu/generic_pt/fmt/Makefile
@@ -1,5 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
+GCOV_PROFILE_iommu_amdv1.o := n
+
 iommu_pt_fmt-$(CONFIG_IOMMU_PT_AMDV1) += amdv1
 iommu_pt_fmt-$(CONFIG_IOMMUFD_TEST) += mock
 
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] iommu/generic_pt: disable GCOV for iommu_amdv1.o
  2026-04-02 14:10 ` [PATCH] " Konstantin Khorenko
@ 2026-04-03 16:07   ` Jason Gunthorpe
  2026-04-09 17:01     ` Konstantin Khorenko
  0 siblings, 1 reply; 7+ messages in thread
From: Jason Gunthorpe @ 2026-04-03 16:07 UTC (permalink / raw)
  To: Konstantin Khorenko
  Cc: Joerg Roedel, Will Deacon, Robin Murphy, Kevin Tian,
	Peter Oberparleiter, Mikhail Zaslonko, iommu, linux-kernel,
	Pavel Tikhomirov, Vasileios Almpanis, Thomas Weißschuh

On Thu, Apr 02, 2026 at 05:10:12PM +0300, Konstantin Khorenko wrote:
> With -fprofile-update=atomic in global CFLAGS_GCOV, GCC cannot
> constant-fold FIELD_PREP() expressions inside deeply inlined page table
> walker functions.  GCC creates .constprop clones of the inline level
> functions, which get their own GCOV instrumentation that prevents
> constant evaluation of compile-time checks.

That's hasn't been the issue here. gcc gets confused where it thinks a
value is constant so the builtin_constant checks inside FIELD_PREP
trigger, but if the value is constant then control flow leading up to
it excludes that path ever happening.

Somehow gcov is breaking the elimination of the impossible branch, and
I think this is all just compiler bugs.

Also, I thought this was fixed by adding the always_inline?

Jason

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] iommu/generic_pt: disable GCOV for iommu_amdv1.o
  2026-04-03 16:07   ` Jason Gunthorpe
@ 2026-04-09 17:01     ` Konstantin Khorenko
  0 siblings, 0 replies; 7+ messages in thread
From: Konstantin Khorenko @ 2026-04-09 17:01 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Joerg Roedel, Will Deacon, Robin Murphy, Kevin Tian,
	Peter Oberparleiter, Mikhail Zaslonko, iommu, linux-kernel,
	Pavel Tikhomirov, Vasileios Almpanis, Thomas Weißschuh

On 4/3/26 18:07, Jason Gunthorpe wrote:
> On Thu, Apr 02, 2026 at 05:10:12PM +0300, Konstantin Khorenko wrote:
>> With -fprofile-update=atomic in global CFLAGS_GCOV, GCC cannot
>> constant-fold FIELD_PREP() expressions inside deeply inlined page table
>> walker functions.  GCC creates .constprop clones of the inline level
>> functions, which get their own GCOV instrumentation that prevents
>> constant evaluation of compile-time checks.
> 
> That's hasn't been the issue here. gcc gets confused where it thinks a
> value is constant so the builtin_constant checks inside FIELD_PREP
> trigger, but if the value is constant then control flow leading up to
> it excludes that path ever happening.
> 
> Somehow gcov is breaking the elimination of the impossible branch, and
> I think this is all just compiler bugs.
> 
> Also, I thought this was fixed by adding the always_inline?

You are definitely right, Jason, thank you for the hint!

Sending v2 with __always_inline.

--
Konstantin Khorenko

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 0/1] iommu/generic_pt: fix GCOV build failure for amdv1
  2026-04-02 14:10 [PATCH 0/1] iommu/generic_pt: disable GCOV for iommu_amdv1.o Konstantin Khorenko
  2026-04-02 14:10 ` [PATCH] " Konstantin Khorenko
@ 2026-04-09 17:01 ` Konstantin Khorenko
  2026-04-09 17:01   ` [PATCH v2] iommu/generic_pt: use __always_inline for amdv1pt_install_leaf_entry() Konstantin Khorenko
  1 sibling, 1 reply; 7+ messages in thread
From: Konstantin Khorenko @ 2026-04-09 17:01 UTC (permalink / raw)
  To: Joerg Roedel, Will Deacon, Jason Gunthorpe
  Cc: Robin Murphy, Kevin Tian, Peter Oberparleiter, Mikhail Zaslonko,
	iommu, linux-kernel, Konstantin Khorenko, Pavel Tikhomirov,
	Vasileios Almpanis

This patch fixes a build failure in drivers/iommu/generic_pt/fmt/iommu_amdv1.o
when -fprofile-update=atomic is added to global CFLAGS_GCOV.

v2: Use __always_inline instead of disabling GCOV for the file, as
    suggested by Jason Gunthorpe.  The root cause is that
    amdv1pt_install_leaf_entry() is "static inline" (not __always_inline),
    so GCC may choose not to inline it.  Without inlining, the compiler
    cannot see constant arguments at the call site and fails to eliminate
    the impossible branch in FIELD_PREP().  Forcing inlining via
    __always_inline solves the problem without losing GCOV coverage.

v1: https://lore.kernel.org/lkml/20260401142020.1434243-4-khorenko@virtuozzo.com/

This is part of a larger effort to add -fprofile-update=atomic to
global CFLAGS_GCOV to fix GCOV counter races that cause crashes on SMP
(posted earlier as a combined series):
  https://lore.kernel.org/lkml/20260401142020.1434243-1-khorenko@virtuozzo.com/T/#t

That combined series was split per subsystem as requested by reviewers.
The companion patches are:

- net: fix skb_ext BUILD_BUG_ON failures (sent to netdev) [1]
- gcov: add -fprofile-update=atomic globally (sent to gcov/kbuild
  maintainers, depends on this patch and the net patches) [2]

[1] https://lore.kernel.org/lkml/20260402140558.1437002-1-khorenko@virtuozzo.com/T/#t
[2] https://lore.kernel.org/lkml/20260402141831.1437357-1-khorenko@virtuozzo.com/T/#t

Konstantin Khorenko (1):
  iommu/generic_pt: use __always_inline for amdv1pt_install_leaf_entry()

 drivers/iommu/generic_pt/fmt/amdv1.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.43.5

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] iommu/generic_pt: use __always_inline for amdv1pt_install_leaf_entry()
  2026-04-09 17:01 ` [PATCH v2 0/1] iommu/generic_pt: fix GCOV build failure for amdv1 Konstantin Khorenko
@ 2026-04-09 17:01   ` Konstantin Khorenko
  2026-04-09 18:29     ` Jason Gunthorpe
  0 siblings, 1 reply; 7+ messages in thread
From: Konstantin Khorenko @ 2026-04-09 17:01 UTC (permalink / raw)
  To: Joerg Roedel, Will Deacon, Jason Gunthorpe
  Cc: Robin Murphy, Kevin Tian, Peter Oberparleiter, Mikhail Zaslonko,
	iommu, linux-kernel, Konstantin Khorenko, Pavel Tikhomirov,
	Vasileios Almpanis

With -fprofile-update=atomic in CFLAGS_GCOV, GCC fails to eliminate
an impossible branch in FIELD_PREP() inside amdv1pt_install_leaf_entry()
when the function is merely "static inline".  GCC may choose not to
inline it, and without seeing the constant arguments at the call site
it cannot prove the FIELD_PREP value fits the field.

Change from "static inline" to "static __always_inline" so GCC is
forced to inline the function and can see the constant values,
allowing dead code elimination of the impossible branch.

Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 drivers/iommu/generic_pt/fmt/amdv1.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/generic_pt/fmt/amdv1.h b/drivers/iommu/generic_pt/fmt/amdv1.h
index 3b2c41d9654d..8d11b08291d7 100644
--- a/drivers/iommu/generic_pt/fmt/amdv1.h
+++ b/drivers/iommu/generic_pt/fmt/amdv1.h
@@ -191,7 +191,7 @@ static inline enum pt_entry_type amdv1pt_load_entry_raw(struct pt_state *pts)
 }
 #define pt_load_entry_raw amdv1pt_load_entry_raw
 
-static inline void
+static __always_inline void
 amdv1pt_install_leaf_entry(struct pt_state *pts, pt_oaddr_t oa,
 			   unsigned int oasz_lg2,
 			   const struct pt_write_attrs *attrs)
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] iommu/generic_pt: use __always_inline for amdv1pt_install_leaf_entry()
  2026-04-09 17:01   ` [PATCH v2] iommu/generic_pt: use __always_inline for amdv1pt_install_leaf_entry() Konstantin Khorenko
@ 2026-04-09 18:29     ` Jason Gunthorpe
  0 siblings, 0 replies; 7+ messages in thread
From: Jason Gunthorpe @ 2026-04-09 18:29 UTC (permalink / raw)
  To: Konstantin Khorenko
  Cc: Joerg Roedel, Will Deacon, Robin Murphy, Kevin Tian,
	Peter Oberparleiter, Mikhail Zaslonko, iommu, linux-kernel,
	Pavel Tikhomirov, Vasileios Almpanis

On Thu, Apr 09, 2026 at 08:01:17PM +0300, Konstantin Khorenko wrote:
> With -fprofile-update=atomic in CFLAGS_GCOV, GCC fails to eliminate
> an impossible branch in FIELD_PREP() inside amdv1pt_install_leaf_entry()
> when the function is merely "static inline".  GCC may choose not to
> inline it, and without seeing the constant arguments at the call site
> it cannot prove the FIELD_PREP value fits the field.
> 
> Change from "static inline" to "static __always_inline" so GCC is
> forced to inline the function and can see the constant values,
> allowing dead code elimination of the impossible branch.
> 
> Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
> ---
>  drivers/iommu/generic_pt/fmt/amdv1.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

It was already merged:

commit 8b72aa5704c77380742346d4ac755b074b7f9eaa
Author: Sherry Yang <sherry.yang@oracle.com>
Date:   Thu Mar 26 09:17:19 2026 -0700

    iommupt/amdv1: mark amdv1pt_install_leaf_entry as __always_inline
    
    After enabling CONFIG_GCOV_KERNEL and CONFIG_GCOV_PROFILE_ALL, following
    build failure is observed under GCC 14.2.1:

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-04-09 18:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-02 14:10 [PATCH 0/1] iommu/generic_pt: disable GCOV for iommu_amdv1.o Konstantin Khorenko
2026-04-02 14:10 ` [PATCH] " Konstantin Khorenko
2026-04-03 16:07   ` Jason Gunthorpe
2026-04-09 17:01     ` Konstantin Khorenko
2026-04-09 17:01 ` [PATCH v2 0/1] iommu/generic_pt: fix GCOV build failure for amdv1 Konstantin Khorenko
2026-04-09 17:01   ` [PATCH v2] iommu/generic_pt: use __always_inline for amdv1pt_install_leaf_entry() Konstantin Khorenko
2026-04-09 18:29     ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox