kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: Luwei Kang <luwei.kang@intel.com>
Cc: pbonzini@redhat.com, rth@twiddle.net, qemu-devel@nongnu.org,
	kvm@vger.kernel.org
Subject: Re: [PATCH 2/2] target/i386: Add support for put/get PEBS registers
Date: Fri, 11 Oct 2019 23:42:32 -0300	[thread overview]
Message-ID: <20191012024232.GA832@habkost.net> (raw)
In-Reply-To: <1567056175-14275-2-git-send-email-luwei.kang@intel.com>

On Thu, Aug 29, 2019 at 01:22:55PM +0800, Luwei Kang wrote:
> This patch add a new feature words for IA32_PERF_CAPABILITIES (RO)
> register that serve to expose PEBS output Intel PT feature.
> The registers relate with PEBS need to be set/get when PEBS output
> Intel PT is supported in guest.
> 
> Signed-off-by: Luwei Kang <luwei.kang@intel.com>

Sorry for taking so long to take a look at the series.

What's the status of the kernel KVM patches for this?

> ---
>  target/i386/cpu.c | 20 ++++++++++++++++++++
>  target/i386/cpu.h |  4 ++++
>  target/i386/kvm.c | 36 ++++++++++++++++++++++++++++++++++++
>  3 files changed, 60 insertions(+)
> 
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index 9e0bac3..7fe34c0 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -1244,6 +1244,26 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
>              },
>          },
>      },
> +    [FEAT_PERF_CAPABILITIES] = {
> +        .type = MSR_FEATURE_WORD,
> +        .feat_names = {
> +            NULL, NULL, NULL, NULL,
> +            NULL, NULL, NULL, NULL,
> +            NULL, NULL, NULL, NULL,
> +            NULL, NULL, NULL, NULL,
> +            "pebs-output-pt", NULL, NULL, NULL,
> +            NULL, NULL, NULL, NULL,
> +            NULL, NULL, NULL, NULL,
> +            NULL, NULL, NULL, NULL,
> +        },
> +        .msr = {
> +            .index = MSR_IA32_PERF_CAPABILITIES,
> +            .cpuid_dep = {
> +                FEAT_1_ECX,
> +                CPUID_EXT_PDCM,
> +            },
> +        },
> +    },
>  };
>  
>  typedef struct X86RegisterInfo32 {
> diff --git a/target/i386/cpu.h b/target/i386/cpu.h
> index d7cec36..0904004 100644
> --- a/target/i386/cpu.h
> +++ b/target/i386/cpu.h
> @@ -347,6 +347,7 @@ typedef enum X86Seg {
>  #define MSR_IA32_PRED_CMD               0x49
>  #define MSR_IA32_CORE_CAPABILITY        0xcf
>  #define MSR_IA32_ARCH_CAPABILITIES      0x10a
> +#define MSR_IA32_PERF_CAPABILITIES      0x345
>  #define MSR_IA32_TSCDEADLINE            0x6e0
>  
>  #define FEATURE_CONTROL_LOCKED                    (1<<0)
> @@ -503,6 +504,7 @@ typedef enum FeatureWord {
>      FEAT_XSAVE_COMP_HI, /* CPUID[EAX=0xd,ECX=0].EDX */
>      FEAT_ARCH_CAPABILITIES,
>      FEAT_CORE_CAPABILITY,
> +    FEAT_PERF_CAPABILITIES,
>      FEATURE_WORDS,
>  } FeatureWord;
>  
> @@ -754,6 +756,8 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS];
>  
>  #define MSR_CORE_CAP_SPLIT_LOCK_DETECT  (1U << 5)
>  
> +#define MSR_PERF_CAP_PEBS_VIA_PT        (1ULL << 16)
> +
>  /* Supported Hyper-V Enlightenments */
>  #define HYPERV_FEAT_RELAXED             0
>  #define HYPERV_FEAT_VAPIC               1
> diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> index 8023c67..c0dcc13 100644
> --- a/target/i386/kvm.c
> +++ b/target/i386/kvm.c
> @@ -2651,6 +2651,20 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
>                  kvm_msr_entry_add(cpu, MSR_IA32_RTIT_ADDR0_A + i,
>                              env->msr_rtit_addrs[i]);
>              }
> +
> +            if (env->features[FEAT_PERF_CAPABILITIES] &
> +                                        MSR_PERF_CAP_PEBS_VIA_PT) {
> +                kvm_msr_entry_add(cpu, MSR_IA32_PEBS_ENABLE,
> +                                env->msr_pebs_enable);
> +                for (i = 0; i < num_architectural_pmu_fixed_counters; i++) {
> +                    kvm_msr_entry_add(cpu, MSR_RELOAD_FIXED_CTR0 + i,
> +                                env->msr_reload_fixed_ctr[i]);
> +                }
> +                for (i = 0; i < num_architectural_pmu_gp_counters; i++) {
> +                    kvm_msr_entry_add(cpu, MSR_RELOAD_PMC0 + i,
> +                                env->msr_reload_pmc[i]);
> +                }
> +            }
>          }
>  
>          /* Note: MSR_IA32_FEATURE_CONTROL is written separately, see
> @@ -2989,6 +3003,16 @@ static int kvm_get_msrs(X86CPU *cpu)
>          for (i = 0; i < addr_num; i++) {
>              kvm_msr_entry_add(cpu, MSR_IA32_RTIT_ADDR0_A + i, 0);
>          }
> +
> +        if (env->features[FEAT_PERF_CAPABILITIES] & MSR_PERF_CAP_PEBS_VIA_PT) {
> +            kvm_msr_entry_add(cpu, MSR_IA32_PEBS_ENABLE, 0);
> +            for (i = 0; i < num_architectural_pmu_fixed_counters; i++) {
> +                kvm_msr_entry_add(cpu, MSR_RELOAD_FIXED_CTR0 + i, 0);
> +            }
> +            for (i = 0; i < num_architectural_pmu_gp_counters; i++) {
> +                kvm_msr_entry_add(cpu, MSR_RELOAD_PMC0 + i, 0);
> +            }
> +        }
>      }
>  
>      ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MSRS, cpu->kvm_msr_buf);
> @@ -3268,6 +3292,18 @@ static int kvm_get_msrs(X86CPU *cpu)
>          case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B:
>              env->msr_rtit_addrs[index - MSR_IA32_RTIT_ADDR0_A] = msrs[i].data;
>              break;
> +        case MSR_IA32_PEBS_ENABLE:
> +            env->msr_pebs_enable = msrs[i].data;
> +            break;
> +        case MSR_RELOAD_FIXED_CTR0 ...
> +                                MSR_RELOAD_FIXED_CTR0 + MAX_FIXED_COUNTERS - 1:
> +            env->msr_reload_fixed_ctr[index - MSR_RELOAD_FIXED_CTR0] =
> +                                                                msrs[i].data;
> +            break;
> +        case MSR_RELOAD_PMC0 ...
> +                                MSR_RELOAD_PMC0 + MAX_GP_COUNTERS - 1:
> +            env->msr_reload_fixed_ctr[index - MSR_RELOAD_PMC0] = msrs[i].data;
> +            break;
>          }
>      }
>  
> -- 
> 1.8.3.1
> 

-- 
Eduardo

      reply	other threads:[~2019-10-12  2:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-29  5:22 [PATCH 1/2] target/i386: Add support for save PEBS registers Luwei Kang
2019-08-29  5:22 ` [PATCH 2/2] target/i386: Add support for put/get " Luwei Kang
2019-10-12  2:42   ` Eduardo Habkost [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191012024232.GA832@habkost.net \
    --to=ehabkost@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=luwei.kang@intel.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).