]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commit
x86/events/amd/iommu: Fix invalid Perf result due to IOMMU PMC power-gating
authorSuravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Tue, 4 May 2021 06:52:36 +0000 (01:52 -0500)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 1 Oct 2021 09:34:02 +0000 (11:34 +0200)
commiteab4821d80840c25c6f725059b55ad7585552352
treefe76a23cd41137f3fd412fea603a67cbca601211
parent1fc1a2c3e56f745353a0cd894459659bfc87185f
x86/events/amd/iommu: Fix invalid Perf result due to IOMMU PMC power-gating

BugLink: https://bugs.launchpad.net/bugs/1945517
commit e10de314287c2c14b0e6f0e3e961975ce2f4a83d upstream.

On certain AMD platforms, when the IOMMU performance counter source
(csource) field is zero, power-gating for the counter is enabled, which
prevents write access and returns zero for read access.

This can cause invalid perf result especially when event multiplexing
is needed (i.e. more number of events than available counters) since
the current logic keeps track of the previously read counter value,
and subsequently re-program the counter to continue counting the event.
With power-gating enabled, we cannot gurantee successful re-programming
of the counter.

Workaround this issue by :

1. Modifying the ordering of setting/reading counters and enabing/
   disabling csources to only access the counter when the csource
   is set to non-zero.

2. Since AMD IOMMU PMU does not support interrupt mode, the logic
   can be simplified to always start counting with value zero,
   and accumulate the counter value when stopping without the need
   to keep track and reprogram the counter with the previously read
   counter value.

This has been tested on systems with and without power-gating.

Fixes: 994d6608efe4 ("iommu/amd: Remove performance counter pre-initialization test")
Suggested-by: Alexander Monakov <amonakov@ispras.ru>
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20210504065236.4415-1-suravee.suthikulpanit@amd.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
arch/x86/events/amd/iommu.c