devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gavin Shan <gwshan@linux.vnet.ibm.com>
To: Rob Herring <robherring2@gmail.com>
Cc: Gavin Shan <gwshan@linux.vnet.ibm.com>,
	linuxppc-dev <linuxppc-dev@lists.ozlabs.org>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Alexey Kardashevskiy <aik@ozlabs.ru>,
	Bjorn Helgaas <bhelgaas@google.com>,
	dja@axtens.net, Alistair Popple <alistair@popple.id.au>
Subject: Re: [PATCH v9 22/22] PCI/hotplug: PowerPC PowerNV PCI hotplug driver
Date: Fri, 6 May 2016 10:28:34 +1000	[thread overview]
Message-ID: <20160506002834.GA5509@gwshan> (raw)
In-Reply-To: <CAL_JsqLAYk2S80LNvF2z2ZzPfCWAbpz2LNKK-04OgSkabjWbxQ@mail.gmail.com>

On Thu, May 05, 2016 at 12:04:49PM -0500, Rob Herring wrote:
>On Tue, May 3, 2016 at 8:22 AM, Gavin Shan <gwshan@linux.vnet.ibm.com> wrote:
>> This adds standalone driver to support PCI hotplug for PowerPC PowerNV
>> platform that runs on top of skiboot firmware. The firmware identifies
>> hotpluggable slots and marked their device tree node with proper
>> "ibm,slot-pluggable" and "ibm,reset-by-firmware". The driver scans
>> device tree nodes to create/register PCI hotplug slot accordingly.
>>
>> The PCI slots are organized in fashion of tree, which means one
>> PCI slot might have parent PCI slot and parent PCI slot possibly
>> contains multiple child PCI slots. At the plugging time, the parent
>> PCI slot is populated before its children. The child PCI slots are
>> removed before their parent PCI slot can be removed from the system.
>>
>> If the skiboot firmware doesn't support slot status retrieval, the PCI
>> slot device node shouldn't have property "ibm,reset-by-firmware". In
>> that case, none of valid PCI slots will be detected from device tree.
>> The skiboot firmware doesn't export the capability to access attention
>> LEDs yet and it's something for TBD.
>>
>> Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
>> Acked-by: Bjorn Helgaas <bhelgaas@google.com>
>
>[...]
>
>> +static void pnv_php_handle_poweron(struct pnv_php_slot *php_slot)
>> +{
>> +       void *fdt, *fdt1, *dt;
>> +       int confirm = PNV_PHP_POWER_CONFIRMED_SUCCESS;
>> +       int ret;
>> +
>> +       /* We don't know the FDT blob size. We try to get it through
>> +        * maximal memory chunk and then copy it to another chunk that
>> +        * fits the real size.
>> +        */
>> +       fdt1 = kzalloc(0x10000, GFP_KERNEL);
>> +       if (!fdt1)
>> +               goto error;
>> +
>> +       ret = pnv_pci_get_device_tree(php_slot->dn->phandle, fdt1, 0x10000);
>> +       if (ret)
>> +               goto free_fdt1;
>> +
>> +       fdt = kzalloc(fdt_totalsize(fdt1), GFP_KERNEL);
>> +       if (!fdt)
>> +               goto free_fdt1;
>> +
>> +       /* Unflatten device tree blob */
>> +       memcpy(fdt, fdt1, fdt_totalsize(fdt1));
>
>This is wrong. If the size is greater than 64K, then you will be
>overrunning the fdt1 buffer. You need to fetch the FDT again if it is
>bigger than 64KB.
>

Thanks for review, Rob. Sorry that I don't see how it's a problem. An
errcode is returned from pnv_pci_get_device_tree() if the FDT blob
size is greater than 64K. In this case, memcpy() won't be triggered.
pnv_pci_get_device_tree() relies on firmware implementation which
avoids overrunning the buffer.

On the other hand, it would be reasonable to retry retriving the
FDT blob if 64K buffer isn't enough. Also, kzalloc() can be replaced
with alloc_pages() as 64K is the default page size on PPC64. I will
have something like below until some one has more concerns. As the
size of the allocated buffer will be greater than the real FDT blob
size, some memory (not too much) is wasted. I guess it should be ok.

	struct page *page;
	void *fdt;
	unsigned int order;
	int ret;

	for (order = 0; order < MAX_ORDER; order++) {
		page = alloc_pages(GFP_KERNEL, order);
		if (page) {
			fdt = page_address(page);
			ret = pnv_pci_get_device_tree(php_slot->dn->phandle,
						      fdt, (1 << order) * PAGE_SIZE);
			if (ret) {
				dev_dbg(&php_slot->pdev.dev, "Error %d getting device tree (%d)\n",
					ret, order);
				free_pages(fdt, order);
				continue;
			}
		}
	}

	if (order >= MAX_ORDER) {
		dev_warn(&php_slot->pdev.dev, "Cannot get device tree\n");
		return;
	}

	/* Unflatten the blob without copying it to another allocated buffer */

Thanks,
Gavin

>
>> +       dt = of_fdt_unflatten_tree(fdt, php_slot->dn, NULL);
>> +       if (!dt) {
>> +               dev_warn(&php_slot->pdev->dev, "Cannot unflatten FDT\n");
>> +               goto free_fdt;
>> +       }
>> +
>

  reply	other threads:[~2016-05-06  0:28 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-03 13:22 [PATCH v9 00/22] powerpc/powernv: PCI hotplug support Gavin Shan
2016-05-03 13:22 ` [PATCH v9 01/22] PCI: Add pcibios_setup_bridge() Gavin Shan
2016-05-03 13:22 ` [PATCH v9 02/22] powerpc/pci: Override pcibios_setup_bridge() Gavin Shan
2016-05-03 13:22 ` [PATCH v9 03/22] powerpc/powernv: Move pnv_pci_ioda_setup_opal_tce_kill() around Gavin Shan
2016-05-06  6:36   ` Alexey Kardashevskiy
2016-05-03 13:22 ` [PATCH v9 04/22] powerpc/powernv: Increase PE# capacity Gavin Shan
2016-05-06  7:17   ` Alexey Kardashevskiy
2016-05-06 11:05     ` Gavin Shan
2016-05-03 13:22 ` [PATCH v9 05/22] powerpc/powernv: Allocate PE# in reverse order Gavin Shan
2016-05-03 13:22 ` [PATCH v9 06/22] powerpc/powernv: Create PEs in pcibios_setup_bridge() Gavin Shan
2016-05-03 13:22 ` [PATCH v9 07/22] powerpc/powernv: Setup PE for root bus Gavin Shan
2016-05-03 13:22 ` [PATCH v9 08/22] powerpc/powernv: Extend PCI bridge resources Gavin Shan
2016-05-03 13:22 ` [PATCH v9 09/22] powerpc/powernv: Make pnv_ioda_deconfigure_pe() visible Gavin Shan
2016-05-03 13:22 ` [PATCH v9 10/22] powerpc/powernv: Dynamically release PE Gavin Shan
2016-05-03 13:22 ` [PATCH v9 11/22] powerpc/pci: Update bridge windows on PCI plug Gavin Shan
2016-05-03 13:22 ` [PATCH v9 12/22] powerpc/pci: Delay populating pdn Gavin Shan
2016-05-03 13:22 ` [PATCH v9 13/22] powerpc/powernv: Support PCI slot ID Gavin Shan
2016-05-03 13:22 ` [PATCH v9 14/22] powerpc/powernv: Use PCI slot reset infrastructure Gavin Shan
2016-05-03 13:22 ` [PATCH v9 15/22] powerpc/powernv: Functions to get/set PCI slot state Gavin Shan
2016-05-11  3:28   ` Alistair Popple
2016-05-03 13:22 ` [PATCH v9 16/22] drivers/of: Split unflatten_dt_node() Gavin Shan
2016-05-03 13:22 ` [PATCH v9 17/22] drivers/of: Avoid recursively calling unflatten_dt_node() Gavin Shan
2016-05-03 13:22 ` [PATCH v9 18/22] drivers/of: Rename unflatten_dt_node() Gavin Shan
2016-05-03 13:22 ` [PATCH v9 19/22] drivers/of: Specify parent node in of_fdt_unflatten_tree() Gavin Shan
     [not found] ` <1462281773-26438-1-git-send-email-gwshan-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-05-03 13:22   ` [PATCH v9 20/22] drivers/of: Return allocated memory from of_fdt_unflatten_tree() Gavin Shan
2016-05-03 13:22 ` [PATCH v9 21/22] drivers/of: Export of_detach_node() Gavin Shan
2016-05-04 13:36   ` Gavin Shan
2016-05-05 19:42     ` Rob Herring
2016-05-06  0:40       ` Gavin Shan
2016-05-03 13:22 ` [PATCH v9 22/22] PCI/hotplug: PowerPC PowerNV PCI hotplug driver Gavin Shan
     [not found]   ` <1462281773-26438-23-git-send-email-gwshan-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-05-05 17:04     ` Rob Herring
2016-05-06  0:28       ` Gavin Shan [this message]
2016-05-06 13:12         ` Rob Herring
2016-05-08 23:51           ` Gavin Shan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160506002834.GA5509@gwshan \
    --to=gwshan@linux.vnet.ibm.com \
    --cc=aik@ozlabs.ru \
    --cc=alistair@popple.id.au \
    --cc=benh@kernel.crashing.org \
    --cc=bhelgaas@google.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dja@axtens.net \
    --cc=linux-pci@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=robherring2@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).