linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of: Fix comparison of reserved memory regions
@ 2015-11-18 10:46 Michael Ellerman
  2015-12-04 17:07 ` Mitchel Humpherys
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Ellerman @ 2015-11-18 10:46 UTC (permalink / raw)
  To: robh+dt
  Cc: devicetree, linux-kernel, linuxppc-dev, mitchelh, frowand.list,
	grant.likely

In order to check for overlapping reserved memory regions, we first need
to sort the array of memory regions. This is implemented using sort(),
and a custom comparison function __rmem_cmp().

Unfortunatley __rmem_cmp() doesn't work in all cases. Because the two
base values are phys_addr_t, they may be u64 on some platforms, in which
case subtracting one from the other and then (implicitly) casting to int
does not give us the -ve/0/+ve value we need.

This leads to incorrect reports about overlaps, eg:

  ibm,slw-image@1ffe600000 (0x0000001ffe600000--0x0000001ffe700000) overlaps with
  ibm,firmware-allocs-memory@1000000000 (0x0000001000000000--0x0000001000dc0200)

Fix it by just doing the standard double if and return 0 logic.

Fixes: ae1add247bf8 ("of: Check for overlap in reserved memory regions")
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 drivers/of/of_reserved_mem.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index be77e75c587d..1a3556a9e9ea 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -206,7 +206,13 @@ static int __init __rmem_cmp(const void *a, const void *b)
 {
 	const struct reserved_mem *ra = a, *rb = b;
 
-	return ra->base - rb->base;
+	if (ra->base < rb->base)
+		return -1;
+
+	if (ra->base > rb->base)
+		return 1;
+
+	return 0;
 }
 
 static void __init __rmem_check_for_overlap(void)
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] of: Fix comparison of reserved memory regions
  2015-11-18 10:46 [PATCH] of: Fix comparison of reserved memory regions Michael Ellerman
@ 2015-12-04 17:07 ` Mitchel Humpherys
  2015-12-05 11:43   ` Michael Ellerman
  0 siblings, 1 reply; 5+ messages in thread
From: Mitchel Humpherys @ 2015-12-04 17:07 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: robh+dt, devicetree, linux-kernel, linuxppc-dev, frowand.list,
	grant.likely

On Wed, Nov 18 2015 at 09:46:38 PM, Michael Ellerman <mpe@ellerman.id.au> wrote:
> In order to check for overlapping reserved memory regions, we first need
> to sort the array of memory regions. This is implemented using sort(),
> and a custom comparison function __rmem_cmp().
>
> Unfortunatley __rmem_cmp() doesn't work in all cases. Because the two
> base values are phys_addr_t, they may be u64 on some platforms, in which
> case subtracting one from the other and then (implicitly) casting to int
> does not give us the -ve/0/+ve value we need.
>
> This leads to incorrect reports about overlaps, eg:
>
>   ibm,slw-image@1ffe600000 (0x0000001ffe600000--0x0000001ffe700000) overlaps with
>   ibm,firmware-allocs-memory@1000000000 (0x0000001000000000--0x0000001000dc0200)
>
> Fix it by just doing the standard double if and return 0 logic.
>
> Fixes: ae1add247bf8 ("of: Check for overlap in reserved memory regions")
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> ---
>  drivers/of/of_reserved_mem.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)

Woops, thanks.

Tested-by: Mitchel Humpherys <mitchelh@codeaurora.org>

-Mitch

-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] of: Fix comparison of reserved memory regions
  2015-12-04 17:07 ` Mitchel Humpherys
@ 2015-12-05 11:43   ` Michael Ellerman
  2015-12-06 20:31     ` Rob Herring
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Ellerman @ 2015-12-05 11:43 UTC (permalink / raw)
  To: Mitchel Humpherys
  Cc: robh+dt, devicetree, linux-kernel, linuxppc-dev, frowand.list,
	grant.likely



