All of lore.kernel.org
 help / color / mirror / Atom feed
From: Magnus Damm <magnus.damm@gmail.com>
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 02/03] ARM: Handle 64-bit memory in case of 32-bit phys_addr_t
Date: Wed, 05 Jun 2013 10:44:46 +0000	[thread overview]
Message-ID: <20130605104446.1720.12461.sendpatchset@w520> (raw)
In-Reply-To: <20130605104427.1720.68752.sendpatchset@w520>

From: Magnus Damm <damm@opensource.se>

Use CONFIG_ARCH_PHYS_ADDR_T_64BIT to determine
if ignoring or truncating of memory banks is
neccessary. This may be needed in the case of
64-bit memory bank addresses but when phys_addr_t
is kept 32-bit.

Signed-off-by: Magnus Damm <damm@opensource.se>
---

 Ignoring case tested on APE6EVM in cases when
 HIGHMEM=y/n and LPAE=y/n. Truncating not tested.

 arch/arm/kernel/setup.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

--- 0003/arch/arm/kernel/setup.c
+++ work/arch/arm/kernel/setup.c	2013-06-05 19:08:17.000000000 +0900
@@ -530,6 +530,7 @@ void __init dump_machine_table(void)
 int __init arm_add_memory(u64 start, u64 size)
 {
 	struct membank *bank = &meminfo.bank[meminfo.nr_banks];
+	u64 aligned_start;
 
 	if (meminfo.nr_banks >= NR_BANKS) {
 		printk(KERN_CRIT "NR_BANKS too low, "
@@ -542,10 +543,16 @@ int __init arm_add_memory(u64 start, u64
 	 * Size is appropriately rounded down, start is rounded up.
 	 */
 	size -= start & ~PAGE_MASK;
-	bank->start = PAGE_ALIGN(start);
+	aligned_start = PAGE_ALIGN(start);
 
-#ifndef CONFIG_ARM_LPAE
-	if (bank->start + size < bank->start) {
+#ifndef CONFIG_ARCH_PHYS_ADDR_T_64BIT
+	if (aligned_start > ULONG_MAX) {
+		printk(KERN_CRIT "Ignoring memory at 0x%08llx outside "
+		       "32-bit physical address space\n", (long long)start);
+		return -EINVAL;
+	}
+
+	if (aligned_start + size > ULONG_MAX) {
 		printk(KERN_CRIT "Truncating memory at 0x%08llx to fit in "
 			"32-bit physical address space\n", (long long)start);
 		/*
@@ -553,10 +560,11 @@ int __init arm_add_memory(u64 start, u64
 		 * 32 bits, we use ULONG_MAX as the upper limit rather than 4GB.
 		 * This means we lose a page after masking.
 		 */
-		size = ULONG_MAX - bank->start;
+		size = ULONG_MAX - aligned_start;
 	}
 #endif
 
+	bank->start = aligned_start;
 	bank->size = size & ~(phys_addr_t)(PAGE_SIZE - 1);
 
 	/*

WARNING: multiple messages have this Message-ID (diff)
From: magnus.damm@gmail.com (Magnus Damm)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 02/03] ARM: Handle 64-bit memory in case of 32-bit phys_addr_t
Date: Wed, 05 Jun 2013 19:44:46 +0900	[thread overview]
Message-ID: <20130605104446.1720.12461.sendpatchset@w520> (raw)
In-Reply-To: <20130605104427.1720.68752.sendpatchset@w520>

From: Magnus Damm <damm@opensource.se>

Use CONFIG_ARCH_PHYS_ADDR_T_64BIT to determine
if ignoring or truncating of memory banks is
neccessary. This may be needed in the case of
64-bit memory bank addresses but when phys_addr_t
is kept 32-bit.

Signed-off-by: Magnus Damm <damm@opensource.se>
---

 Ignoring case tested on APE6EVM in cases when
 HIGHMEM=y/n and LPAE=y/n. Truncating not tested.

 arch/arm/kernel/setup.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

--- 0003/arch/arm/kernel/setup.c
+++ work/arch/arm/kernel/setup.c	2013-06-05 19:08:17.000000000 +0900
@@ -530,6 +530,7 @@ void __init dump_machine_table(void)
 int __init arm_add_memory(u64 start, u64 size)
 {
 	struct membank *bank = &meminfo.bank[meminfo.nr_banks];
+	u64 aligned_start;
 
 	if (meminfo.nr_banks >= NR_BANKS) {
 		printk(KERN_CRIT "NR_BANKS too low, "
@@ -542,10 +543,16 @@ int __init arm_add_memory(u64 start, u64
 	 * Size is appropriately rounded down, start is rounded up.
 	 */
 	size -= start & ~PAGE_MASK;
-	bank->start = PAGE_ALIGN(start);
+	aligned_start = PAGE_ALIGN(start);
 
-#ifndef CONFIG_ARM_LPAE
-	if (bank->start + size < bank->start) {
+#ifndef CONFIG_ARCH_PHYS_ADDR_T_64BIT
+	if (aligned_start > ULONG_MAX) {
+		printk(KERN_CRIT "Ignoring memory at 0x%08llx outside "
+		       "32-bit physical address space\n", (long long)start);
+		return -EINVAL;
+	}
+
+	if (aligned_start + size > ULONG_MAX) {
 		printk(KERN_CRIT "Truncating memory at 0x%08llx to fit in "
 			"32-bit physical address space\n", (long long)start);
 		/*
@@ -553,10 +560,11 @@ int __init arm_add_memory(u64 start, u64
 		 * 32 bits, we use ULONG_MAX as the upper limit rather than 4GB.
 		 * This means we lose a page after masking.
 		 */
-		size = ULONG_MAX - bank->start;
+		size = ULONG_MAX - aligned_start;
 	}
 #endif
 
+	bank->start = aligned_start;
 	bank->size = size & ~(phys_addr_t)(PAGE_SIZE - 1);
 
 	/*

  parent reply	other threads:[~2013-06-05 10:44 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-05 10:44 [PATCH 00/03] ARM: 64-bit memory fixes, APE6EVM second memory bank Magnus Damm
2013-06-05 10:44 ` Magnus Damm
2013-06-05 10:44 ` [PATCH 01/03] ARM: Let arm_add_memory() always use 64-bit arguments Magnus Damm
2013-06-05 10:44   ` Magnus Damm
2013-06-05 10:44 ` Magnus Damm [this message]
2013-06-05 10:44   ` [PATCH 02/03] ARM: Handle 64-bit memory in case of 32-bit phys_addr_t Magnus Damm
2013-06-05 10:44 ` [PATCH 03/03] ARM: shmobile: Add second memory bank to DTS for APE6EVM Magnus Damm
2013-06-05 10:44   ` Magnus Damm
2013-06-05 11:17 ` [PATCH 00/03] ARM: 64-bit memory fixes, APE6EVM second memory bank Arnd Bergmann
2013-06-05 11:17   ` Arnd Bergmann
2013-06-12 10:57   ` Magnus Damm
2013-06-12 10:57     ` Magnus Damm
2013-06-12 12:41     ` Arnd Bergmann
2013-06-12 12:41       ` Arnd Bergmann
2013-07-02  5:52       ` Magnus Damm
2013-07-02  5:52         ` Magnus Damm
2013-06-17 12:44 ` Guennadi Liakhovetski
2013-06-17 12:44   ` Guennadi Liakhovetski

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=20130605104446.1720.12461.sendpatchset@w520 \
    --to=magnus.damm@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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.