[PATCH] iommu/generic_pt: disable GCOV for iommu_amdv1.o

Konstantin Khorenko posted 1 patch 2 months, 1 week ago
drivers/iommu/generic_pt/fmt/Makefile | 2 ++
1 file changed, 2 insertions(+)
[PATCH] iommu/generic_pt: disable GCOV for iommu_amdv1.o
Posted by Konstantin Khorenko 2 months, 1 week ago
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
Re: [PATCH] iommu/generic_pt: disable GCOV for iommu_amdv1.o
Posted by Jason Gunthorpe 2 months, 1 week ago
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
Re: [PATCH] iommu/generic_pt: disable GCOV for iommu_amdv1.o
Posted by Konstantin Khorenko 2 months ago
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