]> Gentwo Git Trees - linux/.git/commitdiff
iommupt: Avoid a compiler bug with sw_bit
authorJason Gunthorpe <jgg@nvidia.com>
Wed, 26 Nov 2025 19:21:27 +0000 (15:21 -0400)
committerJoerg Roedel <joerg.roedel@amd.com>
Thu, 27 Nov 2025 11:46:10 +0000 (12:46 +0100)
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: ef7bfe5bbffd ("iommupt/x86: Support SW bits and permit PT_FEAT_DMA_INCOHERENT")
Fixes: 5448c1558f60 ("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>
drivers/iommu/generic_pt/fmt/vtdss.h
drivers/iommu/generic_pt/fmt/x86_64.h

index d9774848eb6f7f6bf7211718ff3e81a39111c4b7..50ffed9d0e508f2c2ec403d0c2349c3422f2e153 100644 (file)
@@ -174,6 +174,9 @@ static inline unsigned int vtdss_pt_max_sw_bit(struct pt_common *common)
 
 static inline u64 vtdss_pt_sw_bit(unsigned int bitnr)
 {
+       if (__builtin_constant_p(bitnr) && bitnr > 10)
+               BUILD_BUG();
+
        /* Bits marked Ignored in the specification */
        switch (bitnr) {
        case 0:
@@ -184,10 +187,7 @@ static inline u64 vtdss_pt_sw_bit(unsigned int bitnr)
                return BIT_ULL(63);
        /* Some bits in 9-3 are available in some entries */
        default:
-               if (__builtin_constant_p(bitnr))
-                       BUILD_BUG();
-               else
-                       PT_WARN_ON(true);
+               PT_WARN_ON(true);
                return 0;
        }
 }
index a86353f1481e5cd0261c60b95ca56fe615950192..507abf2c934ccb2266f530ea33f658109ef1a566 100644 (file)
@@ -175,6 +175,9 @@ static inline unsigned int x86_64_pt_max_sw_bit(struct pt_common *common)
 
 static inline u64 x86_64_pt_sw_bit(unsigned int bitnr)
 {
+       if (__builtin_constant_p(bitnr) && bitnr > 12)
+               BUILD_BUG();
+
        /* Bits marked Ignored/AVL in the specification */
        switch (bitnr) {
        case 0:
@@ -185,10 +188,7 @@ static inline u64 x86_64_pt_sw_bit(unsigned int bitnr)
                return BIT_ULL((bitnr - 2) + 52);
        /* Some bits in 8,6,4,3 are available in some entries */
        default:
-               if (__builtin_constant_p(bitnr))
-                       BUILD_BUG();
-               else
-                       PT_WARN_ON(true);
+               PT_WARN_ON(true);
                return 0;
        }
 }