Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp732605ybc; Sat, 16 Nov 2019 07:44:59 -0800 (PST) X-Google-Smtp-Source: APXvYqxwNgwKDRXQHPbCFOnKbrFuUFcs1kqr/Nbbp5qQr/YX0jl8bre3tXa0EtYXgPYZzPNTm1C4 X-Received: by 2002:a17:906:1be9:: with SMTP id t9mr10626098ejg.10.1573919099108; Sat, 16 Nov 2019 07:44:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573919099; cv=none; d=google.com; s=arc-20160816; b=d8XmFhxDCT3a1tXpQwsu8N37RTv1WZFiNZCVwEnxS7QtggjAbCjFCxAnf9W3l3JV5a 8sqtCumHgL1j/Rgy+rm81dxQ742n9a6u1pcliNpEuUq1yVWI8Tu45l9XZr/IepJQzHwz t2+sXzI7Av6QXOCPfwI6mdZfhNB/VPCHanObnFIEtG9PokQjdSyL2XZMDIblx7251HQs YKsBw1c+wfN/h/5nK9Xe7Ya3p21nOsWtMpAOnT1ePal+P2eLcPCKGiKVB13iC1LgYIZ1 RV+N1vErBLVXyHnrnwoEqt9/k7UjDe051aLS30ckWtxJInK12dP1J00QmHJpTEH6Jqjb xiaA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=agZ44xVXGQXXiVYHQeMwsDKwSGUwpmCU91eVI/zL+EU=; b=pqys1b6bWNZmLNNvKV836RCEP+zev2rEeh4EpGxBkP6Yf2mOYsDlW5NmCVCErvlRst 0Jdvz5f59P/ts3QDG2gayV1pVRR+foq3X0GRTu6te0ZIrflDvk+mTfS8QSH40mgOF+wo jLkNcbhQpNnDI2+gYYVzq1wYiUwSw6gZpbbCCaexA7Wae3katiCV7Gf614WXcikmZpc0 6lbasciFhmz1b8adLeYnsYR4v1YGKJv6aXgpkuIy5h/1qeZBzoIYcyFGy/eE8h8d2HR+ hqNXaYPz9e7CgwuhWIWI0vtk4FiaZ+pkPwMI5L5qZxei/kzaof8/eGfttsvCdiZuWs1r BkWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1Aw2TMS6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u24si10141194edl.447.2019.11.16.07.44.34; Sat, 16 Nov 2019 07:44:59 -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=1Aw2TMS6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728452AbfKPPms (ORCPT + 99 others); Sat, 16 Nov 2019 10:42:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:46344 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728374AbfKPPmi (ORCPT ); Sat, 16 Nov 2019 10:42:38 -0500 Received: from sasha-vm.mshome.net (unknown [50.234.116.4]) (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 455FF207DD; Sat, 16 Nov 2019 15:42:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573918957; bh=omppKKnMzlwMUO/lGjPYMr5FWF7KOGGvHMhEJD4Ko/A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1Aw2TMS6s/4lnKh+mMRRIBqj2uBDvEkNbne/B+xhXm974eBM3O22Y8C2IHtM0DDXo bdxBOd1WmXVgA31fwJS16M6gzyai6PGGjho4mrcFmFyr2tn5bpGLOIW33v6HHWEEuM skYN26IUtYRmkVB4vzNLMpMc+5kSZYzJZHIYB8Yo= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jon Derrick , Lorenzo Pieralisi , Keith Busch , Sasha Levin , linux-pci@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 076/237] PCI: vmd: Detach resources after stopping root bus Date: Sat, 16 Nov 2019 10:38:31 -0500 Message-Id: <20191116154113.7417-76-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191116154113.7417-1-sashal@kernel.org> References: <20191116154113.7417-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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