Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932993AbdHVOTH (ORCPT ); Tue, 22 Aug 2017 10:19:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53426 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932510AbdHVOTF (ORCPT ); Tue, 22 Aug 2017 10:19:05 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7E46C37E68 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=david@redhat.com Subject: Re: [PATCH RFC v3 7/9] KVM: add kvm_free_vcpus and kvm_arch_free_vcpus To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-mips@linux-mips.org, kvm-ppc@vger.kernel.org, linux-s390@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Paolo Bonzini , Christoffer Dall , Marc Zyngier , Christian Borntraeger , Cornelia Huck , James Hogan , Paul Mackerras , Alexander Graf References: <20170821203530.9266-1-rkrcmar@redhat.com> <20170821203530.9266-8-rkrcmar@redhat.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <45e07499-e60c-5289-f439-9c51f59866ec@redhat.com> Date: Tue, 22 Aug 2017 16:18:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170821203530.9266-8-rkrcmar@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 22 Aug 2017 14:19:05 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1097 Lines: 54 > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 33a15e176927..0d2d8b0c785c 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -750,6 +750,23 @@ static void kvm_destroy_devices(struct kvm *kvm) > } > } > > +void kvm_free_vcpus(struct kvm *kvm) > +{ > + int i; > + > + kvm_arch_free_vcpus(kvm); I wonder if it would be possible to get rid of kvm_arch_free_vcpus(kvm) completely and simply call kvm_for_each_vcpu(i, vcpu, kvm) kvm_arch_vcpu_free(vcpu); at that point. Would certainly require some refactoring, and I am not sure if we could modify the special mmu handling for x86 ("Unpin any mmu pages first."). But if in doubt, that part could be moved to kvm_arch_destroy_vm(), just before calling kvm_free_vcpus(). > + > + mutex_lock(&kvm->lock); > + > + i = atomic_read(&kvm->online_vcpus); > + atomic_set(&kvm->online_vcpus, 0); i = atomic_xchg(&kvm->online_vcpus, 0); > + > + while (i--) > + kvm->vcpus[i] = NULL; > + > + mutex_unlock(&kvm->lock); > +} > + > static void kvm_destroy_vm(struct kvm *kvm) > { > int i; > -- Thanks, David