Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp874941pxk; Thu, 17 Sep 2020 20:00:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEiVBcTxyeZQzQY5frENXGBAZXtA2/9ZxB5uIdbr5KjHFUNxP9lPQbrawkkv08AU8Lx5fg X-Received: by 2002:a17:906:a444:: with SMTP id cb4mr33002536ejb.432.1600398017876; Thu, 17 Sep 2020 20:00:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398017; cv=none; d=google.com; s=arc-20160816; b=gNi6GIhfzJEd9fPfhvJy70ye69hfp1vEMC0a95TaBb4huGJ+P/ci9yS2jGNCoUup8j u2ZFPgnJUXISWBaTlxcgg4aQ4p/09uZb8486/I/OLbSg7T5cw+ujNtzjVuMpFJnfTyms x02LLnFarLUXVFtumXg39lfQXdcizb7EkRu7WW6dF3qH/MjP8SOlgfUwOxMJgaPeUeon 26Tf/XP4bDVPzsCE8vHA8HuwU3WXluohNlsOJ0bU96CWblaqb3sDFIlr6HDBw3X6rq9Y ajI/xUsTYDAdzlTr0hoQuN1Aih1AodbrqXfeBdewJeC9D0/xEgMYEe2o+Ood/BdDlgVp XTSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OdkYZNnPbbIx6NNSuBDugDF0Df9+cDy7fBFMX5SKadI=; b=VW195DNRNZAV54KsLm98NU7CYs0eotZiri3Shlyyh8VnhXpqd1Ny70thVC0I2VDV1C OiNlv70XOjHjStKU9TLLLobtQMPEVHkgj0DIBUyJDcOBSFuV6xNzftL6wuR/PWgn65Ym //MGhHcZwAr3PqA3qczz15WkaHyQbqek/2jcW6ZYyC4AtNMT2l8FyPqLlrwtI1qY11f6 eq5BFCpigDfGmcrPR43sUOuWNsNtCkiHSXec8YNE0qN4LhYtu3vigkuI9SkDSANKPxx9 SMftKxETVJRqw2WnfZeVKgE/SaUjU1BgaXPrC6l/5HeErtweaGwBXZslgq8jJlzCIPTY 3MFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ujtnk2tc; 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; 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 dn20si1465082ejc.196.2020.09.17.19.59.54; Thu, 17 Sep 2020 20:00:17 -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; dkim=pass header.i=@kernel.org header.s=default header.b=ujtnk2tc; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728036AbgIRCz7 (ORCPT + 99 others); Thu, 17 Sep 2020 22:55:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:57122 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727853AbgIRCHI (ORCPT ); Thu, 17 Sep 2020 22:07:08 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 685BC239D1; Fri, 18 Sep 2020 02:07:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394824; bh=l1+/pi1wfyY+JZMuC898nyPmlNyr9NkfUrvnHkUOExc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ujtnk2tcWrZAL6IXfl1Egi3UmNHAIWrLgkoPbv+VE4OlbvKHh7FE4avLsFv2S43SS i92e5kl9u/oN+IOT7HaFN8MwAt5gCderjGma+rNY1FBPOjOMqrNdbwpPrPqqEVGiQZ LSZO6OQDW7tILedF5nmqeuZxXnhKrSkC3U1rV9iQ= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Qian Cai , Alex Williamson , Sasha Levin , kvm@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 289/330] vfio/pci: fix memory leaks of eventfd ctx Date: Thu, 17 Sep 2020 22:00:29 -0400 Message-Id: <20200918020110.2063155-289-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qian Cai [ Upstream commit 1518ac272e789cae8c555d69951b032a275b7602 ] Finished a qemu-kvm (-device vfio-pci,host=0001:01:00.0) triggers a few memory leaks after a while because vfio_pci_set_ctx_trigger_single() calls eventfd_ctx_fdget() without the matching eventfd_ctx_put() later. Fix it by calling eventfd_ctx_put() for those memory in vfio_pci_release() before vfio_device_release(). unreferenced object 0xebff008981cc2b00 (size 128): comm "qemu-kvm", pid 4043, jiffies 4294994816 (age 9796.310s) hex dump (first 32 bytes): 01 00 00 00 6b 6b 6b 6b 00 00 00 00 ad 4e ad de ....kkkk.....N.. ff ff ff ff 6b 6b 6b 6b ff ff ff ff ff ff ff ff ....kkkk........ backtrace: [<00000000917e8f8d>] slab_post_alloc_hook+0x74/0x9c [<00000000df0f2aa2>] kmem_cache_alloc_trace+0x2b4/0x3d4 [<000000005fcec025>] do_eventfd+0x54/0x1ac [<0000000082791a69>] __arm64_sys_eventfd2+0x34/0x44 [<00000000b819758c>] do_el0_svc+0x128/0x1dc [<00000000b244e810>] el0_sync_handler+0xd0/0x268 [<00000000d495ef94>] el0_sync+0x164/0x180 unreferenced object 0x29ff008981cc4180 (size 128): comm "qemu-kvm", pid 4043, jiffies 4294994818 (age 9796.290s) hex dump (first 32 bytes): 01 00 00 00 6b 6b 6b 6b 00 00 00 00 ad 4e ad de ....kkkk.....N.. ff ff ff ff 6b 6b 6b 6b ff ff ff ff ff ff ff ff ....kkkk........ backtrace: [<00000000917e8f8d>] slab_post_alloc_hook+0x74/0x9c [<00000000df0f2aa2>] kmem_cache_alloc_trace+0x2b4/0x3d4 [<000000005fcec025>] do_eventfd+0x54/0x1ac [<0000000082791a69>] __arm64_sys_eventfd2+0x34/0x44 [<00000000b819758c>] do_el0_svc+0x128/0x1dc [<00000000b244e810>] el0_sync_handler+0xd0/0x268 [<00000000d495ef94>] el0_sync+0x164/0x180 Signed-off-by: Qian Cai Signed-off-by: Alex Williamson Signed-off-by: Sasha Levin --- drivers/vfio/pci/vfio_pci.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 0d16f9806655f..12f7691e8b6ca 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -474,6 +474,10 @@ static void vfio_pci_release(void *device_data) if (!(--vdev->refcnt)) { vfio_spapr_pci_eeh_release(vdev->pdev); vfio_pci_disable(vdev); + if (vdev->err_trigger) + eventfd_ctx_put(vdev->err_trigger); + if (vdev->req_trigger) + eventfd_ctx_put(vdev->req_trigger); } mutex_unlock(&vdev->reflck->lock); -- 2.25.1