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 X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83E99C04E53 for ; Wed, 15 May 2019 11:35:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 55E4B2053B for ; Wed, 15 May 2019 11:35:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557920111; bh=TfeV9x0G3bClf1sSiIdL3Y7ZNEIjop5onOLFdhNUwWQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=QKBbksfiEx+5K69pF0PxaFRKBQloQ2RYxYy5xxstg9I2XAC4sl/S/Lb8nSu2tHGwi DFFPN+mxKHD/48bWVwAV+Z+rRigqEQvbfdBfjNabarBsr13TKdfSB0J8cF0+HjftDG zMiumZf2akvo3o7hSPxIQfSn4/Jc3z+mY3vnpXBE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733245AbfEOLdm (ORCPT ); Wed, 15 May 2019 07:33:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:45646 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733241AbfEOLdl (ORCPT ); Wed, 15 May 2019 07:33:41 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 8AFCB206BF; Wed, 15 May 2019 11:33:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557920021; bh=TfeV9x0G3bClf1sSiIdL3Y7ZNEIjop5onOLFdhNUwWQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A/ffqB9U9PyZJzLl0e19bwEaa/nXB3owXEr7PTGy5FkoZnheg6AFqdHumwYlQdG5+ vo/GSclLAXUn+OADRM/aVysBVqkCbJ3yzYMPO1Px3gF4aMz5ZZdMBcPbY2PcPSeF5a gpK3agleG93dGUs6nNtQAKwYW555wfyOJs14FdQg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dexuan Cui , Lorenzo Pieralisi , Stephen Hemminger , Michael Kelley Subject: [PATCH 5.1 43/46] PCI: hv: Fix a memory leak in hv_eject_device_work() Date: Wed, 15 May 2019 12:57:07 +0200 Message-Id: <20190515090629.019359650@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090616.670410738@linuxfoundation.org> References: <20190515090616.670410738@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Dexuan Cui commit 05f151a73ec2b23ffbff706e5203e729a995cdc2 upstream. When a device is created in new_pcichild_device(), hpdev->refs is set to 2 (i.e. the initial value of 1 plus the get_pcichild()). When we hot remove the device from the host, in a Linux VM we first call hv_pci_eject_device(), which increases hpdev->refs by get_pcichild() and then schedules a work of hv_eject_device_work(), so hpdev->refs becomes 3 (let's ignore the paired get/put_pcichild() in other places). But in hv_eject_device_work(), currently we only call put_pcichild() twice, meaning the 'hpdev' struct can't be freed in put_pcichild(). Add one put_pcichild() to fix the memory leak. The device can also be removed when we run "rmmod pci-hyperv". On this path (hv_pci_remove() -> hv_pci_bus_exit() -> hv_pci_devices_present()), hpdev->refs is 2, and we do correctly call put_pcichild() twice in pci_devices_present_work(). Fixes: 4daace0d8ce8 ("PCI: hv: Add paravirtual PCI front-end for Microsoft Hyper-V VMs") Signed-off-by: Dexuan Cui [lorenzo.pieralisi@arm.com: commit log rework] Signed-off-by: Lorenzo Pieralisi Reviewed-by: Stephen Hemminger Reviewed-by: Michael Kelley Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/pci/controller/pci-hyperv.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -1900,6 +1900,9 @@ static void hv_eject_device_work(struct sizeof(*ejct_pkt), (unsigned long)&ctxt.pkt, VM_PKT_DATA_INBAND, 0); + /* For the get_pcichild() in hv_pci_eject_device() */ + put_pcichild(hpdev); + /* For the two refs got in new_pcichild_device() */ put_pcichild(hpdev); put_pcichild(hpdev); put_hvpcibus(hpdev->hbus);