Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5991364ybc; Wed, 27 Nov 2019 13:02:32 -0800 (PST) X-Google-Smtp-Source: APXvYqxPYqTK7wxp21USDOfVw+xAFSmHHqMBZ1NYgzByGcGez+Tdk+NMOHSzgU/Pu3Nh+XwOg5d5 X-Received: by 2002:a17:906:1cc7:: with SMTP id i7mr49305195ejh.172.1574888551951; Wed, 27 Nov 2019 13:02:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574888551; cv=none; d=google.com; s=arc-20160816; b=CXdlgpDuZk85BH75nN47k0MmTLf+YmdmDLQDgC8w0oOupWHlD/UvcyNoCWGslAa9TU nXURelZ6EE2U/mkk8N2GizwLCfVV/bcN7AXqvi/WTcLovvOlZ2z3/8jIkPzwTqxkxwx2 V3PZ1l+YpPmUduG1gWNdl0hlYnXkH29c224J+xjolnGb+729S5Qz8UMduyAvUkywSBg7 ka/xXfdTr3R9IupbtxLe9X7itQ6x0IUtDo2YOzIELmn2rOnK47VY0Je7VWks6snRRwRC QZ18HkkOi2LgC+DtJefYMCGEsqYe2rqzJ/KkUqD6mNm8F6Q+FJca8XK7RuVBka9qmzCf QUnw== 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=agZ44xVXGQXXiVYHQeMwsDKwSGUwpmCU91eVI/zL+EU=; b=X8RXuXVelHlSYZfnRUhZNuUzlCrGDRd50wzbmdyNlPBjr9jGVwF3QO+P+uE1CqP4SP ELqlHkqAel/I14hX11IqLLplKdwfORHIXRHN2eSrejfu+fDz8ipnizlVX2D6j2YcZwpo 3FkG5CwyOT7fJ2lVGnA0mnHl6M1Z8MPZ+qEHCJEy7Lrdw2GVnKVw75Kntx9ClAY7bBl1 a5rQ+2VctKQVwGmTOVtNn9qUpsyf1qHv8Mft1/b3HVO6bpMognyPaQ6aOmb3J1vqIpkI JJLbHAy8gsXnthqLe5q36+deQCWaiY+DAch/d4fKxUdKbUXRYQUJZoWXJE++3d8PIiQe wmAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yIf0qjIO; 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 l36si11803321edc.272.2019.11.27.13.02.08; Wed, 27 Nov 2019 13:02:31 -0800 (PST) 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=yIf0qjIO; 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 S1731388AbfK0U7L (ORCPT + 99 others); Wed, 27 Nov 2019 15:59:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:50516 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731376AbfK0U7D (ORCPT ); Wed, 27 Nov 2019 15:59:03 -0500 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 5A2B820862; Wed, 27 Nov 2019 20:59:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888342; bh=omppKKnMzlwMUO/lGjPYMr5FWF7KOGGvHMhEJD4Ko/A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yIf0qjIOvHEelswmeytunDtWuOSL6ur/3J/ZvU6oE00um1Xt8HYyndlus41IhCV56 567dR3glo+AvkMPX1Xavq3WjOLGREGerN768CN4HhLX4XehGn0snTSl4K/eL9itpXW S68JcOvi1SSjRwFB8di+mU17FWBHUWTp0/nefeOw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jon Derrick , Lorenzo Pieralisi , Keith Busch , Sasha Levin Subject: [PATCH 4.19 095/306] PCI: vmd: Detach resources after stopping root bus Date: Wed, 27 Nov 2019 21:29:05 +0100 Message-Id: <20191127203121.842234236@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@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 From: Jon Derrick [ Upstream commit dc8af3a827df6d4bb925d3b81b7ec94a7cce9482 ] The VMD removal path calls pci_stop_root_busi(), which tears down the pcie tree, including detaching all of the attached drivers. During driver detachment, devices may use pci_release_region() to release resources. This path relies on the resource being accessible in resource tree. By detaching the child domain from the parent resource domain prior to stopping the bus, we are preventing the list traversal from finding the resource to be freed. If we instead detach the resource after stopping the bus, we will have properly freed the resource and detaching is simply accounting at that point. Without this order, the resource is never freed and is orphaned on VMD removal, leading to a warning: [ 181.940162] Trying to free nonexistent resource Fixes: 2c2c5c5cd213 ("x86/PCI: VMD: Attach VMD resources to parent domain's resource tree") Signed-off-by: Jon Derrick [lorenzo.pieralisi@arm.com: updated commit log] Signed-off-by: Lorenzo Pieralisi Reviewed-by: Keith Busch Signed-off-by: Sasha Levin --- drivers/pci/controller/vmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c index 65eaa6b618685..ab36e5ca1aca3 100644 --- a/drivers/pci/controller/vmd.c +++ b/drivers/pci/controller/vmd.c @@ -818,12 +818,12 @@ static void vmd_remove(struct pci_dev *dev) { struct vmd_dev *vmd = pci_get_drvdata(dev); - vmd_detach_resources(vmd); sysfs_remove_link(&vmd->dev->dev.kobj, "domain"); pci_stop_root_bus(vmd->bus); pci_remove_root_bus(vmd->bus); vmd_cleanup_srcu(vmd); vmd_teardown_dma_ops(vmd); + vmd_detach_resources(vmd); irq_domain_remove(vmd->irq_domain); } -- 2.20.1