Re: [PATCH v9 5/8] perf/amd/iommu: Modify functions to query max banks and counters

From: Borislav Petkov
Date: Wed Feb 08 2017 - 14:42:59 EST


On Tue, Feb 07, 2017 at 02:40:33AM -0600, Suravee Suthikulpanit wrote:
> Currently, amd_iommu_pc_get_max_[banks|counters]() use end-point
> device ID to locate an IOMMU and check the reported max banks/counters.
> The logic assumes that the IOMMU_BASE_DEVID belongs to the first IOMMU,
> and uses it to acquire a reference to the first IOMMU, which does not work
> on certain systems. Instead, modify the function to take an IOMMU index,
> and use it to query the corresponding AMD IOMMU instance.
>
> Currently, hardcodes the IOMMU index to 0 since the current AMD IOMMU
> perf implementation only supports a single IOMMU. A subsequent
> patch will add support for multiple IOMMUs, and will use a proper IOMMU index.
>
> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Cc: Borislav Petkov <bp@xxxxxxxxx>
> Cc: Joerg Roedel <joro@xxxxxxxxxx>
> Signed-off-by: Suravee Suthikulpanit <Suravee.Suthikulpanit@xxxxxxx>
> ---

...

> diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
> index 1b5adb4..eb654e7 100644
> --- a/drivers/iommu/amd_iommu_init.c
> +++ b/drivers/iommu/amd_iommu_init.c
> @@ -2715,6 +2715,21 @@ bool amd_iommu_v2_supported(void)
> }
> EXPORT_SYMBOL(amd_iommu_v2_supported);
>
> +struct amd_iommu *get_amd_iommu(unsigned int idx)
> +{
> + unsigned int i = 0;
> + struct amd_iommu *iommu, *ret = NULL;
> +
> + for_each_iommu(iommu) {
> + if (i++ == idx) {
> + ret = iommu;
> + break;

return iommu;

no need for the assignment and the break.

> + }
> + }
> + return ret;
> +}
> +EXPORT_SYMBOL(get_amd_iommu);

--
Regards/Gruss,
Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.