Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1778564imm; Thu, 27 Sep 2018 02:19:00 -0700 (PDT) X-Google-Smtp-Source: ACcGV60zPfHqrC7kuqZONjjM1mk9i/zxkJ4StPShcu6l3OKXSetMrcdlSbehLpMxkgOrSzgsCLBS X-Received: by 2002:a62:8913:: with SMTP id v19-v6mr10407937pfd.127.1538039940851; Thu, 27 Sep 2018 02:19:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538039940; cv=none; d=google.com; s=arc-20160816; b=PfC55MvXDdpki+7x/xXk1w1dxhMGY9SjjCFWoSoIk9DEB9fPw+JG3qmGX6h3PJ8QFl KylVZux1gHxgmNliKUfEFYl/NpnIgeww55wWiZIe4tEwJBjbmcqB2LuTEzZvqxK5L8Zj bxQMMhJkaxeUcKQhgt3jcFSnrEnELyXfFP51X+OG76OTFnJ3wG12nRxR2GeGt1sIAvvb Jyc/jiRPe2t9yktai/t6iSMvhxiAE1avTkB8Wf6XMwiNX5hRgrvHZUObdSqtxnnknAD1 qynoQHaMLAq+4V2HZM+D6/PPOnL81NcZQ5BgVL/uzT84HBjoLMeuEA+It+s2EPxTHltN xLPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=D2VnTUkcPuLXnbSgRyhCYr3rV1O6wqi+HoDpaUoLBNE=; b=IvikQjejCta8+bDqQZhXVpWNPXlWgV8Dqm9hpN2Hoepmek0JFdOIshhYlymj8NKW1O qOiX5V45REbCTZ2cdJ1wq+ujGPj0uXplsM3PRd2NBtPV2uHYmpYGbeCjjHRPi3+5unST zuOt6ZExES4uc3hWr7yW5dtyBIqd0ePrexSEj4WjmfKGf5NK/b0wUuoeNybeZtvIpeKH WgWj8XlatHQEeOucGCbQDoqgzFGCg0PuPTnKCh7eLFv7OAO+dt8uqgYNU8zTtUO6t5lY BIP9s/cDuK8fEIe/V5NTAeM21yj7iMTMy3ksCj7WllTDih+gyyq4c0uHf4Z89HoqnOca cG6w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l5-v6si1507780pgg.277.2018.09.27.02.18.45; Thu, 27 Sep 2018 02:19:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728946AbeI0PfW (ORCPT + 99 others); Thu, 27 Sep 2018 11:35:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57066 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727469AbeI0PfV (ORCPT ); Thu, 27 Sep 2018 11:35:21 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C395B85541; Thu, 27 Sep 2018 09:18:03 +0000 (UTC) Received: from vitty.brq.redhat.com.redhat.com (unknown [10.43.2.217]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5A14B2A2C7; Thu, 27 Sep 2018 09:18:01 +0000 (UTC) From: Vitaly Kuznetsov To: Roman Kagan Cc: kvm@vger.kernel.org, Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , "Michael Kelley \(EOSG\)" , Mohammed Gamal , Cathy Avery , Wanpeng Li , linux-kernel@vger.kernel.org Subject: Re: [PATCH v6 4/7] KVM: x86: hyperv: keep track of mismatched VP indexes In-Reply-To: <20180927075911.GB4186@rkaganb.sw.ru> References: <20180926170259.29796-1-vkuznets@redhat.com> <20180926170259.29796-5-vkuznets@redhat.com> <20180927075911.GB4186@rkaganb.sw.ru> Date: Thu, 27 Sep 2018 11:17:59 +0200 Message-ID: <87sh1vfge0.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 27 Sep 2018 09:18:03 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Roman Kagan writes: > On Wed, Sep 26, 2018 at 07:02:56PM +0200, Vitaly Kuznetsov wrote: >> In most common cases VP index of a vcpu matches its vcpu index. Userspace >> is, however, free to set any mapping it wishes and we need to account for >> that when we need to find a vCPU with a particular VP index. To keep search >> algorithms optimal in both cases introduce 'num_mismatched_vp_indexes' >> counter showing how many vCPUs with mismatching VP index we have. In case >> the counter is zero we can assume vp_index == vcpu_idx. >> >> Signed-off-by: Vitaly Kuznetsov >> --- >> arch/x86/include/asm/kvm_host.h | 3 +++ >> arch/x86/kvm/hyperv.c | 26 +++++++++++++++++++++++--- >> 2 files changed, 26 insertions(+), 3 deletions(-) >> >> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h >> index 09b2e3e2cf1b..711f79f1b5e6 100644 >> --- a/arch/x86/include/asm/kvm_host.h >> +++ b/arch/x86/include/asm/kvm_host.h >> @@ -781,6 +781,9 @@ struct kvm_hv { >> u64 hv_reenlightenment_control; >> u64 hv_tsc_emulation_control; >> u64 hv_tsc_emulation_status; >> + >> + /* How many vCPUs have VP index != vCPU index */ >> + atomic_t num_mismatched_vp_indexes; >> }; >> >> enum kvm_irqchip_mode { >> diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c >> index c8764faf783b..6a19c8e3c432 100644 >> --- a/arch/x86/kvm/hyperv.c >> +++ b/arch/x86/kvm/hyperv.c >> @@ -1045,11 +1045,31 @@ static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host) >> struct kvm_vcpu_hv *hv_vcpu = &vcpu->arch.hyperv; >> >> switch (msr) { >> - case HV_X64_MSR_VP_INDEX: >> - if (!host || (u32)data >= KVM_MAX_VCPUS) >> + case HV_X64_MSR_VP_INDEX: { >> + struct kvm_hv *hv = &vcpu->kvm->arch.hyperv; >> + int vcpu_idx = kvm_vcpu_get_idx(vcpu); >> + u32 new_vp_index = (u32)data; >> + >> + if (!host || new_vp_index >= KVM_MAX_VCPUS) >> return 1; >> - hv_vcpu->vp_index = (u32)data; >> + >> + if (new_vp_index == hv_vcpu->vp_index) >> + return 0; >> + >> + /* >> + * VP index is changing, increment num_mismatched_vp_indexes in >> + * case it was equal to vcpu_idx before; on the other hand, if >> + * the new VP index matches vcpu_idx num_mismatched_vp_indexes >> + * needs to be decremented. > > It may be worth mentioning that the initial balance is provided by > kvm_hv_vcpu_postcreate setting vp_index = vcpu_idx. > Of course, yes, will update the comment in case I'll be re-submitting. >> + */ >> + if (hv_vcpu->vp_index == vcpu_idx) >> + atomic_inc(&hv->num_mismatched_vp_indexes); >> + else if (new_vp_index == vcpu_idx) >> + atomic_dec(&hv->num_mismatched_vp_indexes); > >> + >> + hv_vcpu->vp_index = new_vp_index; >> break; >> + } >> case HV_X64_MSR_VP_ASSIST_PAGE: { >> u64 gfn; >> unsigned long addr; > > Reviewed-by: Roman Kagan Thanks! -- Vitaly