Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2137324imm; Wed, 16 May 2018 08:25:25 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrLejwKqgD9AqUYA+JaWPTt6pDN+2giUGj/VZ8bnznm8kUJWf/ACvf4DWOje9MGXzHTf3ov X-Received: by 2002:a63:6443:: with SMTP id y64-v6mr1102647pgb.68.1526484325273; Wed, 16 May 2018 08:25:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526484325; cv=none; d=google.com; s=arc-20160816; b=KU8egvvbss+7aNEED9iVNS66IkBeVRiCJX7lz0AJ166hZiZMKRHVrYwB6cKet1up3O 20CTq3sX/M+eBDTNd6ehnk0o5wq4gToew8B5zK+x3bzvJpdNPwDs6xbPwpWDpsD2nqxi FgOXms1uZB5dgWkmI2S7AmoiLaLihEA8+MUwCRY+OM2yl2n5hQpmSOIcNdMdUVfF7SQE dnBFf5303+ZRreAf6EnXgljcRNmQpAgCvuaZS6XDhZ4JuqdmP4L9Fo8V8Lein7idt96/ kw7r+phubzFtv9ZUr/s5bca0ttVPKy3ljumcXuieJBb5vhH/VvGA+/JbplIfJggj6zVB CgxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=KYJIvHSH6vHyKrmK6O1XcM53J4ZOL/asbeyAmooPjAw=; b=Ynt+AU26MYwTz3qRcqF2Lr/PL8i2Yjl2HS9Do2EHddy0SquBpbU8QURy9igwpoqO1C wH8lebz+nyH9OuRSClnbGF5bLntotHGMa/6f+oRwdzBq2X4BawzjtmUHmTIctqwAH024 aPY3WfQKI0d71xH4cJOZTNK9uX74exLIZ70z/fheFFDjaaKJpR1+6KA/KvLAPUJbhjYM 4XOnbOvhHRLHFK12HFuTmbKcHH1D6tFuw4co3zcLSwzrXsWH9uhHBWwBcGhYYWLMQxtT p7+CtoCkbT9p51QPmCN0zjafjyv5srOvXF+S4cNDk/9wE60ru3dt4S83Dp+Y+w2Pmz5u REwA== 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 ay10-v6si2791710plb.120.2018.05.16.08.25.05; Wed, 16 May 2018 08:25:25 -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 S1752162AbeEPPXw (ORCPT + 99 others); Wed, 16 May 2018 11:23:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49622 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752038AbeEPPVp (ORCPT ); Wed, 16 May 2018 11:21:45 -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 C2591BB404; Wed, 16 May 2018 15:21:44 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id E9BD8215CDA7; Wed, 16 May 2018 15:21:42 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org Cc: x86@kernel.org, Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Roman Kagan , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , "Michael Kelley (EOSG)" , Mohammed Gamal , Cathy Avery , linux-kernel@vger.kernel.org Subject: [PATCH v4 5/8] KVM: introduce kvm_make_vcpus_request_mask() API Date: Wed, 16 May 2018 17:21:28 +0200 Message-Id: <20180516152131.30689-6-vkuznets@redhat.com> In-Reply-To: <20180516152131.30689-1-vkuznets@redhat.com> References: <20180516152131.30689-1-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.1]); Wed, 16 May 2018 15:21:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 16 May 2018 15:21:44 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 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 --- include/linux/kvm_host.h | 3 +++ virt/kvm/kvm_main.c | 34 ++++++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 6d6e79c59e68..14e710d639c7 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -730,6 +730,9 @@ void kvm_put_guest_fpu(struct kvm_vcpu *vcpu); void kvm_flush_remote_tlbs(struct kvm *kvm); void kvm_reload_remote_mmus(struct kvm *kvm); + +bool kvm_make_vcpus_request_mask(struct kvm *kvm, unsigned int req, + unsigned long *vcpu_bitmap, cpumask_var_t tmp); bool kvm_make_all_cpus_request(struct kvm *kvm, unsigned int req); long kvm_arch_dev_ioctl(struct file *filp, diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index c7b2e927f699..b125d94307d2 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -203,29 +203,47 @@ static inline bool kvm_kick_many_cpus(const struct cpumask *cpus, bool wait) return true; } -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(); + kvm_for_each_vcpu(i, vcpu, kvm) { + if (!test_bit(i, vcpu_bitmap)) + continue; + kvm_make_request(req, vcpu); cpu = vcpu->cpu; if (!(req & KVM_REQUEST_NO_WAKEUP) && kvm_vcpu_wake_up(vcpu)) continue; - if (cpus != NULL && cpu != -1 && cpu != me && + if (tmp != NULL && cpu != -1 && cpu != me && kvm_request_needs_ipi(vcpu, req)) - __cpumask_set_cpu(cpu, cpus); + __cpumask_set_cpu(cpu, tmp); } - called = kvm_kick_many_cpus(cpus, !!(req & KVM_REQUEST_WAIT)); + + called = kvm_kick_many_cpus(tmp, !!(req & KVM_REQUEST_WAIT)); put_cpu(); + + return called; +} + +bool kvm_make_all_cpus_request(struct kvm *kvm, unsigned int req) +{ + cpumask_var_t cpus; + bool called; + static unsigned long vcpu_bitmap[BITS_TO_LONGS(KVM_MAX_VCPUS)] + = {[0 ... BITS_TO_LONGS(KVM_MAX_VCPUS)-1] = ULONG_MAX}; + + zalloc_cpumask_var(&cpus, GFP_ATOMIC); + + called = kvm_make_vcpus_request_mask(kvm, req, vcpu_bitmap, cpus); + free_cpumask_var(cpus); return called; } -- 2.14.3