Received: by 10.213.65.68 with SMTP id h4csp3879596imn; Tue, 3 Apr 2018 12:16:37 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/hOprxOHQteXuR5sNJD4asKcND8jJNmQpFCm0U7fBFhVkGR3ar8fk4Fw8dph0ZU1bps/vK X-Received: by 2002:a17:902:b101:: with SMTP id q1-v6mr15219703plr.3.1522782997608; Tue, 03 Apr 2018 12:16:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522782997; cv=none; d=google.com; s=arc-20160816; b=iVzxAhWzPbNhXGva4dx2rOWLIF5E4hdodMfN9MItw+UZCCmmloZCbpPNo6HEI+9xp+ udfeA31DgXElTGPZMkKU5UeBhGbT3+DtmCEpiyQBf/eOjbDdCf03Ga3tbgf1ZVJbNHnl iZ5+BvKznvhD2qzsAC2dgngc9YEQ1K9VSO91DbXLSVx6zvqrwS9prolaxCOqAH6vYtaM teHo4wxQKNYCBkGNezOu2OuJLINiv+e6d7O3Hg9apsZdqbf7FRAQBxQCh9LxKzIPhoRS UIa9vkdjOkoLfs/GVA57GJpA6jchBh0r6TfUPkGL2Ny6tfaf8/sBMr7tX5/qZFXmfFdC UD3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=+NwxNLBY/IPWXNonJzOe3/A1PfLi0uV/RfbVkTyAFWc=; b=by2EmWekmXXDQ9w2nenqSCLtXzuysXe7QF2uak3IM0+cs/fEJ2IxlipBcW18S6B8xs oJhl1HY4aUHY1j+/9apvNllZH/qUu5KcailJsIOWS9kzi54BCme+XE9+1G6e2+s2/QNQ K/ML5OjCI5PLFRVFnOr3b+w4eb3/3pB1I0icXjgzwMGwW6oq1JMjroAsuEdds+xjmUGl U1iSYtduQeedm5rAOtPquK6PpTZgNcCRKErnfmzhX9ZwtKCM6lRCni6zUVtKqucD+lO4 x3uNebHVBBERzjbrsn/fUakV0D3tSsVE0Voq1YtW3vmdBECTqLkc2AMlNVdIgu9j1VMm seJw== 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 u2-v6si3600014plm.671.2018.04.03.12.16.22; Tue, 03 Apr 2018 12:16:37 -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 S1752973AbeDCTPP (ORCPT + 99 others); Tue, 3 Apr 2018 15:15:15 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38090 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751179AbeDCTPN (ORCPT ); Tue, 3 Apr 2018 15:15:13 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 304B54023150; Tue, 3 Apr 2018 19:15:13 +0000 (UTC) Received: from flask (unknown [10.43.2.80]) by smtp.corp.redhat.com (Postfix) with SMTP id 80CBF215CDAF; Tue, 3 Apr 2018 19:15:09 +0000 (UTC) Received: by flask (sSMTP sendmail emulation); Tue, 03 Apr 2018 21:15:08 +0200 Date: Tue, 3 Apr 2018 21:15:08 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Vitaly Kuznetsov Cc: kvm@vger.kernel.org, x86@kernel.org, Paolo Bonzini , Roman Kagan , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , "Michael Kelley (EOSG)" , Mohammed Gamal , Cathy Avery , linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/5] KVM: x86: hyperv: simplistic HVCALL_FLUSH_VIRTUAL_ADDRESS_{LIST,SPACE} implementation Message-ID: <20180403191508.GA7386@flask> References: <20180402161059.8488-1-vkuznets@redhat.com> <20180402161059.8488-4-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180402161059.8488-4-vkuznets@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 03 Apr 2018 19:15:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 03 Apr 2018 19:15:13 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'rkrcmar@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-04-02 18:10+0200, Vitaly Kuznetsov: > Implement HvFlushVirtualAddress{List,Space} hypercalls in a simplistic way: > do full TLB flush with KVM_REQ_TLB_FLUSH and rely on kvm_vcpu_kick() > kicking only vCPUs which are currently IN_GUEST_MODE. > > Signed-off-by: Vitaly Kuznetsov > --- > arch/x86/kvm/hyperv.c | 54 ++++++++++++++++++++++++++++++++++++++++++++------- > arch/x86/kvm/trace.h | 24 +++++++++++++++++++++++ > 2 files changed, 71 insertions(+), 7 deletions(-) > > diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c > index 3cb3bb68db7e..aa866994366d 100644 > --- a/arch/x86/kvm/hyperv.c > +++ b/arch/x86/kvm/hyperv.c > @@ -1242,6 +1242,49 @@ int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) > return kvm_hv_get_msr(vcpu, msr, pdata); > } > > +static u64 kvm_hv_flush_tlb(struct kvm_vcpu *current_vcpu, u64 ingpa, > + u16 rep_cnt) > +{ > + struct kvm *kvm = current_vcpu->kvm; > + struct hv_tlb_flush flush; > + struct kvm_vcpu *vcpu; > + int i; > + > + if (unlikely(kvm_read_guest(kvm, ingpa, &flush, sizeof(flush)))) > + return HV_STATUS_INVALID_HYPERCALL_INPUT; > + > + trace_kvm_hv_flush_tlb(flush.processor_mask, flush.address_space, > + flush.flags); > + > + kvm_for_each_vcpu(i, vcpu, kvm) { > + struct kvm_vcpu_hv *hv = &vcpu->arch.hyperv; > + > + if (!(flush.flags & HV_FLUSH_ALL_PROCESSORS) && > + !(flush.processor_mask & BIT_ULL(hv->vp_index))) > + continue; > + > + /* > + * vcpu->arch.cr3 may not be up-to-date for running vCPUs so we > + * can't analyze it here, flush TLB regardless of the specified > + * address space. > + */ > + kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu); > + > + /* > + * It is very unlikely but possible that we're doing an extra > + * kick here (e.g. if the vCPU has just entered the guest and > + * has its TLB flushed). > + */ > + if (vcpu != current_vcpu) > + kvm_vcpu_kick(vcpu); The spec says that "This call guarantees that by the time control returns back to the caller, the observable effects of all flushes on the specified virtual processors have occurred." Other KVM code doesn't assume that kvm_vcpu_kick() and a delay provides that guarantee; kvm_make_all_cpus_request waits for the target CPU to exit before saying that TLB has been flushed. I am leaning towards the safer variant here as well. (Anyway, it's a good time to figure out if we really need it.) > + } > + > + /* We always do full TLB flush, set rep_done = rep_cnt. */ > + return (u64)HV_STATUS_SUCCESS | > + ((u64)rep_cnt << HV_HYPERCALL_REP_START_OFFSET) | Why at bits 48-59? I don't see this field in the spec. > + ((u64)rep_cnt << HV_HYPERCALL_REP_COMP_OFFSET); > +} > + > bool kvm_hv_hypercall_enabled(struct kvm *kvm) > { > return READ_ONCE(kvm->arch.hyperv.hv_hypercall) & HV_X64_MSR_HYPERCALL_ENABLE; > @@ -1345,12 +1388,6 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) > > trace_kvm_hv_hypercall(code, fast, rep_cnt, rep_idx, ingpa, outgpa); > > - /* Hypercall continuation is not supported yet */ > - if (rep_cnt || rep_idx) { > - ret = HV_STATUS_INVALID_HYPERCALL_CODE; Hm, we should have returned HV_STATUS_INVALID_HYPERCALL_INPUT in any case. I think it would be good to still fail in case of non-rep hypercalls, thanks.