mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: Vipin Sharma <vipinsh@google.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	seanjc@google.com, pbonzini@redhat.com, dmatlack@google.com
Subject: Re: [PATCH v2 2/6] KVM: x86: hyper-v: Add extended hypercall support in Hyper-v
Date: Thu, 24 Nov 2022 10:28:32 +0100	[thread overview]
Message-ID: <87leo0og5b.fsf@ovpn-192-146.brq.redhat.com> (raw)
In-Reply-To: <CAHVum0fZZwsCEL-bMM2phfiukSF0_M_-DiTEhYg562FYSnf6_g@mail.gmail.com>

Vipin Sharma <vipinsh@google.com> writes:

> On Thu, Nov 24, 2022 at 12:36 AM Vitaly Kuznetsov <vkuznets@redhat.com> wrote:
>>
>> Vipin Sharma <vipinsh@google.com> writes:
>>
>> > On Tue, Nov 22, 2022 at 8:29 AM Vitaly Kuznetsov <vkuznets@redhat.com> wrote:
>> >>
>> >> Vipin Sharma <vipinsh@google.com> writes:
>> >>
>> >> > +/*
>> >> > + * The TLFS carves out 64 possible extended hypercalls, numbered sequentially
>> >> > + * after the base capabilities extended hypercall.
>> >> > + */
>> >> > +#define HV_EXT_CALL_MAX (HV_EXT_CALL_QUERY_CAPABILITIES + 64)
>> >> > +
>> >>
>> >> First, I thought there's an off-by-one here (and should be '63') but
>> >> then I checked with TLFS and figured out that the limit comes from
>> >> HvExtCallQueryCapabilities's response which doesn't include itself
>> >> (0x8001) in the mask, this means it can encode
>> >>
>> >> 0x8002 == bit0
>> >> 0x8003 == bit1
>> >> ..
>> >> 0x8041 == bit63
>> >>
>> >> so indeed, the last one supported is 0x8041 == 0x8001 + 64
>> >>
>> >> maybe it's worth extending the commont on where '64' comes from.
>> >>
>> >
>> > Yeah, I will expand comments.
>> >
>> >> >  static void stimer_mark_pending(struct kvm_vcpu_hv_stimer *stimer,
>> >> >                               bool vcpu_kick);
>> >> >
>> >> > @@ -2411,6 +2417,9 @@ static bool hv_check_hypercall_access(struct kvm_vcpu_hv *hv_vcpu, u16 code)
>> >> >       case HVCALL_SEND_IPI:
>> >> >               return hv_vcpu->cpuid_cache.enlightenments_eax &
>> >> >                       HV_X64_CLUSTER_IPI_RECOMMENDED;
>> >> > +     case HV_EXT_CALL_QUERY_CAPABILITIES ... HV_EXT_CALL_MAX:
>> >> > +             return hv_vcpu->cpuid_cache.features_ebx &
>> >> > +                             HV_ENABLE_EXTENDED_HYPERCALLS;
>> >> >       default:
>> >> >               break;
>> >> >       }
>> >> > @@ -2564,6 +2573,12 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
>> >> >               }
>> >> >               goto hypercall_userspace_exit;
>> >> >       }
>> >> > +     case HV_EXT_CALL_QUERY_CAPABILITIES ... HV_EXT_CALL_MAX:
>> >> > +             if (unlikely(hc.fast)) {
>> >> > +                     ret = HV_STATUS_INVALID_PARAMETER;
>> >>
>> >> I wasn't able to find any statement in TLFS stating whether extended
>> >> hypercalls can be 'fast', I can imagine e.g. MemoryHeatHintAsync using
>> >> it. Unfortunatelly, our userspace exit will have to be modified to
>> >> handle such stuff. This can stay for the time being I guess..
>> >>
>> >
>> > I agree TLFS doesn't state anything about "fast" extended hypercall
>> > but nothing stops in future for some call to be "fast". I think this
>> > condition should also be handled by userspace as it is handling
>> > everything else.
>> >
>> > I will remove it in the next version of the patch. I don't see any
>> > value in verification here.
>>
>> The problem is that we don't currently pass 'fast' flag to userspace,
>> let alone XMM registers. This means that it won't be able to handle fast
>> hypercalls anyway, I guess it's better to keep your check but add a
>> comment saying that it's an implementation shortcoming and not a TLFS
>> requirement.
>>
>
> I think "fast" flag gets passed to the userspace via:
>   vcpu->run->hyperv.u.hcall.input = hc.param;

True, for some reason I thought it's just the hypercall code but it's
actually the full 64bit thing!

>
> Yeah, XMM registers won't be passed, that will require userspace API change.
> I will keep the check and explain in the comments.
>

Thanks!

>>
>> >
>> >> > +                     break;
>> >> > +             }
>> >> > +             goto hypercall_userspace_exit;
>> >> >       default:
>> >> >               ret = HV_STATUS_INVALID_HYPERCALL_CODE;
>> >> >               break;
>> >> > @@ -2722,6 +2737,7 @@ int kvm_get_hv_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid,
>> >> >
>> >> >                       ent->ebx |= HV_POST_MESSAGES;
>> >> >                       ent->ebx |= HV_SIGNAL_EVENTS;
>> >> > +                     ent->ebx |= HV_ENABLE_EXTENDED_HYPERCALLS;
>> >> >
>> >> >                       ent->edx |= HV_X64_HYPERCALL_XMM_INPUT_AVAILABLE;
>> >> >                       ent->edx |= HV_FEATURE_FREQUENCY_MSRS_AVAILABLE;
>> >>
>> >> Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
>> >>
>> >> --
>> >> Vitaly
>> >>
>> >
>>
>> --
>> Vitaly
>>
>

