Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3966059imm; Mon, 11 Jun 2018 04:59:02 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJqW/VkBtFa3lmgdBKV62mUbW+3JF5W7u1VMpMCyNerkn+SX75hOIsIexOUJ+IBC7O4NStQ X-Received: by 2002:a62:2394:: with SMTP id q20-v6mr17240971pfj.1.1528718342238; Mon, 11 Jun 2018 04:59:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528718342; cv=none; d=google.com; s=arc-20160816; b=D9gRHDqGasCCFGzCo2WWRVRUAz1wS919biPv/DLho4fdMkcFIYlaDxkS2a6ww4/Qh1 MoUpkcvIdQSLI7twPhB6dAJbp3SvFu8/uvsxYVbANKyvPhA1pBMpBmqUSpPkKOFTJONH W/haY/NxF+T5/xWXdRaVM+CINVZTtMnqOxxQfcORMieX4f00VP+eW74PkigPFKIS9jme XloDgAjg3JSNG/FaSH5kwJ75eiQvbOcF3sUL//xtKhkSlGIm9ehJSKhxSWfj9F0moZH3 +56DUNvkD91AV/5vkBq09MYyFaID0FE2BV4fgO9kJzXRVnHFzsUVKBvMykIEPGKwQsXt i+Jw== 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=wx3KOe5Y0TR7sX3RB9aYbHtQhAIm8N3F5YHizPPoicc=; b=sruWFnlCG4f5pXTrcbtzL5W2fKY7vk53AqhJI8KiiSV1HdzFihdMVOyzznq6A7ZEcE FC9frczNycmDR3o3vfyZKl1HuMD4zj0x0yzktRuRK4fL+n8d8Iwg5NokcHJoFeZA4wfQ cSrfB8gqMoTs3tLOAjbKP7YsHb+eEvJWsNHtFlV8ujAGmM60rfZTRpq4YdpJBuMxVg+Y EpWCJgDd+ZRzLiSt+rtKHAKn+lAy0uDVHyoXKBO7mbRPuNi6P1vLIvCb/Si0dtnilCE7 ciVagmzkUMDVb8E2pJbK22hEsFo94VRlq2m1L2WgwWvTvoGdWO8ZAMp9v8Y0OOQ0NdCY PiNQ== 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 67-v6si64044617pfm.167.2018.06.11.04.58.48; Mon, 11 Jun 2018 04:59:02 -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 S933326AbeFKL5K (ORCPT + 99 others); Mon, 11 Jun 2018 07:57:10 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55430 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933194AbeFKL5F (ORCPT ); Mon, 11 Jun 2018 07:57:05 -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 B1919406E807; Mon, 11 Jun 2018 11:57:04 +0000 (UTC) Received: from vitty.brq.redhat.com.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C4F27111AF0F; Mon, 11 Jun 2018 11:57:02 +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 v4 5/8] KVM: introduce kvm_make_vcpus_request_mask() API References: <20180516152131.30689-1-vkuznets@redhat.com> <20180516152131.30689-6-vkuznets@redhat.com> <20180526144946.GF23390@flask> Date: Mon, 11 Jun 2018 13:57:01 +0200 In-Reply-To: <20180526144946.GF23390@flask> ("Radim \=\?utf-8\?B\?S3LEjW3DocWZ\?\= \=\?utf-8\?B\?Iidz\?\= message of "Sat, 26 May 2018 16:49:47 +0200") Message-ID: <87bmchtu2a.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.7]); Mon, 11 Jun 2018 11:57:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 11 Jun 2018 11:57:04 +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-05-16 17:21+0200, Vitaly Kuznetsov: >> Hyper-V style PV TLB flush hypercalls inmplementation will use this API. >> To avoid memory allocation in CONFIG_CPUMASK_OFFSTACK case add >> cpumask_var_t argument. >> >> Signed-off-by: Vitaly Kuznetsov >> --- >> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c >> -bool kvm_make_all_cpus_request(struct kvm *kvm, unsigned int req) >> +bool kvm_make_vcpus_request_mask(struct kvm *kvm, unsigned int req, >> + unsigned long *vcpu_bitmap, cpumask_var_t tmp) >> { >> int i, cpu, me; >> - cpumask_var_t cpus; >> - bool called; >> struct kvm_vcpu *vcpu; >> - >> - zalloc_cpumask_var(&cpus, GFP_ATOMIC); >> + bool called; >> >> me = get_cpu(); >> + > > Two optimizations come to mind: First is to use for_each_set_bit instead > of kvm_for_each_vcpu to improve the sparse case. > I think I had such version at some point but then for some reason I decided I'm re-implementing kvm_for_each_vcpu for no particular reason. >> kvm_for_each_vcpu(i, vcpu, kvm) { >> + if (!test_bit(i, vcpu_bitmap)) > > And the second is to pass vcpu_bitmap = NULL instead of building the > bitmap with all VCPUs. Doesn't looks too good in the end, though: > > #define kvm_for_each_vcpu_bitmap(idx, vcpup, kvm, bitmap, len) \ > for (idx = (bitmap ? find_first_bit(bitmap, len) : 0); \ > idx < len && (vcpup = kvm_get_vcpu(kvm, idx)) != NULL; \ > bitmap ? find_next_bit(bitmap, len, idx + 1) : idx++) I'll take a try, thanks! -- Vitaly