diff mbox series

[4/7] KVM: x86/pmu: Add documentation for fixed ctr on PMU filter

Message ID 20230414110056.19665-5-cloudliang@tencent.com (mailing list archive)
State New
Headers show
Series KVM: selftests: Add tests for pmu event filter | expand

Commit Message

Jinrong Liang April 14, 2023, 11 a.m. UTC
From: Jinrong Liang <cloudliang@tencent.com>

Update the documentation for the KVM_SET_PMU_EVENT_FILTER ioctl
to include a detailed description of how fixed performance events
are handled in the pmu filter. The action and fixed_counter_bitmap
members of the pmu filter to determine whether fixed performance
events can be programmed by the guest. This information is helpful
for correctly configuring the fixed_counter_bitmap and action fields
to filter fixed performance events.

Suggested-by: Like Xu <likexu@tencent.com>
Signed-off-by: Jinrong Liang <cloudliang@tencent.com>
---
 Documentation/virt/kvm/api.rst | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

kernel test robot April 15, 2023, 12:53 a.m. UTC | #1
Hi Jinrong,

kernel test robot noticed the following build warnings:

[auto build test WARNING on a25497a280bbd7bbcc08c87ddb2b3909affc8402]

url:    https://github.com/intel-lab-lkp/linux/commits/Jinrong-Liang/KVM-selftests-Replace-int-with-uint32_t-for-nevents/20230414-190401
base:   a25497a280bbd7bbcc08c87ddb2b3909affc8402
patch link:    https://lore.kernel.org/r/20230414110056.19665-5-cloudliang%40tencent.com
patch subject: [PATCH 4/7] KVM: x86/pmu: Add documentation for fixed ctr on PMU filter
reproduce:
        # https://github.com/intel-lab-lkp/linux/commit/b0effe04478df3b33a26331f48540851c4d33173
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Jinrong-Liang/KVM-selftests-Replace-int-with-uint32_t-for-nevents/20230414-190401
        git checkout b0effe04478df3b33a26331f48540851c4d33173
        make menuconfig
        # enable CONFIG_COMPILE_TEST, CONFIG_WARN_MISSING_DOCUMENTS, CONFIG_WARN_ABI_ERRORS
        make htmldocs

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202304150850.rx4UDDsB-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> Documentation/virt/kvm/api.rst:5133: WARNING: Definition list ends without a blank line; unexpected unindent.

vim +5133 Documentation/virt/kvm/api.rst

  5130	
  5131	  FixCtr[i]_is_allowed = (action == ALLOW) && (bitmap & BIT(i)) ||
  5132	    (action == DENY) && !(bitmap & BIT(i));
> 5133	  FixCtr[i]_is_denied = !FixCtr[i]_is_allowed;
  5134
Bagas Sanjaya April 15, 2023, 3:24 a.m. UTC | #2
On Fri, Apr 14, 2023 at 07:00:53PM +0800, Jinrong Liang wrote:
> +Specifically, KVM follows the following pseudo-code when determining whether to
> +allow the guest FixCtr[i] to count its pre-defined fixed event:
> +
> +  FixCtr[i]_is_allowed = (action == ALLOW) && (bitmap & BIT(i)) ||
> +    (action == DENY) && !(bitmap & BIT(i));
> +  FixCtr[i]_is_denied = !FixCtr[i]_is_allowed;
> +

As kernel test robot has reported [1], you need to wrap the code above
in a code block:

---- >8 ----
diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index 036f5b1a39aff8..b5836767e0e76d 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -5126,7 +5126,7 @@ Via this API, KVM userspace can also control the behavior of the VM's fixed
 counters (if any) by configuring the "action" and "fixed_counter_bitmap" fields.
 
 Specifically, KVM follows the following pseudo-code when determining whether to
-allow the guest FixCtr[i] to count its pre-defined fixed event:
+allow the guest FixCtr[i] to count its pre-defined fixed event::
 
   FixCtr[i]_is_allowed = (action == ALLOW) && (bitmap & BIT(i)) ||
     (action == DENY) && !(bitmap & BIT(i));

Thanks.

[1]: https://lore.kernel.org/linux-doc/202304150850.rx4UDDsB-lkp@intel.com/
Jinrong Liang April 16, 2023, 12:25 a.m. UTC | #3
Bagas Sanjaya <bagasdotme@gmail.com> 于2023年4月15日周六 11:24写道:
>
> On Fri, Apr 14, 2023 at 07:00:53PM +0800, Jinrong Liang wrote:
> > +Specifically, KVM follows the following pseudo-code when determining whether to
> > +allow the guest FixCtr[i] to count its pre-defined fixed event:
> > +
> > +  FixCtr[i]_is_allowed = (action == ALLOW) && (bitmap & BIT(i)) ||
> > +    (action == DENY) && !(bitmap & BIT(i));
> > +  FixCtr[i]_is_denied = !FixCtr[i]_is_allowed;
> > +
>
> As kernel test robot has reported [1], you need to wrap the code above
> in a code block:

I will make the changes as you suggested, i.e. wrap the code above in
a code block.

Thanks.

>
> ---- >8 ----
> diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
> index 036f5b1a39aff8..b5836767e0e76d 100644
> --- a/Documentation/virt/kvm/api.rst
> +++ b/Documentation/virt/kvm/api.rst
> @@ -5126,7 +5126,7 @@ Via this API, KVM userspace can also control the behavior of the VM's fixed
>  counters (if any) by configuring the "action" and "fixed_counter_bitmap" fields.
>
>  Specifically, KVM follows the following pseudo-code when determining whether to
> -allow the guest FixCtr[i] to count its pre-defined fixed event:
> +allow the guest FixCtr[i] to count its pre-defined fixed event::
>
>    FixCtr[i]_is_allowed = (action == ALLOW) && (bitmap & BIT(i)) ||
>      (action == DENY) && !(bitmap & BIT(i));
>
> Thanks.
>
> [1]: https://lore.kernel.org/linux-doc/202304150850.rx4UDDsB-lkp@intel.com/
>
> --
> An old man doll... just what I always wanted! - Clara
diff mbox series

Patch

diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index a69e91088d76..036f5b1a39af 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -5122,6 +5122,27 @@  Valid values for 'action'::
   #define KVM_PMU_EVENT_ALLOW 0
   #define KVM_PMU_EVENT_DENY 1
 
+Via this API, KVM userspace can also control the behavior of the VM's fixed
+counters (if any) by configuring the "action" and "fixed_counter_bitmap" fields.
+
+Specifically, KVM follows the following pseudo-code when determining whether to
+allow the guest FixCtr[i] to count its pre-defined fixed event:
+
+  FixCtr[i]_is_allowed = (action == ALLOW) && (bitmap & BIT(i)) ||
+    (action == DENY) && !(bitmap & BIT(i));
+  FixCtr[i]_is_denied = !FixCtr[i]_is_allowed;
+
+Note once this API interface is called, the default zero value of the field
+"fixed_counter_bitmap" will implicitly affect all fixed counters, even if it's
+expected to be used only to control the events on generic counters.
+
+In addition, pre-defined performance events on the fixed counters already have
+event_select and unit_mask values defined, which means userspace can also
+control fixed counters by configuring "action"+ "events" fields.
+
+When there is a contradiction between these two polices, the fixed performance
+counter will only follow the rule of the pseudo-code above.
+
 4.121 KVM_PPC_SVM_OFF
 ---------------------