Skip to contentSkip to conversation

ARM: mm: fix size rounding-down of arm_add_memory() function

PATCH In review Masahiro Yamada 2 participants 3 messages Dec 22, 2014 – Jan 14, 2015 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ARM: mm: fix size rounding-down of arm_add_memory() function

The current rounding of "size" is wrong:

- If "start" is sufficiently near the next page boundary, "size" is decremented by more than enough and the last page is lost.

- If "size" is sufficiently small, it is wrapped around and gets a bogus value.

---

Changes in v2:
- Avoid wrap around of "size"

 arch/arm/kernel/setup.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
arch/arm/kernel/setup.c +5 -2
index f9c8639..d13f185 100644
@@ -657,10 +657,13 @@ int __init arm_add_memory(u64 start, u64 size)
 
 	/*
 	 * Ensure that start/size are aligned to a page boundary.
-	 * Size is appropriately rounded down, start is rounded up.
+	 * Size is rounded down, start is rounded up.
 	 */
-	size -= start & ~PAGE_MASK;
 	aligned_start = PAGE_ALIGN(start);
+	if (aligned_start > start + size)
+		size = 0;
+	else
+		size -= aligned_start - start;
 
 #ifndef CONFIG_ARCH_PHYS_ADDR_T_64BIT
 	if (aligned_start > ULONG_MAX) {
Signature · 1 line
1.9.1
Acked-by on v2 1/1
#1 lore raw
Quoted 10 lines · Masahiro Yamada

The current rounding of "size" is wrong:

- If "start" is sufficiently near the next page boundary, "size" is decremented by more than enough and the last page is lost.

- If "size" is sufficiently small, it is wrapped around and gets a bogus value.

Quoted 31 lines

---

Changes in v2:
- Avoid wrap around of "size"

 arch/arm/kernel/setup.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
arch/arm/kernel/setup.c +5 -3
index f9c8639..d13f185 100644
@@ -657,10 +657,13 @@ int __init arm_add_memory(u64 start, u64 size)
 
        /*
         * Ensure that start/size are aligned to a page boundary.
-        * Size is appropriately rounded down, start is rounded up.
+        * Size is rounded down, start is rounded up.
         */
-       size -= start & ~PAGE_MASK;
        aligned_start = PAGE_ALIGN(start);
+       if (aligned_start > start + size)
+               size = 0;
+       else
+               size -= aligned_start - start;
 
 #ifndef CONFIG_ARCH_PHYS_ADDR_T_64BIT
        if (aligned_start > ULONG_MAX) {
--

1.9.1

#2 lore raw

Hello Russell King,

Could you apply this patch for arm_add_memory() fix, please ?

Thanks,
Masahiro Yamada

Quoted 51 lines · On Mon, 22 Dec 2014 10:09:32 +0100 Ard Biesheuvel <[email protected]>…
Quoted 10 lines · Masahiro Yamada

The current rounding of "size" is wrong:

- If "start" is sufficiently near the next page boundary, "size" is decremented by more than enough and the last page is lost.

- If "size" is sufficiently small, it is wrapped around and gets a bogus value.

Quoted 29 lines

---

Changes in v2:
- Avoid wrap around of "size"

 arch/arm/kernel/setup.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
arch/arm/kernel/setup.c +5 -3
index f9c8639..d13f185 100644
@@ -657,10 +657,13 @@ int __init arm_add_memory(u64 start, u64 size)
 
        /*
         * Ensure that start/size are aligned to a page boundary.
-        * Size is appropriately rounded down, start is rounded up.
+        * Size is rounded down, start is rounded up.
         */
-       size -= start & ~PAGE_MASK;
        aligned_start = PAGE_ALIGN(start);
+       if (aligned_start > start + size)
+               size = 0;
+       else
+               size -= aligned_start - start;
 
 #ifndef CONFIG_ARCH_PHYS_ADDR_T_64BIT
        if (aligned_start > ULONG_MAX) {
--
Quoted 2 lines

1.9.1

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel