Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1757018ybz; Sat, 18 Apr 2020 07:52:19 -0700 (PDT) X-Google-Smtp-Source: APiQypJ9fL4jxfLntUrdrmGFr+bsgCxm4Yx6XsMFLrlu4gGJtNPpG1gIl6Saza7gBRz+URz26Qi6 X-Received: by 2002:a50:d90f:: with SMTP id t15mr7414618edj.209.1587221538848; Sat, 18 Apr 2020 07:52:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587221538; cv=none; d=google.com; s=arc-20160816; b=ikCbk60IlzdJ+9vuKvRJ0tq8Y5eBPC44bQ0GfdFjHTwCRl2E/bJohzZ2OpUP/x/C/e CRrG2L1pZQcm2MeBstD26DvGuPA5VQLq4WeXBG+TuMFwT0PLQtsXbk93px7f0wfChCZl z3iEk1LC4tvzW4+17ZdQGHkyWS07DWr0p8mlpqrZ6BI5Gg7to8nozQ3JHY6dQa1B1MFW ic1XR3ngXnf7uRyedA0Fo6WH4T21ZVEvfJn0rvWzI/nkVJOPgyKatCXUpNqjhX5483oG A6dX88VfvDMAPGeFhzdPKIVCacSyct6mj6nIYqLlwrkSvM7ZNQPDLu7ZogAa1Wp9YwiU 6vIg== 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=vbYDt3udNTI9qUQ6Ckz35PK3XWXlFejNH3kG5ycyd/E=; b=e8O/MaQ1puEKMt65yfJnAn+JtCIG1fCBcaKI/yEz1pfmt8S+pLzLtITIf7X+LsSq+q Vr7KexOaleJfXPbnGaiP1cYm8/76H0O91cMl2SIemqP6fRTcx9bVhiIgd0oAjO3mG8fi 3ouDd5yif/86R0n5IHcin9QrX3QS5Haz2lQnG/bbUJ+d73uOxIr6qtmMZzt+XsA4hmJ0 YfKPnfwf9pz9n1co7HcDcxG4zM2NYeV8S9XVeiC7DyHNJvrHwo8nzIf/i4JKiMRtyQqB 6XPvO0ZAwGFh+IRqJDIUeFgtA+8P++cbkAUQrT34vqydFKnCwata6YZO1mEb93xlRnXS +SXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=l8xQh4H3; 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 o5si16534832ejj.514.2020.04.18.07.51.55; Sat, 18 Apr 2020 07:52:18 -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=l8xQh4H3; 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 S1728480AbgDROt4 (ORCPT + 99 others); Sat, 18 Apr 2020 10:49:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:54286 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728549AbgDROnU (ORCPT ); Sat, 18 Apr 2020 10:43:20 -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 6DFFC21D82; Sat, 18 Apr 2020 14:43:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587220999; bh=GUP71k4DWLyje3IERdpzAzJTjDkOkehV0jMXlO3fw4Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l8xQh4H3kSLSK4VtvjagZ4g/oJ9KvApxaoPctiCn5kNWKRULvD8njOF+O3bJNuqLY OLH+78uzzJFKSL6/eQG0T9huFj3BeBgzUR5kFuNbXL6DDUdH9ev5WPiQGJ/OQa5HpQ +Q7/UB0ooh1ZNsV5dvH4X8paIWPjDBs1SkgaUv4s= 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 4.19 41/47] powerpc/powernv/ioda: Fix ref count for devices with their own PE Date: Sat, 18 Apr 2020 10:42:21 -0400 Message-Id: <20200418144227.9802-41-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200418144227.9802-1-sashal@kernel.org> References: <20200418144227.9802-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: 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 ecd211c5f24a5..19cd6affdd5fb 100644 --- a/arch/powerpc/platforms/powernv/pci-ioda.c +++ b/arch/powerpc/platforms/powernv/pci-ioda.c @@ -1071,14 +1071,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; @@ -1093,7 +1092,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; } @@ -1213,6 +1211,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 @@ -1236,7 +1242,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.20.1