All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Fontenot <nfont@linux.vnet.ibm.com>
To: Michael Ellerman <mpe@ellerman.id.au>, linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH v2 3/8] powerpc/mm: Separate ibm, dynamic-memory data from DT format
Date: Mon, 13 Nov 2017 08:51:59 -0600	[thread overview]
Message-ID: <91f1c54a-a7cd-5ccb-a7f8-f9714d8f06fc@linux.vnet.ibm.com> (raw)
In-Reply-To: <87vaifwtu5.fsf@concordia.ellerman.id.au>

On 11/12/2017 06:43 AM, Michael Ellerman wrote:
> Hi Nathan,
> 
> Nathan Fontenot <nfont@linux.vnet.ibm.com> writes:
>> diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
>> index f83056297441..917184c13890 100644
>> --- a/arch/powerpc/kernel/prom.c
>> +++ b/arch/powerpc/kernel/prom.c
>> @@ -454,92 +455,93 @@ static int __init early_init_dt_scan_chosen_ppc(unsigned long node,
> ...
>>  
>>  static int __init early_init_dt_scan_memory_ppc(unsigned long node,
>>  						const char *uname,
>>  						int depth, void *data)
>>  {
>> +	int rc;
>> +
>>  	if (depth == 1 &&
>> -	    strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0)
>> -		return early_init_dt_scan_drconf_memory(node);
>> +	    strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0) {
>> +		rc = init_drmem_lmbs(node);
>> +		if (!rc)
>> +			early_init_dt_scan_drmem_lmbs(node);
>> +
>> +		return rc;
>> +	}
>>  	
>>  	return early_init_dt_scan_memory(node, uname, depth, data);
>>  }
> 
> There's one bug in here which is that you return rc as returned by
> init_drmem_lmbs(). Returning non-zero from these scan routines
> terminates the scan, which means if anything goes wrong in
> init_drmem_lmbs() we may not call early_init_dt_scan_memory()
> in which case we won't have any memory at all.
> 

I didn't know this would stop scanning the device tree, thanks for letting me know.

> I say "may not" because it depends on the order of the nodes in the
> device tree whether you hit the memory nodes or the dynamic reconfig mem
> info first. And the order of the nodes in the device tree is arbitrary
> so we can't rely on that.
> 
> 
>> diff --git a/arch/powerpc/mm/drmem.c b/arch/powerpc/mm/drmem.c
>> new file mode 100644
>> index 000000000000..8ad7cf36b2c4
>> --- /dev/null
>> +++ b/arch/powerpc/mm/drmem.c
>> @@ -0,0 +1,84 @@
> ...
>> +
>> +int __init init_drmem_lmbs(unsigned long node)
>> +{
>> +	struct drmem_lmb *lmb;
>> +	const __be32 *prop;
>> +	int prop_sz;
>> +	u32 len;
>> +
>> +	prop = of_get_flat_dt_prop(node, "ibm,lmb-size", &len);
>> +	if (!prop || len < dt_root_size_cells * sizeof(__be32))
>> +		return -1;
>> +
>> +	drmem_info->lmb_size = dt_mem_next_cell(dt_root_size_cells, &prop);
>> +
>> +	prop = of_get_flat_dt_prop(node, "ibm,dynamic-memory", &len);
>> +	if (!prop || len < dt_root_size_cells * sizeof(__be32))
>> +		return -1;
>> +
>> +	drmem_info->n_lmbs = of_read_number(prop++, 1);
>> +	prop_sz = drmem_info->n_lmbs * sizeof(struct of_drconf_cell)
>> +		  + sizeof(__be32);
>> +	if (prop_sz < len)
>> +		return -1;
>> +
>> +	drmem_info->lmbs = alloc_bootmem(drmem_info->n_lmbs * sizeof(*lmb));
>> +	if (!drmem_info->lmbs)
>> +		return -1;
> 
> The bigger problem we have though is that you're trying to allocate
> memory, in order to find out what memory we have :)
> 
> I suspect it works in some cases because you hit the memory@0 node first
> in the device tree, and add that memory to memblock, which means
> init_drmem_lmbs() *can* allocate memory, and everything's good.
> 
> But if we hit init_drmem_lmbs() first, or there's not enough space in
> memory@0, then allocating memory in order to discover memory is not
> going to work.
> 
> I'm not sure what the best solution is. One option would be to
> statically allocate some space, so that we can discover some of the LMBs
> without doing an allocation. But we wouldn't be able to guarantee that
> we had enough space i nthat static allocation, so the code would need to
> handle doing that and then potentially finding more LMBs later using a
> dynamic alloc. So that could be a bit messy.
> 
> The other option would be for the early_init_dt_scan_drmem_lmbs() code
> to still work on the device tree directly, rather than using the
> drmem_info array. That would make for uglier code, but may be necessary.
> 

I have been thinking about my initial approach, and the more I look at it
the more I do not like trying to do the bootmem allocation. As you mention
there is just too much that could go wrong with that.

I have started looking at a design where an interface similar to
walk_memory_range() is used for the prom and numa code so we do not have to rely
on making the allocation for the lmb array early in boot. The lmb array
could then be allocated in the late_initcall in drmem.c at which point
the general kernel allocator is available.

I'm still working on getting this coded up and when send out a new patch set
once it's ready unless anyone has objections to this approach.

-Nathan

  reply	other threads:[~2017-11-13 14:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-20 13:21 [PATCH v2 0/8] powerpc: Support ibm,dynamic-memory-v2 property Nathan Fontenot
2017-10-20 13:21 ` [PATCH v2 1/8] powerpc/numa: Look up device node in of_get_assoc_arrays() Nathan Fontenot
2017-10-20 13:22 ` [PATCH v2 2/8] powerpc/numa: Look up device node in of_get_usable_memory() Nathan Fontenot
2017-10-20 13:22 ` [PATCH v2 3/8] powerpc/mm: Separate ibm, dynamic-memory data from DT format Nathan Fontenot
2017-10-24  6:08   ` Michael Ellerman
2017-10-24 20:33     ` Nathan Fontenot
2017-10-25  9:16       ` Michael Ellerman
2017-11-12 12:43   ` Michael Ellerman
2017-11-13 14:51     ` Nathan Fontenot [this message]
2017-11-14 10:25       ` Michael Ellerman
2017-10-20 13:22 ` [PATCH v2 4/8] powerpc/numa: Update numa code use drmem LMB array Nathan Fontenot
2017-10-20 13:22 ` [PATCH v2 5/8] powerpc/pseries: Update memory hotplug code to " Nathan Fontenot
2017-10-20 13:22 ` [PATCH v2 6/8] powerpc: Move of_drconf_cell struct to asm/drmem.h Nathan Fontenot
2017-10-20 13:22 ` [PATCH v2 7/8] powerpc/pseries: Add support for ibm, dynamic-memory-v2 property Nathan Fontenot
2017-10-20 13:22 ` [PATCH v2 8/8] powerpc: Enable support of ibm,dynamic-memory-v2 Nathan Fontenot
2017-11-16  5:37 ` [PATCH v2 0/8] powerpc: Support ibm,dynamic-memory-v2 property Bharata B Rao
2017-11-16 16:01   ` Nathan Fontenot
2017-11-17  4:51     ` Bharata B Rao
2017-11-20 14:48       ` Nathan Fontenot

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=91f1c54a-a7cd-5ccb-a7f8-f9714d8f06fc@linux.vnet.ibm.com \
    --to=nfont@linux.vnet.ibm.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.