Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp11034ybm; Mon, 20 May 2019 10:58:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqzlzc8cFPSiuvHP3zC4gCc+fp8wmonCv7XqzWDEcWQIbHam1Hgx1brFCiGgIymB4s6vx56G X-Received: by 2002:a17:902:848c:: with SMTP id c12mr27958439plo.17.1558375117864; Mon, 20 May 2019 10:58:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558375117; cv=none; d=google.com; s=arc-20160816; b=dCw4zPm1j7AcVwiw71rfN5MN0C5c5ctNPWrtiQPBCxVDY/Y8bgXZeaVrKMiWn+3ffE QObm/Kr+JYD+WNt9cX+cGli+0qaKFprBUQpADef3wZsNHLXhvymaATVI7KiBaDbRfYr8 ty/Yny8E0tb36b1wKfAQyDl1vXriKsbYj5gULUzzzYmngsFI0TcMn7uSNQbikhW6FFKL 4RhoAiANgN4R4x4gv/drXPpcvJtGvsem8JFLpBjfgp5PoadhGt+L8VJqPWp1xjUmGOhM XvUBEDWWz42fe2lnmd7BgArpEtn0incgqwZj+ZAB69lVvg8U8WyA+UDns9ttzfEM47og W30w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wuewUbXpFIsWb1lJz/Jw4qVbY2oTAM9Hz9oylGxAtSY=; b=Ia+04AJovK3eXqRb7ekww+vJg20QoymzUqEYwUzJujiSZ1b2V6V0U7987ck9ZKh/iO IOzkEmH1Gy0tpHSSrs4ZOzS4+MrFHmcL0Uu0frIVVha39QOcT4/Z0outh1fkfC/6D24Q pC1k1OmpwfO1Rywjb7yaYxIrQ4TdtTJZyaVQboCHisjdUcab0ZpHVC2nMMJcRkrCdy8p bwPhX/4Kacqs3yPI5BvA3vzWG/vN6D94OeTHjb6C8da1I5yW9dB5FBuZKYXyjACBcK2A 73FuZnYT104JPUF6tVQO80JqnSUb94Jjm5d6pAU9HyvtF7jiNpPq/sgqJ4hiBQgqEbPR Dn9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VQBg8SsL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x19si20347496pfr.226.2019.05.20.10.58.23; Mon, 20 May 2019 10:58:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VQBg8SsL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391505AbfETMwr (ORCPT + 99 others); Mon, 20 May 2019 08:52:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:59636 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730819AbfETMSb (ORCPT ); Mon, 20 May 2019 08:18:31 -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 CA1E5208C3; Mon, 20 May 2019 12:18:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558354711; bh=g+JruYIfqgO+BWwlMhcvFwYfPn/bYDmBg8KUOWPJY0U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VQBg8SsLq9XnMbpX5rzaeX/1XhunP+0QEyVP/8WbnoM6dVwA9XZQ7i9QoMnlyJsoR Uwrvnfv40Gbv0G6EZHpzFbK6M+in6cVf1y/muZQC5nePyMgalmhxJgs8jSsU9sIgf7 xBxtGtkZVq5SP+5dL3Db3NXFnB+eCB2WvP+NLJmA= 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 , Sasha Levin Subject: [PATCH 4.14 03/63] PCI: hv: Fix a memory leak in hv_eject_device_work() Date: Mon, 20 May 2019 14:13:42 +0200 Message-Id: <20190520115231.555170179@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115231.137981521@linuxfoundation.org> References: <20190520115231.137981521@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 05f151a73ec2b23ffbff706e5203e729a995cdc2 ] 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: Sasha Levin --- drivers/pci/host/pci-hyperv.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c index 53d1c08cef4dc..292450c7da625 100644 --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -1941,6 +1941,7 @@ static void hv_eject_device_work(struct work_struct *work) VM_PKT_DATA_INBAND, 0); put_pcichild(hpdev, hv_pcidev_ref_childlist); + put_pcichild(hpdev, hv_pcidev_ref_initial); put_pcichild(hpdev, hv_pcidev_ref_pnp); put_hvpcibus(hpdev->hbus); } -- 2.20.1