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 8B8F1CE8347 for ; Mon, 30 Sep 2024 14:22:22 +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=QU4kdPQtZW4F/7AzLo8ONIB23WBGGREtf50GqIhG/3A=; b=PRRXW2xhMfC79/ADFXBsqKHJoI DJaw4qRZhamYXXXhrZIfAN/BP54KqKoDY+4PUERhXFrC+OekwZre46CMebHo8kEbgrhZeDWi5QI7Q RCo/1sbX+ae/umdXgE4l+T3qZMqjrFSLXalBVzcsXh5eYhuHXuHV0QY6J6v9/XM/i/Haef94pwUmH yXAG9+gndlnUYjYoJvx74o6dLCvysudK+SEzd9GBPVrFA2RLu6S2Lds85/lJSGOCtm1ADWA/NOoNM MYi2asuxOxSi3Lox4k4+Z1Nl43LMu1JuUf7r4TQnJId3czQ6RH+z1za+2Sh4p0Q9B3hlH8KsX2YEv Ey1ri4aQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1svHHw-0000000HUv1-2gQg; Mon, 30 Sep 2024 14:22:12 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1svH65-0000000HSK8-1D6U for linux-arm-kernel@lists.infradead.org; Mon, 30 Sep 2024 14:09:58 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 465EB5C24D5; Mon, 30 Sep 2024 14:09:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 006A6C4CEC7; Mon, 30 Sep 2024 14:09:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727705396; bh=xIhCwLT+5EuwEo8Tx2twzWVA1JnCXRa20LyD9fiNNbc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=QMUrGcjT8u1xHeMCd4YfZ6ABDuxEekUa41X3lkhxpZXJKvdMWdx/EhFqTPi9C48MI 1fw4+26PN/lGuQpcQprKEtN2LpVWYbsmCc6aEQAbKVcGtR90WzOauxihPSKNs1y904 4afBWZ0NpSEfZvF6tSj8rMFQXdJIz3tvhRYcQFVPOat8s+P5I+RrMv2MU1A3hdorNB o5fh8TCHbb+0bfd9Wbbva3aWBiy6YAPyoUjJduczFr14f6xzShO3rLChkubU1Qyxeq b1ymorqhjFUkZ2Qd+zDfp7q7+stHqT6gUI8uvnqU2AozotFUmoYd3C6HaAk4h5cvIJ c2ZoVav5hMDlA== Received: from [12.191.124.166] (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.95) (envelope-from ) id 1svH61-00GStE-KD; Mon, 30 Sep 2024 15:09:54 +0100 Date: Mon, 30 Sep 2024 15:09:48 +0100 Message-ID: <87r091utar.wl-maz@kernel.org> From: Marc Zyngier To: Kunkun Jiang Cc: Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , , , , , Subject: Re: [bug report] KVM: arm64: vgic-v4: Occasionally issue VMOVP to an unmapped VPE on GICv4.1 In-Reply-To: <5ea32d67-f429-acfb-c6d4-06c7860146e2@huawei.com> References: <87ttdyvklx.wl-maz@kernel.org> <5ea32d67-f429-acfb-c6d4-06c7860146e2@huawei.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/29.4 (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: 12.191.124.166 X-SA-Exim-Rcpt-To: jiangkunkun@huawei.com, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, wanghaibin.wang@huawei.com, tangnianyao@huawei.com, wangzhou1@hisilicon.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-20240930_070957_437685_23A66497 X-CRM114-Status: GOOD ( 32.32 ) 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 Mon, 30 Sep 2024 07:25:28 +0100, Kunkun Jiang wrote: > > Hi Marc, > > On 2024/9/29 18:07, Marc Zyngier wrote: > > On Sun, 29 Sep 2024 08:18:41 +0100, > > Kunkun Jiang wrote: > >> > >> Hi all, > >> > >> I found a problem with occasionally issuing VMOVP to an unmapped VPE > >> on GICv4.1. In my test environment, operating an unmapped VPE will > >> generate RAS, so I found this problem. The detailed analysis is as > >> follows. > >> > >> The vgic_v4_teardown() will be executed when VM is destroyed to free > >> the GICv4 data structures. The code is as follows: > >>> /** > >>> * vgic_v4_teardown - Free the GICv4 data structures > >>> * @kvm: Pointer to the VM being destroyed > >>> */ > >>> void vgic_v4_teardown(struct kvm *kvm) > >>> { > >>> struct its_vm *its_vm = &kvm->arch.vgic.its_vm; > >>> int i; > >>> > >>> lockdep_assert_held(&kvm->arch.config_lock); > >>> > >>> if (!its_vm->vpes) > >>> return; > >>> > >>> for (i = 0; i < its_vm->nr_vpes; i++) { > >>> struct kvm_vcpu *vcpu = kvm_get_vcpu(kvm, i); > >>> int irq = its_vm->vpes[i]->irq; > >>> > >>> irq_clear_status_flags(irq, DB_IRQ_FLAGS); > >>> free_irq(irq, vcpu); > >>> } > >>> > >>> its_free_vcpu_irqs(its_vm); > >>> kfree(its_vm->vpes); > >>> its_vm->nr_vpes = 0; > >>> its_vm->vpes = NULL; > >>> } > >> > >> [1] In irq_clear_status_flags(irq, DB_IRQ_FLAGS), the status flags of > >> a doorbell are cleared. DB_IRQ_FLAGS contains IRQ_NO_BALANCING. So > >> after this,the irqbalance.service can schedule the doorbell. > >> [2] In free_irq(), the VPE is unmaped. > >> [3] In its_free_vcpu_irqs(its_vm), unregister_irq_proc() is called to > >> delete the contents in /proc/irq/xx/ of the doorbell. > >> > >> For VPEs in large-scale VM, there is a centain time window between [2] > >> and [3]. The irqbalance.service got a chance to schedule the > >> doorbell. Therefore, the VMOVP is issued to an unmapped VPE. > >> > >> I tried not clearing IRQ_NO_BALANCING and the problem was solved. But > >> it's not clear if there's any other problem with doing so. > > > > I don't think that's a good idea, because whoever request the same > > interrupt number again for a different purpose will have the flag set > > and will experience odd behaviours. > > > > I'd rather fix it for good, given that we have all the necessary > > tracking in place already. Something like the patch below, as usual > > untested. > > After testing, the patch below fixes my problem. Thanks. But it also introduces a regression on GICv4.0, which doesn't use vmapp_count. So the fix is slightly more involved. I'll try to post a more complete patch later this week. M. -- Without deviation from the norm, progress is not possible.