From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23334C433FE for ; Sat, 6 Nov 2021 11:17:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 038D3611AE for ; Sat, 6 Nov 2021 11:17:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234032AbhKFLUg (ORCPT ); Sat, 6 Nov 2021 07:20:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:34242 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbhKFLUc (ORCPT ); Sat, 6 Nov 2021 07:20:32 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BD2F160ED5; Sat, 6 Nov 2021 11:17:50 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mjJhk-003oLQ-Fj; Sat, 06 Nov 2021 11:17:48 +0000 Date: Sat, 06 Nov 2021 11:17:41 +0000 Message-ID: <87o86xednu.wl-maz@kernel.org> From: Marc Zyngier To: Sean Christopherson Cc: kvm@vger.kernel.org, linux-mips@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linuxppc-dev@lists.ozlabs.org, Huacai Chen , Aleksandar Markovic , Anup Patel , Atish Patra , Christian Borntraeger , Janosch Frank , David Hildenbrand , Claudio Imbrenda , Paolo Bonzini , Juergen Gross , Nicholas Piggin , Paul Mackerras , Michael Ellerman , James Morse , Suzuki K Poulose , Alexandru Elisei , kernel-team@android.com Subject: Re: [PATCH 1/5] KVM: Move wiping of the kvm->vcpus array to common code In-Reply-To: References: <20211105192101.3862492-1-maz@kernel.org> <20211105192101.3862492-2-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: seanjc@google.com, kvm@vger.kernel.org, linux-mips@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linuxppc-dev@lists.ozlabs.org, chenhuacai@kernel.org, aleksandar.qemu.devel@gmail.com, anup.patel@wdc.com, atish.patra@wdc.com, borntraeger@de.ibm.com, frankja@linux.ibm.com, david@redhat.com, imbrenda@linux.ibm.com, pbonzini@redhat.com, jgross@suse.com, npiggin@gmail.com, paulus@samba.org, mpe@ellerman.id.au, james.morse@arm.com, suzuki.poulose@arm.com, alexandru.elisei@arm.com, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Fri, 05 Nov 2021 20:12:12 +0000, Sean Christopherson wrote: > > On Fri, Nov 05, 2021, Marc Zyngier wrote: > > All architectures have similar loops iterating over the vcpus, > > freeing one vcpu at a time, and eventually wiping the reference > > off the vcpus array. They are also inconsistently taking > > the kvm->lock mutex when wiping the references from the array. > > ... > > > +void kvm_destroy_vcpus(struct kvm *kvm) > > +{ > > + unsigned int i; > > + struct kvm_vcpu *vcpu; > > + > > + kvm_for_each_vcpu(i, vcpu, kvm) > > + kvm_vcpu_destroy(vcpu); > > + > > + mutex_lock(&kvm->lock); > > But why is kvm->lock taken here? Unless I'm overlooking an arch, > everyone calls this from kvm_arch_destroy_vm(), in which case this > is the only remaining reference to @kvm. And if there's some magic > path for which that's not true, I don't see how it can possibly be > safe to call kvm_vcpu_destroy() without holding kvm->lock, or how > this would guarantee that all vCPUs have actually been destroyed > before nullifying the array. I asked myself the same question two years ago, and couldn't really understand the requirement. However, x86 does just that, so I preserved the behaviour. If you too believe that this is just wrong, I'm happy to drop the locking altogether. If that breaks someone's flow, they'll shout soon enough. Thanks, M. -- Without deviation from the norm, progress is not possible.