Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp578251ybz; Wed, 15 Apr 2020 14:25:20 -0700 (PDT) X-Google-Smtp-Source: APiQypIMO0hwNYzeLG8S0LsxFTHVGpsEPb0/crKWFkmlMVnYGNG3V+BB4UmLtodnTr3diWNDcFgd X-Received: by 2002:a17:906:2410:: with SMTP id z16mr6908789eja.1.1586985920614; Wed, 15 Apr 2020 14:25:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586985920; cv=none; d=google.com; s=arc-20160816; b=QNIDJLe3kBXzY60wCqZaboggc+l8N/CxO1JBdHkfCAqlteQNGdfuE7p7QvTtirMO0h gv4e6UzJwWJpq5jj+bMV2Pdz7sv6M37nuk0pbP8jRYVfWUkuM/jVa2oyLiSTdM8IedDe I5chRuhLysDuFL4Id0HAPpShR8EIGKOCEFlvugAd9EupjPrVY1pe/py1cX3+tFxe4Y56 6BQOresiNP13K5Zv8EJlkc8v3+QCI96yQifxX5cLLTtb3YAj0SaSEk8tq4HFee95SU9S Y2eE6gpYYQ1sGlbSyLZoVXBQjxH7v71r0Y2raMGg0uZseFRBVU4XGCDAAzMORX3JB/Eg D8QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=jeFUK8ZaAd57b4Agy2SbLpUrBc+1PKDmHzTr6q0c7TY=; b=vnpy890BAb+NYPrtBLv5W2SQVVmbdd3gf76JvCYPzPCuL910PO9qanJKv2TID3WCWi aACed4bDSxjE2rLfI2D0C7BgectMfAIi4sOKleZrK6vtpWvvq+N+VXgqBJAB6hi21b1W JtbMBSIN7P7Hkm/oIEAzbxr8vxjIA7rORFGRdFBefbhLB4QKZfogoF4YbADl48YjZTUM +LpSBIoO1U6YIMEQZ9SoYN+5xTw8yZovHb7D/DxCmgiGWD6zoq8hCRqwVKB2CzFcX0Zb IxIKTJPsB9AGq/GSmH4ins0UHUE7b9NcflbcNzDCGsGQym9A/DvOO80ONjHF8vNlTYI4 wrWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a6si11260143edr.242.2020.04.15.14.24.57; Wed, 15 Apr 2020 14:25:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439001AbgDNLSV (ORCPT + 99 others); Tue, 14 Apr 2020 07:18:21 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2370 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2438988AbgDNLSD (ORCPT ); Tue, 14 Apr 2020 07:18:03 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 1D8E5BC680AC97D09CAD; Tue, 14 Apr 2020 19:17:58 +0800 (CST) Received: from [127.0.0.1] (10.173.222.27) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Tue, 14 Apr 2020 19:17:50 +0800 Subject: Re: [PATCH 1/2] KVM: arm64: vgic-v3: Retire all pending LPIs on vcpu destroy To: Marc Zyngier CC: , , , , , , , References: <20200414030349.625-1-yuzenghui@huawei.com> <20200414030349.625-2-yuzenghui@huawei.com> <20200414115417.451f8b66@why> From: Zenghui Yu Message-ID: Date: Tue, 14 Apr 2020 19:17:49 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0 MIME-Version: 1.0 In-Reply-To: <20200414115417.451f8b66@why> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.173.222.27] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Marc, On 2020/4/14 18:54, Marc Zyngier wrote: > On Tue, 14 Apr 2020 11:03:47 +0800 > Zenghui Yu wrote: > > Hi Zenghui, > >> It's likely that the vcpu fails to handle all virtual interrupts if >> userspace decides to destroy it, leaving the pending ones stay in the >> ap_list. If the un-handled one is a LPI, its vgic_irq structure will >> be eventually leaked because of an extra refcount increment in >> vgic_queue_irq_unlock(). >> >> This was detected by kmemleak on almost every guest destroy, the >> backtrace is as follows: >> >> unreferenced object 0xffff80725aed5500 (size 128): >> comm "CPU 5/KVM", pid 40711, jiffies 4298024754 (age 166366.512s) >> hex dump (first 32 bytes): >> 00 00 00 00 00 00 00 00 08 01 a9 73 6d 80 ff ff ...........sm... >> c8 61 ee a9 00 20 ff ff 28 1e 55 81 6c 80 ff ff .a... ..(.U.l... >> backtrace: >> [<000000004bcaa122>] kmem_cache_alloc_trace+0x2dc/0x418 >> [<0000000069c7dabb>] vgic_add_lpi+0x88/0x418 >> [<00000000bfefd5c5>] vgic_its_cmd_handle_mapi+0x4dc/0x588 >> [<00000000cf993975>] vgic_its_process_commands.part.5+0x484/0x1198 >> [<000000004bd3f8e3>] vgic_its_process_commands+0x50/0x80 >> [<00000000b9a65b2b>] vgic_mmio_write_its_cwriter+0xac/0x108 >> [<0000000009641ebb>] dispatch_mmio_write+0xd0/0x188 >> [<000000008f79d288>] __kvm_io_bus_write+0x134/0x240 >> [<00000000882f39ac>] kvm_io_bus_write+0xe0/0x150 >> [<0000000078197602>] io_mem_abort+0x484/0x7b8 >> [<0000000060954e3c>] kvm_handle_guest_abort+0x4cc/0xa58 >> [<00000000e0d0cd65>] handle_exit+0x24c/0x770 >> [<00000000b44a7fad>] kvm_arch_vcpu_ioctl_run+0x460/0x1988 >> [<0000000025fb897c>] kvm_vcpu_ioctl+0x4f8/0xee0 >> [<000000003271e317>] do_vfs_ioctl+0x160/0xcd8 >> [<00000000e7f39607>] ksys_ioctl+0x98/0xd8 >> >> Fix it by retiring all pending LPIs in the ap_list on the destroy path. >> >> p.s. I can also reproduce it on a normal guest shutdown. It is because >> userspace still send LPIs to vcpu (through KVM_SIGNAL_MSI ioctl) while >> the guest is being shutdown and unable to handle it. A little strange >> though and haven't dig further... > > What userspace are you using? You'd hope that the VMM would stop > processing I/Os when destroying the guest. But we still need to handle > it anyway, and I thing this fix makes sense. I'm using Qemu (master) for debugging. Looks like an interrupt corresponding to a virtio device configuration change, triggered after all other devices had freed their irqs. Not sure if it's expected. >> >> Signed-off-by: Zenghui Yu >> --- >> virt/kvm/arm/vgic/vgic-init.c | 6 ++++++ >> 1 file changed, 6 insertions(+) >> >> diff --git a/virt/kvm/arm/vgic/vgic-init.c b/virt/kvm/arm/vgic/vgic-init.c >> index a963b9d766b7..53ec9b9d9bc4 100644 >> --- a/virt/kvm/arm/vgic/vgic-init.c >> +++ b/virt/kvm/arm/vgic/vgic-init.c >> @@ -348,6 +348,12 @@ void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu) >> { >> struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; >> >> + /* >> + * Retire all pending LPIs on this vcpu anyway as we're >> + * going to destroy it. >> + */ >> + vgic_flush_pending_lpis(vcpu); >> + >> INIT_LIST_HEAD(&vgic_cpu->ap_list_head); >> } >> > > I guess that at this stage, the INIT_LIST_HEAD() is superfluous, right? I was just thinking that the ap_list_head may not be empty (besides LPI, with other active or pending interrupts), so leave it unchanged. > Otherwise, looks good. If you agree with the above, I can fix that > locally, no need to resend this patch. Thanks, Zenghui