Commit 5de863ef authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Joerg Roedel
Browse files

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: ef7bfe5b ("iommupt/x86: Support SW bits and permit PT_FEAT_DMA_INCOHERENT")
Fixes: 5448c155 ("iommupt: Add the Intel VT-d second stage page table format")
Reported-by: default avatarkernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202511242012.I7g504Ab-lkp@intel.com/


Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Signed-off-by: default avatarJoerg Roedel <joerg.roedel@amd.com>
parent 152c862c
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -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,9 +187,6 @@ 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);
		return 0;
	}
+4 −4
Original line number Diff line number Diff line
@@ -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,9 +188,6 @@ 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);
		return 0;
	}