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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 000C3CD6E74 for ; Fri, 5 Jun 2026 07:48:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=FZVDInluTaIFvdMQJs+CfkcPbN0fYw+fpNJ0QFXGggI=; b=T+HBevtWZ10GiDqkbPW73bnIsu JWgoKYMIIVXxEsBbzFZiEKZsbGzUTL/vwqFXHWJhIA+R7nWX9Emsr3DWk4+kTcpgfDqWZAEPuy82o XujWVG1fbYj+tWfXH+B4jfKUdX/tnbPgT0rHiyiL5x3QeFE1iatjCY3Ns+su4YfkDAX5xvACLvBck aAFE2Sg2NAR2+HY+oUhWdtsdnDbU35fWzRj63y7BJWfsw8fNnCwvlpxYTF32uAj5t1mqcltmqxkrg tAaAIHU0HemzFmQBal0RNml46UXyaZpLt0PQnRHpqS/pfKqQsZLSChMiniTw1F9PAudhtsRuMmqRj u13y9RqQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wVPIG-00000000Fq0-0THt; Fri, 05 Jun 2026 07:48:40 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wVPIE-00000000FpX-34aK for linux-arm-kernel@lists.infradead.org; Fri, 05 Jun 2026 07:48:38 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id B920B600AA; Fri, 5 Jun 2026 07:48:37 +0000 (UTC) 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) 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 X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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.