Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp881415pxk; Thu, 17 Sep 2020 20:13:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCvwVv5YnL3qx7rvfP3jUOIa5vByuhY6jrf/IzpAWxeXyDJyQQPRSQwEb24Hstg00jwUPW X-Received: by 2002:a17:906:4c8b:: with SMTP id q11mr32343372eju.531.1600398787606; Thu, 17 Sep 2020 20:13:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398787; cv=none; d=google.com; s=arc-20160816; b=OE8ntF4vrIgD6yMrCiJZhWu0XcV8w/9CBiQWYA1Oo4+8U9xj7cvPJTpmPs3TGmyHM1 w7NJsqt7edMkEQXAClYQUDrt5KNzn1fPjhyNCCUfn14Hk9whGxdsmwQoBIzDx84zfosE qaUMt/dZzBt5QHuqbU52WvN7Bv6L7Yz8WmL3wWpir3pJfuc/gvf4R/TUjvJE4inWURu+ P+XxVxD2DvYY9RfN+M7caZXslm/CQA3qrHg9Cu9yMul32uI6zsU8thVs62drkX8dW0Wy oJ/ox9Ef0o76e9uacsvFkIj0/ZiKgewu+Ks9099mFnd9MxpageIG3LwILPjfmh4ew/Eb SBVQ== 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=pWMfbl4P6cuROMl6QomLJgNGKky39PWNm+vvqSWpaUA=; b=mM+3m2ny4pS/XX3e1jEHvm5/hguP+kTx6qAVOBwDqNoVRf0XLj7lPTRfCcu5kApzgU 00U8XTfRac1+rqb9NFj9Q+nUX7UwSU9rXUll4TKDaHRa97d4kCGfTWOEZFDqreoZsw7n r61WHuoaV1ocu10brNZU7avYmkjPghiDyWSJhHexTWvx56wwW/wtEs7QdFipFSWw4tYK hu5ByXHW1R6ta4jqjyJZAW4YzAqpFZzWG1qusC8JFfBvUit1XjDSlqcWAFrLANl7CCVC L7lmLU8Tce61VdWOIVyF3dcDaaCS4BxCKWUPidgAortq2I/dfruP3LwND66/t+5Uq13a TkEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zvNU9bWe; 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 g15si1313080ejd.257.2020.09.17.20.12.44; Thu, 17 Sep 2020 20:13:07 -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=zvNU9bWe; 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 S1727028AbgIRCDS (ORCPT + 99 others); Thu, 17 Sep 2020 22:03:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:49230 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727006AbgIRCDO (ORCPT ); Thu, 17 Sep 2020 22:03:14 -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 C338C208DB; Fri, 18 Sep 2020 02:03:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394593; bh=q8aSY4BrpykZOhPnaUpN26R7PA9NuLZectz/YVdYvOI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zvNU9bWe4qeZMc1hzmC9NslCvWR8Hn0xFvMzu7yLKzpREQSks0TuhB0am8cKp7O+o CpZgcHtJ5A06aM08EDv9EabWyz0IDjTED3EJ9ZRJGTqx7JDKO2SE9yQAYN/UwS2+Kp lRzUTQ0K/kKoR3wmXZOqfATAk3/EAhmCsHtb+pKA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Frederic Barrat , Andrew Donnellan , Michael Ellerman , Sasha Levin , linuxppc-dev@lists.ozlabs.org Subject: [PATCH AUTOSEL 5.4 101/330] powerpc/powernv/ioda: Fix ref count for devices with their own PE Date: Thu, 17 Sep 2020 21:57:21 -0400 Message-Id: <20200918020110.2063155-101-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: Frederic Barrat [ Upstream commit 05dd7da76986937fb288b4213b1fa10dbe0d1b33 ] The pci_dn structure used to store a pointer to the struct pci_dev, so taking a reference on the device was required. However, the pci_dev pointer was later removed from the pci_dn structure, but the reference was kept for the npu device. See commit 902bdc57451c ("powerpc/powernv/idoa: Remove unnecessary pcidev from pci_dn"). We don't need to take a reference on the device when assigning the PE as the struct pnv_ioda_pe is cleaned up at the same time as the (physical) device is released. Doing so prevents the device from being released, which is a problem for opencapi devices, since we want to be able to remove them through PCI hotplug. Now the ugly part: nvlink npu devices are not meant to be released. Because of the above, we've always leaked a reference and simply removing it now is dangerous and would likely require more work. There's currently no release device callback for nvlink devices for example. So to be safe, this patch leaks a reference on the npu device, but only for nvlink and not opencapi. Signed-off-by: Frederic Barrat Reviewed-by: Andrew Donnellan Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20191121134918.7155-2-fbarrat@linux.ibm.com Signed-off-by: Sasha Levin --- arch/powerpc/platforms/powernv/pci-ioda.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c index 058223233088e..e9cda7e316a50 100644 --- a/arch/powerpc/platforms/powernv/pci-ioda.c +++ b/arch/powerpc/platforms/powernv/pci-ioda.c @@ -1062,14 +1062,13 @@ static struct pnv_ioda_pe *pnv_ioda_setup_dev_PE(struct pci_dev *dev) return NULL; } - /* NOTE: We get only one ref to the pci_dev for the pdn, not for the - * pointer in the PE data structure, both should be destroyed at the - * same time. However, this needs to be looked at more closely again - * once we actually start removing things (Hotplug, SR-IOV, ...) + /* NOTE: We don't get a reference for the pointer in the PE + * data structure, both the device and PE structures should be + * destroyed at the same time. However, removing nvlink + * devices will need some work. * * At some point we want to remove the PDN completely anyways */ - pci_dev_get(dev); pdn->pe_number = pe->pe_number; pe->flags = PNV_IODA_PE_DEV; pe->pdev = dev; @@ -1084,7 +1083,6 @@ static struct pnv_ioda_pe *pnv_ioda_setup_dev_PE(struct pci_dev *dev) pnv_ioda_free_pe(pe); pdn->pe_number = IODA_INVALID_PE; pe->pdev = NULL; - pci_dev_put(dev); return NULL; } @@ -1205,6 +1203,14 @@ static struct pnv_ioda_pe *pnv_ioda_setup_npu_PE(struct pci_dev *npu_pdev) struct pci_controller *hose = pci_bus_to_host(npu_pdev->bus); struct pnv_phb *phb = hose->private_data; + /* + * Intentionally leak a reference on the npu device (for + * nvlink only; this is not an opencapi path) to make sure it + * never goes away, as it's been the case all along and some + * work is needed otherwise. + */ + pci_dev_get(npu_pdev); + /* * Due to a hardware errata PE#0 on the NPU is reserved for * error handling. This means we only have three PEs remaining @@ -1228,7 +1234,6 @@ static struct pnv_ioda_pe *pnv_ioda_setup_npu_PE(struct pci_dev *npu_pdev) */ dev_info(&npu_pdev->dev, "Associating to existing PE %x\n", pe_num); - pci_dev_get(npu_pdev); npu_pdn = pci_get_pdn(npu_pdev); rid = npu_pdev->bus->number << 8 | npu_pdn->devfn; npu_pdn->pe_number = pe_num; -- 2.25.1