Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2996710imm; Sun, 13 May 2018 01:48:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr1Jxc30YPgVgg5AM8sufJo8FlstIvAxrjxsRH9z4EFwdVT71PobsO36y56hGWAxIFNcKeu X-Received: by 2002:a17:902:9a4c:: with SMTP id x12-v6mr5173645plv.213.1526201280758; Sun, 13 May 2018 01:48:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526201280; cv=none; d=google.com; s=arc-20160816; b=VhJGiOSVgSDq1q/h4ZXWCEo/eMY37scQXK20b1BUac0rKYbMcXFdcWYXmnWUknjITM I2LwqB5J3bb9VDUd2xkct6o7GyhAfAYJwG73sgDywAnmGZ98b6ErGRl5Ujo3a7ZZLuFf nWOeHTTnQqFnsqwuljtyMihf6z2PrfDKNAwSAOtnmI+EKOK5KzeSnUxQB2Asbma0s2nd hYzDy6/w52wxAzsJQ5inajlUHYcXcn18Nh25L4BIf7U7NoRCVN6z9mHjIwzfifqEwFCf RVQErxxgxZyJVxpDTEslnJbdJJf2z+YIOnNcitUF8pwi4j5r3SuV6xSuF/aC0ts/H/IC 3z1g== 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=ngSs5E1TFL6XVjRkaAHuMLhOGP/Y1wfPsc4KSUO9+KA=; b=MqjuD7OPSbcFwpIzMVwDBjHFQOmeigk7aMgvjQFn4XYSpqvOCP9TpezAP7LL5xGCma OeSCr5I8Ceo6QXnhEQOsBp+HGvXgNVeUdSCqOTcjRmfOc/b0CAW0/QU2CW8Pb0PjoFAO JG6WOsSqOsBwd6tS9T3URyOeDiHXqoi/OeT6J5nHHRok/UChh4Za5cS0UFF2PqNR0JEv zVyS1zEUA/CAd/c/RwTuy/TNQjGm3L535yz5w+SKgLSIFE7DMVzfYUFOlgfyUs/egYBO h6ThoJaBNKZIswVj5RVdPau4Xt8u2yER92PmAggjepmloNGj8feGJDh7PSChWT2xuuzd 3m5w== 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 x1-v6si6791707pfm.32.2018.05.13.01.47.46; Sun, 13 May 2018 01:48: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 S1751916AbeEMIrS (ORCPT + 99 others); Sun, 13 May 2018 04:47:18 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38804 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750949AbeEMIrQ (ORCPT ); Sun, 13 May 2018 04:47:16 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 88522407B3B8; Sun, 13 May 2018 08:47:15 +0000 (UTC) Received: from vitty.brq.redhat.com.redhat.com (ovpn-204-41.brq.redhat.com [10.40.204.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 18D2E83B99; Sun, 13 May 2018 08:47:12 +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: Sun, 13 May 2018 10:47:12 +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: <877eo8lz73.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.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Sun, 13 May 2018 08:47:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Sun, 13 May 2018 08:47:15 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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: ... > >> + /* >> + * 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. We really want to avoid memory allocation for cpumask on this path and that's what kvm_make_all_cpus_request() currently does (when CPUMASK_OFFSTACK). vcpu bitmap is probably OK as KVM_MAX_VCPUS is much lower. Making cpumask allocation avoidable leads us to the following API: bool kvm_make_vcpus_request_mask(struct kvm *kvm, unsigned int req, long *vcpu_bitmap, cpumask_var_t tmp); or, if we want to prettify this a little bit, we may end up with the following pair: bool kvm_make_vcpus_request_mask(struct kvm *kvm, unsigned int req, long *vcpu_bitmap); bool __kvm_make_vcpus_request_mask(struct kvm *kvm, unsigned int req, long *vcpu_bitmap, cpumask_var_t tmp); and from hyperv code we'll use the later. With this, no code duplication is required. Does this look acceptable? -- Vitaly