Skip to content

Commit 5de863e

Browse files
jgunthorpejoergroedel
authored andcommitted
iommupt: Avoid a compiler bug with sw_bit
gcc 13, in some cases, gets confused if the __builtin_constant_p() is inside the switch. It thinks that bitnr can have the value max+1 and fails. Lift the check outside the switch to avoid it. Fixes: ef7bfe5 ("iommupt/x86: Support SW bits and permit PT_FEAT_DMA_INCOHERENT") Fixes: 5448c15 ("iommupt: Add the Intel VT-d second stage page table format") Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202511242012.I7g504Ab-lkp@intel.com/ Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
1 parent 152c862 commit 5de863e

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

drivers/iommu/generic_pt/fmt/vtdss.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ static inline unsigned int vtdss_pt_max_sw_bit(struct pt_common *common)
174174

175175
static inline u64 vtdss_pt_sw_bit(unsigned int bitnr)
176176
{
177+
if (__builtin_constant_p(bitnr) && bitnr > 10)
178+
BUILD_BUG();
179+
177180
/* Bits marked Ignored in the specification */
178181
switch (bitnr) {
179182
case 0:
@@ -184,10 +187,7 @@ static inline u64 vtdss_pt_sw_bit(unsigned int bitnr)
184187
return BIT_ULL(63);
185188
/* Some bits in 9-3 are available in some entries */
186189
default:
187-
if (__builtin_constant_p(bitnr))
188-
BUILD_BUG();
189-
else
190-
PT_WARN_ON(true);
190+
PT_WARN_ON(true);
191191
return 0;
192192
}
193193
}

drivers/iommu/generic_pt/fmt/x86_64.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ static inline unsigned int x86_64_pt_max_sw_bit(struct pt_common *common)
175175

176176
static inline u64 x86_64_pt_sw_bit(unsigned int bitnr)
177177
{
178+
if (__builtin_constant_p(bitnr) && bitnr > 12)
179+
BUILD_BUG();
180+
178181
/* Bits marked Ignored/AVL in the specification */
179182
switch (bitnr) {
180183
case 0:
@@ -185,10 +188,7 @@ static inline u64 x86_64_pt_sw_bit(unsigned int bitnr)
185188
return BIT_ULL((bitnr - 2) + 52);
186189
/* Some bits in 8,6,4,3 are available in some entries */
187190
default:
188-
if (__builtin_constant_p(bitnr))
189-
BUILD_BUG();
190-
else
191-
PT_WARN_ON(true);
191+
PT_WARN_ON(true);
192192
return 0;
193193
}
194194
}

0 commit comments

Comments
 (0)