Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp50197imu; Thu, 8 Nov 2018 14:35:06 -0800 (PST) X-Google-Smtp-Source: AJdET5ecx5jPh9p7ZBGoI7hThcKSo14I6HX742zzXfagFGO7rD3mohpLxOglSC1TDpNx/ogenfBM X-Received: by 2002:a63:588:: with SMTP id 130mr5239389pgf.273.1541716506439; Thu, 08 Nov 2018 14:35:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541716506; cv=none; d=google.com; s=arc-20160816; b=Nynwd55aXT3MIKqB+8qA6UWaJgow7N1I+iUQd+F1NmBCJfnxdnOpdQbC10CutnX6yK O0Cbp7qKyChIHTe9JDCGchXGHJPya8IrIZQkd0QrHEViCFQafM+5M2dIJkPiwmBk5eRg QXA+lMHU8jQrKFuyNW6kLvzIzbm7pTmA3ruwX7L13tY3RtkrCqk5gS/pazt+QkrotuwJ lTT7qULVjYc9zGJdB4jBKv6NTEJW8ZdyYT3xQUqvVaTaHMhivQguskwQQ0NWt5Zwt88s GFbbiJxW7IAvNM/cdeQrIx/sZJcgfT7O8v2nvW41jzu29d4UfKnPu040jGbdhkYMxVgg JA1w== 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=lzTlsebueghNAURNQaHuQoA7Oh2DWiyJgXUEdeJIWTs=; b=QpM1xtLYEB5m8KkaKlEUNGsbFNjnpHeqxyx6S25Q2BOcI75kWJL3CJ+mjrzN8AjiGD cDohViRWNQD2ktD7wZU6eR2iNFC4GuzN+eo6ex+TqXVyKNuEarTjSIfvYKpTxhdD39iK X14jw5ZN61ZKy2mTVszuBBFbaGTKzX+xDWgh9OfFGLZoPBJnWUmR+/EwgAnNZeFg0nXp 47oek6ugjiA2apJYAnxjbdPWTz+mOkMU20TC8z0aCN57CQrBzBrMOl9lBvfI7GD6NDGN 3N9B00c2rpsO7Yc4N2EFdXxls79WeY0Su/vokpwVwbbYCUU6PgnxO5jckZioBQINR5P7 HpVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XK3JpCqd; 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 e2si4568344pgs.94.2018.11.08.14.34.50; Thu, 08 Nov 2018 14:35:06 -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=XK3JpCqd; 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 S1730136AbeKIHhQ (ORCPT + 99 others); Fri, 9 Nov 2018 02:37:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:55158 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729144AbeKIHhP (ORCPT ); Fri, 9 Nov 2018 02:37:15 -0500 Received: from localhost (unknown [208.72.13.198]) (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 E537321019; Thu, 8 Nov 2018 21:59:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541714387; bh=a7VBmdl0t6YNAiGGNbmSFTOkoTMhbrESBTkAyyCwvKc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XK3JpCqdsBx7qFjLLykQGx+iEuLc3iutbo4i3JMQ52sCQMXxQ87dkvjUixNtZFo1y LeuCfc+Ia4HZOAJ7uam7DUPHcOj0zgSfU+Z74+o3IV1bRgQqbGJZVS/fRmleLGSZPu oGnEvQB8WaBl7ADL60NYH9cOM/ALRNksi4GWIfJk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sowmini Varadhan , Babu Moger , Khalid Aziz , "David S. Miller" , Sasha Levin Subject: [PATCH 4.4 048/114] sparc/pci: Refactor dev_archdata initialization into pci_init_dev_archdata Date: Thu, 8 Nov 2018 13:51:03 -0800 Message-Id: <20181108215105.510943466@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108215059.051093652@linuxfoundation.org> References: <20181108215059.051093652@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 9a78d4fc28904785ffe4c2d361e25b251b479704 ] The function pcibios_add_device() added by commit d0c31e020057 ("sparc/PCI: Fix for panic while enabling SR-IOV") initializes the dev_archdata by doing a memcpy from the PF. This has the problem that it erroneously copies the OF device without explicitly refcounting it. As David Miller pointed out: "Generally speaking we don't really support hot-plug for OF probed devices, but if we did all of the device tree pointers have to be refcounted properly." To fix this error, and also avoid code duplication, this patch creates a new helper function, pci_init_dev_archdata(), that initializes the fields in dev_archdata, and can be invoked by callers after they have taken the needed refcounts Signed-off-by: Sowmini Varadhan Tested-by: Babu Moger Reviewed-by: Khalid Aziz Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- arch/sparc/kernel/pci.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/arch/sparc/kernel/pci.c b/arch/sparc/kernel/pci.c index 9f9614df9e1e..c2b202d763a1 100644 --- a/arch/sparc/kernel/pci.c +++ b/arch/sparc/kernel/pci.c @@ -245,6 +245,18 @@ static void pci_parse_of_addrs(struct platform_device *op, } } +static void pci_init_dev_archdata(struct dev_archdata *sd, void *iommu, + void *stc, void *host_controller, + struct platform_device *op, + int numa_node) +{ + sd->iommu = iommu; + sd->stc = stc; + sd->host_controller = host_controller; + sd->op = op; + sd->numa_node = numa_node; +} + static struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm, struct device_node *node, struct pci_bus *bus, int devfn) @@ -259,13 +271,10 @@ static struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm, if (!dev) return NULL; + op = of_find_device_by_node(node); sd = &dev->dev.archdata; - sd->iommu = pbm->iommu; - sd->stc = &pbm->stc; - sd->host_controller = pbm; - sd->op = op = of_find_device_by_node(node); - sd->numa_node = pbm->numa_node; - + pci_init_dev_archdata(sd, pbm->iommu, &pbm->stc, pbm, op, + pbm->numa_node); sd = &op->dev.archdata; sd->iommu = pbm->iommu; sd->stc = &pbm->stc; @@ -1003,9 +1012,13 @@ int pcibios_add_device(struct pci_dev *dev) * Copy dev_archdata from PF to VF */ if (dev->is_virtfn) { + struct dev_archdata *psd; + pdev = dev->physfn; - memcpy(&dev->dev.archdata, &pdev->dev.archdata, - sizeof(struct dev_archdata)); + psd = &pdev->dev.archdata; + pci_init_dev_archdata(&dev->dev.archdata, psd->iommu, + psd->stc, psd->host_controller, NULL, + psd->numa_node); } return 0; } -- 2.17.1