* [PATCH] mm: cma: fix CMA aligned offset calculation
@ 2015-02-24 19:55 Danesh Petigara
2015-02-24 20:54 ` Gregory Fong
2015-02-24 21:10 ` Michal Nazarewicz
0 siblings, 2 replies; 4+ messages in thread
From: Danesh Petigara @ 2015-02-24 19:55 UTC (permalink / raw)
To: akpm
Cc: m.szyprowski, mina86, iamjoonsoo.kim, aneesh.kumar,
laurent.pinchart+renesas, gregory.0xf0, linux-mm, linux-kernel,
Danesh Petigara, stable
The CMA aligned offset calculation is incorrect for
non-zero order_per_bit values.
For example, if cma->order_per_bit=1, cma->base_pfn=
0x2f800000 and align_order=12, the function returns
a value of 0x17c00 instead of 0x400.
This patch fixes the CMA aligned offset calculation.
Cc: stable@vger.kernel.org
Signed-off-by: Danesh Petigara <dpetigara@broadcom.com>
Reviewed-by: Gregory Fong <gregory.0xf0@gmail.com>
---
mm/cma.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/mm/cma.c b/mm/cma.c
index 75016fd..58f37bd 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -70,9 +70,13 @@ static unsigned long cma_bitmap_aligned_offset(struct cma *cma, int align_order)
if (align_order <= cma->order_per_bit)
return 0;
- alignment = 1UL << (align_order - cma->order_per_bit);
- return ALIGN(cma->base_pfn, alignment) -
- (cma->base_pfn >> cma->order_per_bit);
+
+ /*
+ * Find a PFN aligned to the specified order and return
+ * an offset represented in order_per_bits.
+ */
+ return (ALIGN(cma->base_pfn, (1UL << align_order))
+ - cma->base_pfn) >> cma->order_per_bit;
}
static unsigned long cma_bitmap_maxno(struct cma *cma)
--
1.9.1
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm: cma: fix CMA aligned offset calculation
2015-02-24 19:55 [PATCH] mm: cma: fix CMA aligned offset calculation Danesh Petigara
@ 2015-02-24 20:54 ` Gregory Fong
2015-02-24 21:10 ` Michal Nazarewicz
1 sibling, 0 replies; 4+ messages in thread
From: Gregory Fong @ 2015-02-24 20:54 UTC (permalink / raw)
To: Danesh Petigara
Cc: Andrew Morton, Marek Szyprowski, Michal Nazarewicz, Joonsoo Kim,
Aneesh Kumar K.V, Laurent Pinchart, linux-mm, linux-kernel
[removed stable from cc]
On Tue, Feb 24, 2015 at 11:55 AM, Danesh Petigara
<dpetigara@broadcom.com> wrote:
> diff --git a/mm/cma.c b/mm/cma.c
> index 75016fd..58f37bd 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -70,9 +70,13 @@ static unsigned long cma_bitmap_aligned_offset(struct cma *cma, int align_order)
>
> if (align_order <= cma->order_per_bit)
> return 0;
> - alignment = 1UL << (align_order - cma->order_per_bit);
> - return ALIGN(cma->base_pfn, alignment) -
> - (cma->base_pfn >> cma->order_per_bit);
> +
> + /*
> + * Find a PFN aligned to the specified order and return
> + * an offset represented in order_per_bits.
> + */
> + return (ALIGN(cma->base_pfn, (1UL << align_order))
> + - cma->base_pfn) >> cma->order_per_bit;
It was noticed that this doesn't remove the now-unused 'alignment'
variable, so I think Danesh is planning to submit an updated patch.
Best regards,
Gregory
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm: cma: fix CMA aligned offset calculation
2015-02-24 19:55 [PATCH] mm: cma: fix CMA aligned offset calculation Danesh Petigara
2015-02-24 20:54 ` Gregory Fong
@ 2015-02-24 21:10 ` Michal Nazarewicz
2015-02-24 21:43 ` Danesh Petigara
1 sibling, 1 reply; 4+ messages in thread
From: Michal Nazarewicz @ 2015-02-24 21:10 UTC (permalink / raw)
To: Danesh Petigara, akpm
Cc: m.szyprowski, iamjoonsoo.kim, aneesh.kumar,
laurent.pinchart+renesas, gregory.0xf0, linux-mm, linux-kernel,
stable
On Tue, Feb 24 2015, Danesh Petigara <dpetigara@broadcom.com> wrote:
> The CMA aligned offset calculation is incorrect for
> non-zero order_per_bit values.
>
> For example, if cma->order_per_bit=1, cma->base_pfn=
> 0x2f800000 and align_order=12, the function returns
> a value of 0x17c00 instead of 0x400.
>
> This patch fixes the CMA aligned offset calculation.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Danesh Petigara <dpetigara@broadcom.com>
> Reviewed-by: Gregory Fong <gregory.0xf0@gmail.com>
Acked-by: Michal Nazarewicz <mina86@mina86.com>
> ---
> mm/cma.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/mm/cma.c b/mm/cma.c
> index 75016fd..58f37bd 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -70,9 +70,13 @@ static unsigned long cma_bitmap_aligned_offset(struct cma *cma, int align_order)
>
> if (align_order <= cma->order_per_bit)
> return 0;
> - alignment = 1UL << (align_order - cma->order_per_bit);
> - return ALIGN(cma->base_pfn, alignment) -
> - (cma->base_pfn >> cma->order_per_bit);
> +
> + /*
> + * Find a PFN aligned to the specified order and return
> + * an offset represented in order_per_bits.
> + */
It probably makes sense to move this comment outside of the function as
function documentation.
> + return (ALIGN(cma->base_pfn, (1UL << align_order))
> + - cma->base_pfn) >> cma->order_per_bit;
> }
>
> static unsigned long cma_bitmap_maxno(struct cma *cma)
> --
> 1.9.1
>
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michał “mina86” Nazarewicz (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm: cma: fix CMA aligned offset calculation
2015-02-24 21:10 ` Michal Nazarewicz
@ 2015-02-24 21:43 ` Danesh Petigara
0 siblings, 0 replies; 4+ messages in thread
From: Danesh Petigara @ 2015-02-24 21:43 UTC (permalink / raw)
To: Michal Nazarewicz, akpm
Cc: m.szyprowski, iamjoonsoo.kim, aneesh.kumar,
laurent.pinchart+renesas, gregory.0xf0, linux-mm, linux-kernel,
stable
On 2/24/2015 1:10 PM, Michal Nazarewicz wrote:
> On Tue, Feb 24 2015, Danesh Petigara <dpetigara@broadcom.com> wrote:
>> The CMA aligned offset calculation is incorrect for
>> non-zero order_per_bit values.
>>
>> For example, if cma->order_per_bit=1, cma->base_pfn=
>> 0x2f800000 and align_order=12, the function returns
>> a value of 0x17c00 instead of 0x400.
>>
>> This patch fixes the CMA aligned offset calculation.
>>
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Danesh Petigara <dpetigara@broadcom.com>
>> Reviewed-by: Gregory Fong <gregory.0xf0@gmail.com>
>
> Acked-by: Michal Nazarewicz <mina86@mina86.com>
>
>> ---
>> mm/cma.c | 10 +++++++---
>> 1 file changed, 7 insertions(+), 3 deletions(-)
>>
>> diff --git a/mm/cma.c b/mm/cma.c
>> index 75016fd..58f37bd 100644
>> --- a/mm/cma.c
>> +++ b/mm/cma.c
>> @@ -70,9 +70,13 @@ static unsigned long cma_bitmap_aligned_offset(struct cma *cma, int align_order)
>>
>> if (align_order <= cma->order_per_bit)
>> return 0;
>> - alignment = 1UL << (align_order - cma->order_per_bit);
>> - return ALIGN(cma->base_pfn, alignment) -
>> - (cma->base_pfn >> cma->order_per_bit);
>> +
>> + /*
>> + * Find a PFN aligned to the specified order and return
>> + * an offset represented in order_per_bits.
>> + */
>
> It probably makes sense to move this comment outside of the function as
> function documentation.
>
Thanks for the feedback. Will send out patch v2 with the comment moved
outside the function and also remove the unused 'alignment' variable.
>> + return (ALIGN(cma->base_pfn, (1UL << align_order))
>> + - cma->base_pfn) >> cma->order_per_bit;
>> }
>>
>> static unsigned long cma_bitmap_maxno(struct cma *cma)
>> --
>> 1.9.1
>>
>
Best regards,
Danesh Petigara
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-02-24 21:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-24 19:55 [PATCH] mm: cma: fix CMA aligned offset calculation Danesh Petigara
2015-02-24 20:54 ` Gregory Fong
2015-02-24 21:10 ` Michal Nazarewicz
2015-02-24 21:43 ` Danesh Petigara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox