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 9116BC433F5 for ; Thu, 25 Nov 2021 14:24:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=AwOsrV7pwFUNJvwUsoZ8baq0LNHTBtZXLjauPh4lcho=; b=DIa+2FBwSca1vD x0i5dc+UMcleYbbRg7VjfoLp8ryhZXlKKqcszYLF9j7l0TJi6ME1XPF37WPA23I1ylAFG6Q/WfpzA 2ws2KYWcCBeqVroxGamy8hC4ljetHhj8nhSBfCBfDGlbqPssr93I4UqpJfV8DjVvXzkkp49h8yR5R XMQ0cik/kyA/0Jho+QALPXy2P05yNJZdj3LSvxtBuLPT3MZILvmJ8HHqkmEhBIomTUtooFjJanjam iYdM2hj9+AVsQXPr4suyTD86mykozctzHdQAkLMdJ4ZTKzn/4115SLGpBkL9P002rU/27emYBzULX ffxTPn2s/Jni5hqQyVQA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqFeW-007o8c-MB; Thu, 25 Nov 2021 14:23:08 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqFeS-007o83-JR for linux-arm-kernel@lists.infradead.org; Thu, 25 Nov 2021 14:23:06 +0000 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 3D198610CA; Thu, 25 Nov 2021 14:23:04 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.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 1mqFeQ-007pBz-5g; Thu, 25 Nov 2021 14:23:02 +0000 Date: Thu, 25 Nov 2021 14:23:01 +0000 Message-ID: <877dcwco1m.wl-maz@kernel.org> From: Marc Zyngier To: Ganapatrao Kulkarni Cc: catalin.marinas@arm.com, will@kernel.org, andre.przywara@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, darren@os.amperecomputing.com, d.scott.phillips@amperecomputing.com Subject: Re: [PATCH 2/2] KVM: arm64: nv: fixup! Support multiple nested Stage-2 mmu structures In-Reply-To: <20211122095803.28943-3-gankulkarni@os.amperecomputing.com> References: <20211122095803.28943-1-gankulkarni@os.amperecomputing.com> <20211122095803.28943-3-gankulkarni@os.amperecomputing.com> 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") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: gankulkarni@os.amperecomputing.com, catalin.marinas@arm.com, will@kernel.org, andre.przywara@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, darren@os.amperecomputing.com, d.scott.phillips@amperecomputing.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211125_062304_705273_4F3D05D0 X-CRM114-Status: GOOD ( 26.39 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, 22 Nov 2021 09:58:03 +0000, Ganapatrao Kulkarni wrote: > > Commit 1776c91346b6 ("KVM: arm64: nv: Support multiple nested Stage-2 mmu > structures")[1] added a function kvm_vcpu_init_nested which expands the > stage-2 mmu structures array when ever a new vCPU is created. The array > is expanded using krealloc() and results in a stale mmu address pointer > in pgt->mmu. Adding a fix to update the pointer with the new address after > successful krealloc. > > [1] https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/ > branch kvm-arm64/nv-5.13 > > Signed-off-by: Ganapatrao Kulkarni > --- > arch/arm64/kvm/nested.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c > index 4ffbc14d0245..57ad8d8f4ee5 100644 > --- a/arch/arm64/kvm/nested.c > +++ b/arch/arm64/kvm/nested.c > @@ -68,6 +68,8 @@ int kvm_vcpu_init_nested(struct kvm_vcpu *vcpu) > num_mmus * sizeof(*kvm->arch.nested_mmus), > GFP_KERNEL | __GFP_ZERO); > if (tmp) { > + int i; > + > if (kvm_init_stage2_mmu(kvm, &tmp[num_mmus - 1]) || > kvm_init_stage2_mmu(kvm, &tmp[num_mmus - 2])) { > kvm_free_stage2_pgd(&tmp[num_mmus - 1]); > @@ -80,6 +82,13 @@ int kvm_vcpu_init_nested(struct kvm_vcpu *vcpu) > } > > kvm->arch.nested_mmus = tmp; > + > + /* Fixup pgt->mmu after krealloc */ > + for (i = 0; i < kvm->arch.nested_mmus_size; i++) { > + struct kvm_s2_mmu *mmu = &kvm->arch.nested_mmus[i]; > + > + mmu->pgt->mmu = mmu; > + } > } > > mutex_unlock(&kvm->lock); Another good catch. I've tweaked a bit to avoid some unnecessary repainting, see below. Thanks again, M. diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c index a4dfffa1dae0..92b225db59ac 100644 --- a/arch/arm64/kvm/nested.c +++ b/arch/arm64/kvm/nested.c @@ -66,8 +66,19 @@ int kvm_vcpu_init_nested(struct kvm_vcpu *vcpu) num_mmus = atomic_read(&kvm->online_vcpus) * 2; tmp = krealloc(kvm->arch.nested_mmus, num_mmus * sizeof(*kvm->arch.nested_mmus), - GFP_KERNEL | __GFP_ZERO); + GFP_KERNEL_ACCOUNT | __GFP_ZERO); if (tmp) { + /* + * If we went through a realocation, adjust the MMU + * back-pointers in the pg_table structures. + */ + if (kvm->arch.nested_mmus != tmp) { + int i; + + for (i = 0; i < num_mms - 2; i++) + tmp[i].pgt->mmu = &tmp[i]; + } + if (kvm_init_stage2_mmu(kvm, &tmp[num_mmus - 1]) || kvm_init_stage2_mmu(kvm, &tmp[num_mmus - 2])) { kvm_free_stage2_pgd(&tmp[num_mmus - 1]); -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel