Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp719964imm; Fri, 11 May 2018 05:27:43 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoqvV/UEWgZCQ1USx07q84H3v7SLoz45Gy1b9M6yhP45wFB15j4nuxRPgwS0ftzl/fxLlUX X-Received: by 2002:a17:902:694b:: with SMTP id k11-v6mr5392027plt.334.1526041663312; Fri, 11 May 2018 05:27:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526041663; cv=none; d=google.com; s=arc-20160816; b=s3NeaFY0dhOXRRe8Lm2MD+U7+NfPGnIm0yPFE/+f5hPoelwizpkQoCQ5IFlB/wONB+ kF35820LO5WjtebACo7MSEoyEnGOzbrXQ7s70RYpB5xU7zHJmsOnNTC7+Gxm0MpfOQpx hELjSCgfV4x9QvmlcbuQS+3hkl6rofm1Dbb6xqpkgSRhioKGN6zmuzGZUeXHba4zab/H szv2LxboBrx9LFv+ktxn6+5XS2ybL6EMdbmYxwMbIWxxV3vECoD7KKGGLcHFqRJGuYSU KXsXZPJWlRpY10alHbUWcSz7GtGvLQaayRiwKfUaAJTPpwz3yXkR0eJXTHEaSAkZlyZq 2+HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:message-id:in-reply-to:date:references:subject:cc:to :from:arc-authentication-results; bh=W5vhurjMU2njfynQywPef2wdL/lVVODKo34Ge2G4brM=; b=R6iqcX2g5ieHruNDXjXPzMQ6EpBhd8VnFE5Omy/w9qyh4CaUDvmoThc5wZIiyiw4ST HZJ/tKfb4DTUwsKwPKPRTzgjUmDJqoEjlZ8B6nvuGPFTJlKQOwliMTGwEYmLoojy+Qy1 aqUlu0JfcliIVd37s2v9tnplyDQQWBm4+Qg3KIOrlJ3N/x5OOWtvOeRXtWOg0LoFANe8 3oQQRM+efLwEKrqEw+rBF5uxKDw09jASzP2o5siUr43c69zOCyOMFoX7LjaI8dcd5yj3 g6PPUREiQB8aIfQs5nWff2FVvqcp8xDtUKu2Gpow5UrsjTtQgSFl2UR9cL3rpX28sobM i1qw== 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 p11-v6si2809080plk.294.2018.05.11.05.27.27; Fri, 11 May 2018 05:27:43 -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 S1752692AbeEKM1P (ORCPT + 99 others); Fri, 11 May 2018 08:27:15 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37362 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750726AbeEKM1N (ORCPT ); Fri, 11 May 2018 08:27:13 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5607A8185344; Fri, 11 May 2018 12:27:13 +0000 (UTC) Received: from vitty.brq.redhat.com.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4F7AB1002976; Fri, 11 May 2018 12:27:11 +0000 (UTC) From: Vitaly Kuznetsov To: Radim =?utf-8?B?S3LEjW3DocWZ?= 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 4/6] KVM: x86: hyperv: simplistic HVCALL_FLUSH_VIRTUAL_ADDRESS_{LIST,SPACE} implementation References: <20180416110806.4896-1-vkuznets@redhat.com> <20180416110806.4896-5-vkuznets@redhat.com> <20180510194016.GB3885@flask> Date: Fri, 11 May 2018 14:27:10 +0200 In-Reply-To: <20180510194016.GB3885@flask> ("Radim \=\?utf-8\?B\?S3LEjW3DocWZ\?\= \=\?utf-8\?B\?Iidz\?\= message of "Thu, 10 May 2018 21:40:17 +0200") Message-ID: <87in7uml7l.fsf@vitty.brq.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 11 May 2018 12:27:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 11 May 2018 12:27:13 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'vkuznets@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Radim Krčmář writes: > 2018-04-16 13:08+0200, Vitaly Kuznetsov: >> Implement HvFlushVirtualAddress{List,Space} 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 >> @@ -1242,6 +1242,65 @@ int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) >> return kvm_hv_get_msr(vcpu, msr, pdata); >> } >> >> +static void ack_flush(void *_completed) >> +{ >> +} >> + >> +static u64 kvm_hv_flush_tlb(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 flush; >> + struct kvm_vcpu *vcpu; >> + int i, cpu, me; >> + >> + 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); >> + >> + cpumask_clear(&hv_current->tlb_lush); >> + >> + me = get_cpu(); >> + >> + kvm_for_each_vcpu(i, vcpu, kvm) { >> + struct kvm_vcpu_hv *hv = &vcpu->arch.hyperv; >> + >> + if (!(flush.flags & HV_FLUSH_ALL_PROCESSORS) && > > Please add a check to prevent undefined behavior in C: > > (hv->vp_index >= 64 || > >> + !(flush.processor_mask & BIT_ULL(hv->vp_index))) >> + continue; > > It would also fail in the wild as shl only considers the bottom 5 bits. > >> + /* >> + * 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 possible that vCPU will migrate and we will kick wrong >> + * CPU but vCPU's TLB will anyway be flushed upon migration as >> + * we already made KVM_REQ_TLB_FLUSH request. >> + */ >> + cpu = vcpu->cpu; >> + if (cpu != -1 && cpu != me && cpu_online(cpu) && >> + kvm_arch_vcpu_should_kick(vcpu)) >> + cpumask_set_cpu(cpu, &hv_current->tlb_lush); >> + } >> + >> + if (!cpumask_empty(&hv_current->tlb_lush)) >> + smp_call_function_many(&hv_current->tlb_lush, ack_flush, >> + NULL, true); > > Hm, quite a lot of code duplication with EX hypercall and also > kvm_make_all_cpus_request ... I'm thinking about making something like > > kvm_make_some_cpus_request(struct kvm *kvm, unsigned int req, > bool (*predicate)(struct kvm_vcpu *vcpu)) > > or to implement a vp_index -> vcpu mapping and using > > kvm_vcpu_request_mask(struct kvm *kvm, unsigned int req, long *vcpu_bitmap) > > The latter would probably simplify logic of the EX hypercall. > > What do you think? Makes sense, I'll take a look. Thanks! -- Vitaly