Received: by 10.192.165.148 with SMTP id m20csp1588804imm; Thu, 10 May 2018 13:08:55 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoNtZAgXl3+8bm4zl4mWe4rIXKzj/Rkq4+Za7rlnuDfQHqhh0wek4FplyTi9ed127mzUGsW X-Received: by 2002:a65:488c:: with SMTP id n12-v6mr2177111pgs.155.1525982935007; Thu, 10 May 2018 13:08:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525982934; cv=none; d=google.com; s=arc-20160816; b=nzAh3pV4V9pae9QTheC1AdAOqhRyWeptjbRHl1c4IrYxAk2AhqthSKdmrCXO+b1BnL wYXEZMcONtB2Oq5IQ3BYDcy7W1zBuYbW13sf+fXJMm/XskMDF1AFXl4y5YQ7g5sBcg3I TD0b+r6lzRCBW7yWhIOFgbvaQlp3SfeJt3ry+7fkc/EH5YaPqnlLYAAI6JRv4GUbrbx2 MxrZ2UnkZoS9O14EEAkWtxlEQ0FUCUm3+8hWk5BO39bHBnaeOYcBk6ARrSrBsDrzzGQe +NdIjKgJP33ksAgtt7mEvLJYHOzXqzLs0SgdWog+P8ANR6VIFJyiC4aQo9MDegYwxW/6 sRew== 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=/Qj28+m8tjnV1LJCt3NZqWwm3+A3ajAvmeCumGriZ8s=; b=R1aCVpS0KBP51atMj4P+GvHnSNwt2Wr6O9zbdNn9cyuDXMOZ3Z/ME2HsuRGo6qubdG ZskUxyajn/JFt0zEt889ksb36sMwwXxjSe+JgLAx3uYlj8IredUKgnrQ/6ID7vTJlPQP qEnIMuAGxHirtjnnM8or/GfPCMmugnHwC+T6sl7d7S1FnmTH0Gv3xhGC96aECNstFV7Z LcmJsylW+dPIxZmT9pBr2R9n9RAIJv1ahgSnb2/kbUsdJzuBGCbgf9OU6eUfLaWVI5pr x7chLyiSxdSWd2xoorA9VKxAL2naXPvlDpu/ihIxbJK7yUBGo+yQpEKUWIREDARG3YcK BcCA== 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 a8-v6si1611973pln.349.2018.05.10.13.08.40; Thu, 10 May 2018 13:08:54 -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 S1752019AbeEJUIc (ORCPT + 99 others); Thu, 10 May 2018 16:08:32 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59688 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750876AbeEJUIb (ORCPT ); Thu, 10 May 2018 16:08:31 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C10C7818A6A3; Thu, 10 May 2018 20:08:30 +0000 (UTC) Received: from flask (unknown [10.43.2.80]) by smtp.corp.redhat.com (Postfix) with SMTP id 113E52026DEF; Thu, 10 May 2018 20:08:27 +0000 (UTC) Received: by flask (sSMTP sendmail emulation); Thu, 10 May 2018 22:08:27 +0200 Date: Thu, 10 May 2018 22:08:27 +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 v3 5/6] KVM: x86: hyperv: simplistic HVCALL_FLUSH_VIRTUAL_ADDRESS_{LIST,SPACE}_EX implementation Message-ID: <20180510200826.GC3885@flask> References: <20180416110806.4896-1-vkuznets@redhat.com> <20180416110806.4896-6-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180416110806.4896-6-vkuznets@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 10 May 2018 20:08:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 10 May 2018 20:08:30 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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-16 13:08+0200, Vitaly Kuznetsov: > Implement HvFlushVirtualAddress{List,Space}Ex hypercalls in a simplistic > way: do full TLB flush with KVM_REQ_TLB_FLUSH and kick vCPUs which are > currently IN_GUEST_MODE. > > Signed-off-by: Vitaly Kuznetsov > --- > diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c > @@ -1301,6 +1301,108 @@ static u64 kvm_hv_flush_tlb(struct kvm_vcpu *current_vcpu, u64 ingpa, > ((u64)rep_cnt << HV_HYPERCALL_REP_COMP_OFFSET); > } > > +static __always_inline int get_sparse_bank_no(u64 valid_bank_mask, int bank_no) > +{ > + int i = 0, j; > + > + if (!(valid_bank_mask & BIT_ULL(bank_no))) > + return -1; > + > + for (j = 0; j < bank_no; j++) > + if (valid_bank_mask & BIT_ULL(j)) > + i++; > + > + return i; > +} > + > +static __always_inline int load_bank_guest(struct kvm *kvm, u64 ingpa, > + int sparse_bank, u64 *bank_contents) > +{ > + int offset; > + > + offset = offsetof(struct hv_tlb_flush_ex, hv_vp_set.bank_contents) + > + sizeof(u64) * sparse_bank; > + > + if (unlikely(kvm_read_guest(kvm, ingpa + offset, > + bank_contents, sizeof(u64)))) > + return 1; > + > + return 0; > +} > + > +static int kvm_hv_flush_tlb_ex(struct kvm_vcpu *current_vcpu, u64 ingpa, > + u16 rep_cnt) > +{ > + struct kvm *kvm = current_vcpu->kvm; > + struct kvm_vcpu_hv *hv_current = ¤t_vcpu->arch.hyperv; > + struct hv_tlb_flush_ex flush; > + struct kvm_vcpu *vcpu; > + u64 bank_contents, valid_bank_mask; > + int i, cpu, me, current_sparse_bank = -1; > + u64 ret = HV_STATUS_INVALID_HYPERCALL_INPUT; > + > + if (unlikely(kvm_read_guest(kvm, ingpa, &flush, sizeof(flush)))) > + return ret; > + > + valid_bank_mask = flush.hv_vp_set.valid_bank_mask; > + > + trace_kvm_hv_flush_tlb_ex(valid_bank_mask, flush.hv_vp_set.format, > + flush.address_space, flush.flags); > + > + cpumask_clear(&hv_current->tlb_lush); > + > + me = get_cpu(); > + > + kvm_for_each_vcpu(i, vcpu, kvm) { > + struct kvm_vcpu_hv *hv = &vcpu->arch.hyperv; > + int bank = hv->vp_index / 64, sparse_bank; > + > + if (flush.hv_vp_set.format == HV_GENERIC_SET_SPARCE_4K) { ^ typo in the define > + /* Check is the bank of this vCPU is in sparse set */ > + sparse_bank = get_sparse_bank_no(valid_bank_mask, bank); > + if (sparse_bank < 0) > + continue; > + > + /* > + * Assume hv->vp_index is in ascending order and we can > + * optimize by not reloading bank contents for every > + * vCPU. > + */ Since sparse_bank is packed, we could compute how many bank_contents do we need to load and do it with one kvm_read_guest() into a local array; it would be faster even if hv->vp_index were in ascending order and wouldn't take that much memory (up to 512 B). > + if (sparse_bank != current_sparse_bank) { > + if (load_bank_guest(kvm, ingpa, sparse_bank, > + &bank_contents)) > + return ret; > + current_sparse_bank = sparse_bank; > + }