qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Ladi Prosek <lprosek@redhat.com>,
	qemu-devel@nongnu.org, kvm@vger.kernel.org
Cc: pbonzini@redhat.com, mtosatti@redhat.com, rkrcmar@redhat.com
Subject: Re: [Qemu-devel] [PATCH 3/3] i386/kvm: advertise Hyper-V frequency MSRs
Date: Fri, 4 Aug 2017 15:39:38 +0200	[thread overview]
Message-ID: <2ddf96f2-be1a-7fc6-c2b2-80c53ea5ddf3@redhat.com> (raw)
In-Reply-To: <20170804091403.13478-4-lprosek@redhat.com>

On 04.08.2017 11:14, Ladi Prosek wrote:
> As of kernel commit eb82feea59d6 ("KVM: hyperv: support HV_X64_MSR_TSC_FREQUENCY
> and HV_X64_MSR_APIC_FREQUENCY"), KVM supports two new MSRs which are required
> for nested Hyper-V to read timestamps with RDTSC + TSC page.
> 
> This commit makes QEMU advertise the MSRs with CPUID.40000003H:EAX[11] and
> CPUID.40000003H:EDX[8] as specified in the Hyper-V TLFS and experimentally
> verified on a Hyper-V host. The feature is enabled with the existing hv-time CPU
> flag, and only if the TSC frequency is stable across migration and known.
> 
> Signed-off-by: Ladi Prosek <lprosek@redhat.com>
> ---
>  target/i386/kvm.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> index 77b6373..7e484a7 100644
> --- a/target/i386/kvm.c
> +++ b/target/i386/kvm.c
> @@ -89,6 +89,7 @@ static bool has_msr_hv_vpindex;
>  static bool has_msr_hv_runtime;
>  static bool has_msr_hv_synic;
>  static bool has_msr_hv_stimer;
> +static bool has_msr_hv_frequencies;
>  static bool has_msr_xss;
>  
>  static bool has_msr_architectural_pmu;
> @@ -631,7 +632,17 @@ static int hyperv_handle_properties(CPUState *cs)
>      if (cpu->hyperv_time) {
>          env->features[FEAT_HYPERV_EAX] |= HV_X64_MSR_HYPERCALL_AVAILABLE;
>          env->features[FEAT_HYPERV_EAX] |= HV_X64_MSR_TIME_REF_COUNT_AVAILABLE;
> -        env->features[FEAT_HYPERV_EAX] |= 0x200;
> +        env->features[FEAT_HYPERV_EAX] |= HV_X64_MSR_REFERENCE_TSC_AVAILABLE;
> +        if (has_msr_hv_frequencies> +            /* TSC clock must be stable and known for this feature. */
> +            && ((env->features[FEAT_8000_0007_EDX] & CPUID_APM_INVTSC)
> +                || env->user_tsc_khz != 0)
> +            && env->tsc_khz != 0) {

I'd drop the != 0 in both cases and move the env->tsc_khz check up to
has_msr_hv_frequencies.

if (has_msr_hv_frequencies && env->tsc_khz && ...

Wonder if it even would make sense to move some parts of this check into
a helper function, to beautify this a bit. tsc_stable(env)
tsc_known(env) ...

> +
> +            env->features[FEAT_HYPERV_EAX] |= HV_X64_ACCESS_FREQUENCY_MSRS;
> +            env->features[FEAT_HYPERV_EDX] |=
> +                HV_FEATURE_FREQUENCY_MSRS_AVAILABLE;
> +        }
>      }
>      if (cpu->hyperv_crash && has_msr_hv_crash) {
>          env->features[FEAT_HYPERV_EDX] |= HV_X64_GUEST_CRASH_MSR_AVAILABLE;
> @@ -1127,6 +1138,9 @@ static int kvm_get_supported_msrs(KVMState *s)
>                  case HV_X64_MSR_STIMER0_CONFIG:
>                      has_msr_hv_stimer = true;
>                      break;
> +                case HV_X64_MSR_TSC_FREQUENCY:
> +                    has_msr_hv_frequencies = true;
> +                    break;
>                  }
>  
>              }
> 


-- 

Thanks,

David

  reply	other threads:[~2017-08-04 13:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-04  9:14 [Qemu-devel] [PATCH 0/3] i386/kvm: advertise Hyper-V frequency MSRs Ladi Prosek
2017-08-04  9:14 ` [Qemu-devel] [PATCH 1/3] i386/kvm: use a switch statement for MSR detection Ladi Prosek
2017-08-04 13:30   ` David Hildenbrand
2017-08-04  9:14 ` [Qemu-devel] [PATCH 2/3] i386/kvm: set tsc_khz before configuring Hyper-V CPUID Ladi Prosek
2017-08-04  9:14 ` [Qemu-devel] [PATCH 3/3] i386/kvm: advertise Hyper-V frequency MSRs Ladi Prosek
2017-08-04 13:39   ` David Hildenbrand [this message]
2017-08-04 13:45     ` Ladi Prosek

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=2ddf96f2-be1a-7fc6-c2b2-80c53ea5ddf3@redhat.com \
    --to=david@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=lprosek@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rkrcmar@redhat.com \
    /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).