]> www.infradead.org Git - users/jedix/linux-maple.git/commit
iommu/arm-smmu-v3: Fix last_sid_idx calculation for sid_bits==32
authorDaniel Mentz <danielmentz@google.com>
Wed, 2 Oct 2024 01:53:57 +0000 (18:53 -0700)
committerWill Deacon <will@kernel.org>
Tue, 8 Oct 2024 17:37:48 +0000 (18:37 +0100)
commitf63237f54cf18448728201a65e6c82018e807cd9
treef58b345b48d037b3d37515f3725e6548f7b0fa8c
parent0dfe314cdd0d378f96bb9c6bdc05c8120f48606d
iommu/arm-smmu-v3: Fix last_sid_idx calculation for sid_bits==32

The function arm_smmu_init_strtab_2lvl uses the expression

((1 << smmu->sid_bits) - 1)

to calculate the largest StreamID value. However, this fails for the
maximum allowed value of SMMU_IDR1.SIDSIZE which is 32. The C standard
states:

"If the value of the right operand is negative or is greater than or
equal to the width of the promoted left operand, the behavior is
undefined."

With smmu->sid_bits being 32, the prerequisites for undefined behavior
are met.  We observed that the value of (1 << 32) is 1 and not 0 as we
initially expected.

Similar bit shift operations in arm_smmu_init_strtab_linear seem to not
be affected, because it appears to be unlikely for an SMMU to have
SMMU_IDR1.SIDSIZE set to 32 but then not support 2-level Stream tables

This issue was found by Ryan Huang <tzukui@google.com> on our team.

Fixes: ce410410f1a7 ("iommu/arm-smmu-v3: Add arm_smmu_strtab_l1/2_idx()")
Signed-off-by: Daniel Mentz <danielmentz@google.com>
Link: https://lore.kernel.org/r/20241002015357.1766934-1-danielmentz@google.com
Signed-off-by: Will Deacon <will@kernel.org>
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c