-- 
Vitaly


  reply	other threads:[~2022-11-24  9:29 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-21 23:40 [PATCH v2 0/6] Add Hyper-v extended hypercall support in KVM Vipin Sharma
2022-11-21 23:40 ` [PATCH v2 1/6] KVM: x86: hyper-v: Use common code for hypercall userspace exit Vipin Sharma
2022-11-22 16:04   ` Vitaly Kuznetsov
2022-11-22 19:58     ` Sean Christopherson
2022-11-23 20:01       ` Vipin Sharma
2022-11-21 23:40 ` [PATCH v2 2/6] KVM: x86: hyper-v: Add extended hypercall support in Hyper-v Vipin Sharma
2022-11-22 16:29   ` Vitaly Kuznetsov
2022-11-23 19:43     ` Vipin Sharma
2022-11-24  8:36       ` Vitaly Kuznetsov
2022-11-24  9:03         ` Vipin Sharma
2022-11-24  9:28           ` Vitaly Kuznetsov [this message]
2022-11-21 23:40 ` [PATCH v2 3/6] KVM: selftests: Test Hyper-V extended hypercall enablement Vipin Sharma
2022-11-22 16:02   ` Vitaly Kuznetsov
2022-11-21 23:40 ` [PATCH v2 4/6] KVM: selftests: Replace hardcoded Linux OS id with HYPERV_LINUX_OS_ID Vipin Sharma
2022-11-22 16:00   ` Vitaly Kuznetsov
2022-11-21 23:40 ` [PATCH v2 5/6] KVM: selftests: Make vCPU exit reason test assertion common Vipin Sharma
2022-11-21 23:40 ` [PATCH v2 6/6] KVM: selftests: Test Hyper-V extended hypercall exit to userspace Vipin Sharma
2022-11-22 15:57   ` Vitaly Kuznetsov
2022-11-23 19:33     ` Vipin Sharma

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=87leo0og5b.fsf@ovpn-192-146.brq.redhat.com \
    --to=vkuznets@redhat.com \
    --cc=dmatlack@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=vipinsh@google.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

all inboxes | Powered by JetHome®