On 5 December 2015 04:07:39 GMT+11:00, Mitchel Humpherys <mitchelh@codeaurora.org> wrote:
>On Wed, Nov 18 2015 at 09:46:38 PM, Michael Ellerman
><mpe@ellerman.id.au> wrote:
>> In order to check for overlapping reserved memory regions, we first
>need
>> to sort the array of memory regions. This is implemented using
>sort(),
>> and a custom comparison function __rmem_cmp().
>>
>> Unfortunatley __rmem_cmp() doesn't work in all cases. Because the two
>> base values are phys_addr_t, they may be u64 on some platforms, in
>which
>> case subtracting one from the other and then (implicitly) casting to
>int
>> does not give us the -ve/0/+ve value we need.
>>
>> This leads to incorrect reports about overlaps, eg:
>>
>>   ibm,slw-image@1ffe600000 (0x0000001ffe600000--0x0000001ffe700000)
>overlaps with
>>   ibm,firmware-allocs-memory@1000000000
>(0x0000001000000000--0x0000001000dc0200)
>>
>> Fix it by just doing the standard double if and return 0 logic.
>>
>> Fixes: ae1add247bf8 ("of: Check for overlap in reserved memory
>regions")
>> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
>> ---
>>  drivers/of/of_reserved_mem.c | 8 +++++++-
>>  1 file changed, 7 insertions(+), 1 deletion(-)
>
>Woops, thanks.
>
>Tested-by: Mitchel Humpherys <mitchelh@codeaurora.org>

Thanks for testing.

Rob, can we get this merged for 4.4 please?

cheers 

-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] of: Fix comparison of reserved memory regions
  2015-12-05 11:43   ` Michael Ellerman
@ 2015-12-06 20:31     ` Rob Herring
  2015-12-06 23:33       ` Michael Ellerman
  0 siblings, 1 reply; 5+ messages in thread
From: Rob Herring @ 2015-12-06 20:31 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: Mitchel Humpherys, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linuxppc-dev, Frank Rowand,
	Grant Likely

On Sat, Dec 5, 2015 at 5:43 AM, Michael Ellerman <michael@ellerman.id.au> wrote:
>
>
> On 5 December 2015 04:07:39 GMT+11:00, Mitchel Humpherys <mitchelh@codeaurora.org> wrote:
>>On Wed, Nov 18 2015 at 09:46:38 PM, Michael Ellerman
>><mpe@ellerman.id.au> wrote:
>>> In order to check for overlapping reserved memory regions, we first
>>need
>>> to sort the array of memory regions. This is implemented using
>>sort(),
>>> and a custom comparison function __rmem_cmp().
>>>
>>> Unfortunatley __rmem_cmp() doesn't work in all cases. Because the two
>>> base values are phys_addr_t, they may be u64 on some platforms, in
>>which
>>> case subtracting one from the other and then (implicitly) casting to
>>int
>>> does not give us the -ve/0/+ve value we need.
>>>
>>> This leads to incorrect reports about overlaps, eg:
>>>
>>>   ibm,slw-image@1ffe600000 (0x0000001ffe600000--0x0000001ffe700000)
>>overlaps with
>>>   ibm,firmware-allocs-memory@1000000000
>>(0x0000001000000000--0x0000001000dc0200)
>>>
>>> Fix it by just doing the standard double if and return 0 logic.
>>>
>>> Fixes: ae1add247bf8 ("of: Check for overlap in reserved memory
>>regions")
>>> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
>>> ---
>>>  drivers/of/of_reserved_mem.c | 8 +++++++-
>>>  1 file changed, 7 insertions(+), 1 deletion(-)
>>
>>Woops, thanks.
>>
>>Tested-by: Mitchel Humpherys <mitchelh@codeaurora.org>
>
> Thanks for testing.
>
> Rob, can we get this merged for 4.4 please?

Yes. I meant to last week, but was waiting on getting another issue
sorted out. I should get it to Linus in the next couple of days.

Rob

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] of: Fix comparison of reserved memory regions
  2015-12-06 20:31     ` Rob Herring
@ 2015-12-06 23:33       ` Michael Ellerman
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2015-12-06 23:33 UTC (permalink / raw)
  To: Rob Herring
  Cc: devicetree@vger.kernel.org, Frank Rowand,
	linux-kernel@vger.kernel.org, linuxppc-dev, Grant Likely,
	Mitchel Humpherys

On Sun, 2015-12-06 at 14:31 -0600, Rob Herring wrote:
> On Sat, Dec 5, 2015 at 5:43 AM, Michael Ellerman <michael@ellerman.id.au> wrote:
> > On 5 December 2015 04:07:39 GMT+11:00, Mitchel Humpherys <mitchelh@codeaurora.org> wrote:
> > > On Wed, Nov 18 2015 at 09:46:38 PM, Michael Ellerman
> > > <mpe@ellerman.id.au> wrote:
> > > > Fix it by just doing the standard double if and return 0 logic.
> > > > 
> > > > Fixes: ae1add247bf8 ("of: Check for overlap in reserved memory
> > > regions")
> > > 
> > > Woops, thanks.
> > > 
> > > Tested-by: Mitchel Humpherys <mitchelh@codeaurora.org>
> > 
> > Thanks for testing.
> > 
> > Rob, can we get this merged for 4.4 please?
> 
> Yes. I meant to last week, but was waiting on getting another issue
> sorted out. I should get it to Linus in the next couple of days.

Sure thing. No great rush but would be nice for it to be fixed before 4.4
releases.

cheers

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-12-06 23:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-18 10:46 [PATCH] of: Fix comparison of reserved memory regions Michael Ellerman
2015-12-04 17:07 ` Mitchel Humpherys
2015-12-05 11:43   ` Michael Ellerman
2015-12-06 20:31     ` Rob Herring
2015-12-06 23:33       ` Michael Ellerman

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).