From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDD6EC48BE5 for ; Tue, 15 Jun 2021 14:25:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C76F361483 for ; Tue, 15 Jun 2021 14:25:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231332AbhFOO1Y (ORCPT ); Tue, 15 Jun 2021 10:27:24 -0400 Received: from linux.microsoft.com ([13.77.154.182]:43360 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231417AbhFOO0W (ORCPT ); Tue, 15 Jun 2021 10:26:22 -0400 Received: from [192.168.86.35] (c-73-38-52-84.hsd1.vt.comcast.net [73.38.52.84]) by linux.microsoft.com (Postfix) with ESMTPSA id 46E8720B6C50; Tue, 15 Jun 2021 07:24:14 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 46E8720B6C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1623767057; bh=cTHCck5KxKI/CP9LuHPjfsJBbv22Q8bxdprLpu918Iw=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=gVGORou0bGGK/tDWC+ScR4xEWsbnBBcs7/CdN1MOHGlJIH94UjEqOAvgBSDKHS35O ceRtBHHCZbXj840On4Gh5lNTG9vo8IO0hh39xOjN8gOoSv2dGDgXnASaf84hDDoEPT HtxukizWCqySB5fOlL+ii6Hx3XawlTf52rssJQWI= Subject: Re: [PATCH v5 7/7] KVM: SVM: hyper-v: Direct Virtual Flush support To: Vitaly Kuznetsov , Paolo Bonzini , kvm@vger.kernel.org Cc: "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "K. Y. Srinivasan" , x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, Lan Tianyu , Michael Kelley , Sean Christopherson , Tom Lendacky , Wanpeng Li , Jim Mattson , Joerg Roedel , Wei Liu , Stephen Hemminger , Haiyang Zhang , Maxim Levitsky References: <878s3c65nr.fsf@vitty.brq.redhat.com> From: Vineeth Pillai Message-ID: <73508c14-3ca6-1d20-8f9e-14bd966c849a@linux.microsoft.com> Date: Tue, 15 Jun 2021 10:24:14 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <878s3c65nr.fsf@vitty.brq.redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Vitaly, >> + >> +static inline void svm_hv_update_vp_id(struct vmcb *vmcb, >> + struct kvm_vcpu *vcpu) >> +{ >> + struct hv_enlightenments *hve = >> + (struct hv_enlightenments *)vmcb->control.reserved_sw; >> + >> + if (hve->hv_vp_id != to_hv_vcpu(vcpu)->vp_index) { >> + hve->hv_vp_id = to_hv_vcpu(vcpu)->vp_index; >> + vmcb_mark_dirty(vmcb, VMCB_HV_NESTED_ENLIGHTENMENTS); >> + } > This blows up in testing when no Hyper-V context was created on a vCPU, > e.g. when running KVM selftests (to_hv_vcpu(vcpu) is NULL when no > Hyper-V emulation features were requested on a vCPU but > svm_hv_update_vp_id() is called unconditionally by svm_vcpu_run()). > > I'll be sending a patch to fix the immediate issue but I was wondering > why we need to call svm_hv_update_vp_id() from svm_vcpu_run() as VP > index is unlikely to change; we can probably just call it from > kvm_hv_set_msr() instead. Thanks a lot for catching this. I think you are right, updating at kvm_hv_set_msr() makes sense. I was following the vmx logic where it also sets the vp_id in vmx_vcpu_run. But it calls a wrapper "kvm_hv_get_vpindex" which actually checks if hv_vcpu is not null before the assignment. I should have used that instead, my mistake. I will look a bit more into it and send out a patch for vmx and svm after little more investigation. Thanks, Vineeth