Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp648714imm; Sat, 26 May 2018 07:50:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpYnAKzLSSzMNmGAbd6T4tDEbGjXRB+3rmhhoo4ufQbOpliy3xLXLc54gxC07AICRMAeCwm X-Received: by 2002:a63:7f15:: with SMTP id a21-v6mr5244860pgd.21.1527346226848; Sat, 26 May 2018 07:50:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527346226; cv=none; d=google.com; s=arc-20160816; b=OXOTPBp94vUKRDa4umHUjYxP+xh1AK1gpxEyAPQE+iGnoPqOyM0AF/NQFdb3yPCiHP YK/1aPCBpOcNDP8eShcwk3uCDrmoDIi80bOKC2k0T/m/B6K/SWyqfQlx0Xzr9OvMNEFu pZgq08uen1YLm4CsNaKDYt5y9KDdpdHt5t0h47gHqIOhSlu03oQNhBod+0oC+TcMtkst ugyINqs7ZPBCSJmCF9DzCOEg/mJ8dGL2rghA/xk0rZgNsGdwgcaBx5pGxYwzpWkPlB83 B3Ldp7COdL6SKUEMqMfPAbylk9zecwZqPv8CXBfkspHzxs8gOIvB7gldcHbaXbrzla+M KMWA== 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=mFZ0sNw9TZ0dlSsUwsFlooAW2P/oP6qxAPox8CSyoQI=; b=Ev0b+S3RBLiZ2bhnl2NHY74gUjBE+oHsU6Qzt3P+2YVl3orePcq4SEE/wNIkuARzyy /+by3mr26wvyyINC3GWxtgE7Q/oZNdtjerZ0xPeB/4kNxmMxLRfNrzmArneYNDsYQNsh m8JqSmKjztDO53pmaccreAxmdennuD1h5fKT5S6paKy6CFPbSAoeewosTRtUQmYZRzwj TvEFL8ci0q3c+1kfzHbMO29HLvx5hXJjHiySFiYyzDJOlxNryyvr1qT8Zc/EjBpe1MHd C08v5OKYVQYQg/U8wjtY64CIpryKpAMIDF/ubDEjaMKG4Ud5CrR/lYUVFyqmLpBDhz4R UBNQ== 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 a23-v6si25072671pfi.353.2018.05.26.07.49.59; Sat, 26 May 2018 07:50:26 -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 S1754988AbeEZOtw (ORCPT + 99 others); Sat, 26 May 2018 10:49:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:32834 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753991AbeEZOtv (ORCPT ); Sat, 26 May 2018 10:49:51 -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 8FCE1805A52F; Sat, 26 May 2018 14:49:50 +0000 (UTC) Received: from flask (unknown [10.43.2.80]) by smtp.corp.redhat.com (Postfix) with SMTP id C5F8C2166BB2; Sat, 26 May 2018 14:49:47 +0000 (UTC) Received: by flask (sSMTP sendmail emulation); Sat, 26 May 2018 16:49:47 +0200 Date: Sat, 26 May 2018 16:49:47 +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 v4 5/8] KVM: introduce kvm_make_vcpus_request_mask() API Message-ID: <20180526144946.GF23390@flask> References: <20180516152131.30689-1-vkuznets@redhat.com> <20180516152131.30689-6-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180516152131.30689-6-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.8]); Sat, 26 May 2018 14:49:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Sat, 26 May 2018 14:49:50 +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-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. > 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++)