Re: [PATCH] iommupt/amdv1: avoid GCOV builds triggering FIELD_PREP build failure

From: Sherry Yang

Date: Tue Mar 10 2026 - 13:18:18 EST




> On Mar 10, 2026, at 9:41 AM, Jason Gunthorpe <jgg@xxxxxxxxxx> wrote:
>
> On Tue, Mar 10, 2026 at 09:31:36AM -0700, Sherry Yang wrote:
>> After enabling CONFIG_GCOV_KERNEL and CONFIG_GCOV_PROFILE_ALL, following
>> build failure is observed:
>>
>> In function 'amdv1pt_install_leaf_entry',
>> inlined from '__do_map_single_page' at drivers/iommu/generic_pt/fmt/../iommu_pt.h:650:3,
>> inlined from '__map_single_page0' at drivers/iommu/generic_pt/fmt/../iommu_pt.h:661:1,
>> inlined from 'pt_descend' at drivers/iommu/generic_pt/fmt/../pt_iter.h:391:9,
>> inlined from '__do_map_single_page' at drivers/iommu/generic_pt/fmt/../iommu_pt.h:657:10,
>> inlined from '__map_single_page1.constprop' at drivers/iommu/generic_pt/fmt/../iommu_pt.h:661:1:
>> ././include/linux/compiler_types.h:706:45: error: call to '__compiletime_assert_71' declared with attribute error: FIELD_PREP: value too large for the field
>> 706 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
>> |
>>
>> ......
>>
>> drivers/iommu/generic_pt/fmt/amdv1.h:220:26: note: in expansion of macro 'FIELD_PREP'
>> 220 | FIELD_PREP(AMDV1PT_FMT_OA,
>> | ^~~~~~~~~~
>>
>> In the path '__do_map_single_page()', level 0 always invokes
>> 'pt_install_leaf_entry(&pts, map->oa, PAGE_SHIFT, …)'. At runtime that
>> lands in the 'if (oasz_lg2 == isz_lg2)' arm of 'amdv1pt_install_leaf_entry()';
>> the contiguous-only 'else' block is unreachable for 4 KiB pages.
>
> I think this is fixed already by
>
> commit 98d5110f90ae0dbc5f2f13f033e06f6d57009e0d
> Author: Jason Gunthorpe <jgg@xxxxxxxx>
> Date: Mon Jan 19 20:19:49 2026 -0400
>
> iommupt: Make it clearer to the compiler that pts.level == 0 for single page
>
> Older versions of gcc and clang sometimes get tripped up by the build time
> assertion in FIELD_PREP because they can see that the argument to
> FIELD_PREP is constant but can't see that the if condition protecting it
> is also a constant false.
>
> In file included from <command-line>:
> In function 'amdv1pt_install_leaf_entry',
> inlined from '__do_map_single_page' at drivers/iommu/generic_pt/fmt/../iommu_pt.h:651:3,
> inlined from '__map_single_page0' at drivers/iommu/generic_pt/fmt/../iommu_pt.h:662:1,
> inlined from 'pt_descend' at drivers/iommu/generic_pt/fmt/../pt_iter.h:391:9,
> inlined from '__do_map_single_page' at drivers/iommu/generic_pt/fmt/../iommu_pt.h:658:10,
> inlined from '__map_single_page1.constprop' at drivers/iommu/generic_pt/fmt/../iommu_pt.h:662:1:
>
>
> ??
>
> Jason

Hi Jason,

Unfortunately, I ran into the FIELD_PREP build failure with 98d5110f90ae (“iommupt: Make it clearer to the compiler that pts.level == 0 for single page”) already merged, which means it doesn’t work for me. I noticed you mentioned clang 18 hit the same issue and fixed by the patch. We’re using GCC 14.2.1, looks like GCC still constant-folds the contiguous branch despite the change to pts.level.

Thanks,
Sherry