[v2 PATCH] iommu/arm-smmu-v3: Fix L1 stream table index calculation for 32-bit sid size

Yang Shi yang at os.amperecomputing.com
Wed Oct 2 12:50:51 PDT 2024



On 10/2/24 12:22 PM, Nicolin Chen wrote:
> On Wed, Oct 02, 2024 at 12:04:32PM -0700, Yang Shi wrote:
>>> On Wed, Oct 02, 2024 at 10:55:14AM -0700, Yang Shi wrote:
>>>> +static inline unsigned int arm_smmu_strtab_max_sid(struct arm_smmu_device *smmu)
>>>> +{
>>>> +       return (1ULL << smmu->sid_bits);
>>>> +}
>>>> +
>>> Hmm, why ULL gets truncated to unsigned int here?
>> No particular reason, but it should be better to not truncate here. Will
>> fix it.
> Yea, and looks like we are going to do with:
> static inline u64 arm_smmu_strtab_num_sids(struct arm_smmu_device *smmu);

Since this is an inline function, so the truncate should actually 
happens when it is used. But anyway using the correct type does make the 
code less confusing.

>
> Then let's be careful at those return-value holders too:
> -----------------------------------------------------------
> static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu)
> {
> 	u32 size;
> 	struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg;
>
> 	size = (1 << smmu->sid_bits) * sizeof(struct arm_smmu_ste);
>          ^^^^
>          overflow?
> [...]
> 	cfg->linear.num_ents = 1 << smmu->sid_bits;
>                      ^^^^^^^^
>                      This is u32
> -----------------------------------------------------------
>
> Thanks
> Nicolin




More information about the linux-arm-kernel mailing list