From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCE45472782 for ; Fri, 5 Jun 2026 07:48:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780645718; cv=none; b=WZWqNVFrW3pN+D/0OD4cPycuGNdOhuE7fhz5X/Y6iKCUkKUI4HMRK36NPv0LHMuat4zALsirflZmxMgKGrpzwE095KFBLb/ZqFBqeN3/MmI51IWJh5r0RF2ngUh5xL2eBGV0neSMlWwdPFEWwSptxbLGQ+2U7diXtdAKozQoBHg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780645718; c=relaxed/simple; bh=+fc9tgvYeC5BnpjsbzaoII2wEO5RWwQvQFxWYC7MxDE=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=h+5sLhnS+XSTcNipsY5h+TJFqsf0iCTP/RW9SWOD68lsbDhUncSO01MgWelZss8/01usbqNWajSEIt+rdSNtyWvo1UWlI31I9Zs+uj4NvmoCgbL+d/+jVhWXNS8ExPvrBiyyt3q9doT0/KWFXtRojh+Q1QRGugWvUXUG56di+hA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JNCVOusd; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JNCVOusd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C2201F00893; Fri, 5 Jun 2026 07:48:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780645717; bh=FZVDInluTaIFvdMQJs+CfkcPbN0fYw+fpNJ0QFXGggI=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=JNCVOusd8jyIc13IH7WKkfEk6t1xywT9EiJYqjlr8Q/On9JaG++34BP+NUbp5KwHg kD4dzS1MkMMx0zLHYruyz8S45U9VLyhmtYIpEthV4o1BOlStrNb+DE4HGnomyl5kOF XgAH8svOuJ6q2Kkotyjdi2Xj4MAIoAZDdzG1jkRT9SJL1K21Voj5wAZ/q/ly9gWL8L GFo2jS1hVfG0qWb/CCYD9WdJGe+00gH7lgJUKkK+82r1WwkhXamdftdBLJGXrQ7UOr dpkTfAjwSt/perK9Yz6QK614LQt2EGqmWWCp62jWGQtrsPiq6fpAMM9B6espwnbyDK mh36QibAAZIhw== Received: from sofa.misterjones.org ([185.219.108.64] helo=lobster-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wVPIB-00000009g0G-1WzI; Fri, 05 Jun 2026 07:48:35 +0000 Date: Fri, 05 Jun 2026 08:51:54 +0100 Message-ID: <87cxy5a0h1.wl-maz@kernel.org> From: Marc Zyngier To: Hyunwoo Kim Cc: Oliver Upton , joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, christoffer.dall@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev Subject: Re: [PATCH] KVM: arm64: Reallocate the nested_mmus array under the mmu_lock In-Reply-To: References: 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/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: 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: imv4bel@gmail.com, oupton@kernel.org, joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, christoffer.dall@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Fri, 05 Jun 2026 06:35:20 +0100, Hyunwoo Kim wrote: > > On Thu, Jun 04, 2026 at 03:27:16PM -0700, Oliver Upton wrote: > > Hi, > > > > The shortlog is very confusing, since "allocate behind $LOCK" is usually > > something alarming. Maybe instead: > > > > KVM: arm64: Reassign nested_mmus array behind mmu_lock > > heh, that's confusing indeed. I'll change it that way. > > > > > On Fri, Jun 05, 2026 at 03:30:00AM +0900, Hyunwoo Kim wrote: > > > Code that walks kvm->arch.nested_mmus[] holds kvm->mmu_lock. By contrast, > > > kvm_vcpu_init_nested() reallocates the array and frees the old buffer while > > > holding only kvm->arch.config_lock, so a walker can reference the freed > > > array. > > > > It wouldn't hurt to share slightly more information here. Are you > > dealing with a concurrent MMU notifier? > > Yes. The MMU notifier path also walks nested_mmus[] under mmu_lock. > kvm_vcpu_init_nested() holds only config_lock, so if a notifier fires > during vCPU init, it races with the array realloc and free. > > Here's the reworked changelog. Should I send v2? > > kvm->arch.nested_mmus[] is walked under kvm->mmu_lock, including from the > MMU notifier path (kvm_unmap_gfn_range() -> kvm_nested_s2_unmap()), which > can run at any time. kvm_vcpu_init_nested() reallocates the array and frees > the old buffer while holding only kvm->arch.config_lock, so such a walker > can reference the freed array. > > Allocate the new array outside of mmu_lock, as the allocation can sleep. > Under the lock, copy the existing entries, fix up the back pointers and > reassign the array. Free the old buffer after dropping the lock, as > kvfree() can sleep as well. That's significantly better. Please send a v2 with this. Thanks, M. -- Jazz isn't dead. It just smells funny.