Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4491973ybb; Tue, 14 Apr 2020 08:20:02 -0700 (PDT) X-Google-Smtp-Source: APiQypIT6nG5c4VzYa5tojUcbUS5NsXiAVSwS+VeVkx53t+VGF/yd++yIuw7Wj63U9Bp6/t0yyfx X-Received: by 2002:aa7:dc17:: with SMTP id b23mr20667887edu.321.1586877602736; Tue, 14 Apr 2020 08:20:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586877602; cv=none; d=google.com; s=arc-20160816; b=rgcW5dPjMwTbCX3H/kfVc2MlZy9aekGeDjQcxTSQHtNzrgq9YruWGiVIdW6tVHRo1j 3nRk726/hdO9Ljx5NyK/bjs0JNLcz0tkO68jYgdcHTK8yC1W2p92KOQJIgTNih9iJeqP TmZuOYK/uggbO3xgutxzDLeOE61WL6nqXFeVB3jIU4NNE1v7whLUr95CWecq2hqqM+Lc 3OqiCYb8Xe2PNgaDlv05znSzXH8e0xb8zJeBkHGlppFT8kAKI4ZziLPDwG+FuO8WZu+U UAR7NQ5yjwB2YUmsF51d+cgiGUuYT3W2787bVnDER/HJP00oTkha7LckiAyNcQjhdIbT VbNw== 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:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=j6esCYOYuN+dB49UA97pumkdoqYETVE3YMPTrSSqrrQ=; b=N7tjg1qdiJciceOsE1htgQX1k0XEP3ohMQH8bxAGtYh7RREo9yu2bB5QICuDUqJ7QH TVKxBI7wmdR7I8LQytcwfqdTC5ZrO9BWTUfTNR5hm9en9DlJXOLHaw1lTtEXNilfxHxS ZVtx1vJmCW6gceVkPZmHstzjrM1wT0hJOizRh+vH5JBukA5LMLPf4gppAlqcDEMSU0vx XLXx71Yw1qg+40kDIKvxHy3de1o/xTQTPJL6KsZ2fhU224yGheA9FKzWBvMHLpQDMTzB DLgflLWGuEjSAdcTWn+rtsBbqxMd3ShRk3p/Xsasq377J+XSDFyny/GyRBluGnHGClDi CjSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Fc/LMjA9"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z6si9364453edp.440.2020.04.14.08.19.38; Tue, 14 Apr 2020 08:20:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for 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; dkim=pass header.i=@kernel.org header.s=default header.b="Fc/LMjA9"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438671AbgDNKyp (ORCPT + 99 others); Tue, 14 Apr 2020 06:54:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:33118 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438668AbgDNKyY (ORCPT ); Tue, 14 Apr 2020 06:54:24 -0400 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 B89F5206D5; Tue, 14 Apr 2020 10:54:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586861660; bh=xFUIZbH4BsMb5b7OW+ZPT+Rdm2ffQ8mGwuPjUuQdWTQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Fc/LMjA9ksRxtgC05kP1DEhmyrhWWuxz0ZFh9ZoPsYbw1EHTL/8mPb9NocwA75h+t xNXeTRBParT4VdvVX1hzfdLEM9lyP6cCbxLOpORbZnYpL+JqedeJ3dfWJen18yaPE+ jup9HN8GQRTkR4FzVGqjCIneRQiwgLD0OhQjMxeQ= Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why) by disco-boy.misterjones.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jOJCs-0037HZ-SM; Tue, 14 Apr 2020 11:54:19 +0100 Date: Tue, 14 Apr 2020 11:54:17 +0100 From: Marc Zyngier To: Zenghui Yu Cc: , , , , , , , Subject: Re: [PATCH 1/2] KVM: arm64: vgic-v3: Retire all pending LPIs on vcpu destroy Message-ID: <20200414115417.451f8b66@why> In-Reply-To: <20200414030349.625-2-yuzenghui@huawei.com> References: <20200414030349.625-1-yuzenghui@huawei.com> <20200414030349.625-2-yuzenghui@huawei.com> Organization: Approximate X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: yuzenghui@huawei.com, kvmarm@lists.cs.columbia.edu, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, wanghaibin.wang@huawei.com, yezengruan@huawei.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > 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? Otherwise, looks good. If you agree with the above, I can fix that locally, no need to resend this patch. Thanks, M. -- Jazz is not dead. It just smells funny...