linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND 0/3] mm, x86: Fix ioremap RAM check interfaces
@ 2015-07-16 23:23 Toshi Kani
  2015-07-16 23:23 ` [PATCH RESEND 1/3] mm, x86: Fix warning in ioremap RAM check Toshi Kani
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Toshi Kani @ 2015-07-16 23:23 UTC (permalink / raw)
  To: tglx, mingo, hpa, akpm
  Cc: travis, roland, dan.j.williams, mcgrof, x86, linux-kernel,
	linux-mm

ioremap() checks if a target range is in RAM and fails the request
if true.  There are multiple issues in the iormap RAM check interfaces.

 1. region_is_ram() always fails with -1.
 2. The check calls two functions, region_is_ram() and
    walk_system_ram_range(), which are redundant as both walk the
    same iomem_resource table.
 3. walk_system_ram_range() requires RAM ranges be page-aligned in
    the iomem_resource table to work properly.  This restriction
    has allowed multiple ioremaps to RAM which are page-unaligned.

This patchset solves issue 1 and 2.  It does not address issue 3,
but continues to allow the existing ioremaps to work until it is
addressed.

---
resend:
 - Rebased to 4.2-rc2 (no change needed). Modified change logs.

---
Toshi Kani (3):
  1/3 mm, x86: Fix warning in ioremap RAM check
  2/3 mm, x86: Remove region_is_ram() call from ioremap
  3/3 mm: Fix bugs in region_is_ram()

---
 arch/x86/mm/ioremap.c | 23 ++++++-----------------
 kernel/resource.c     |  6 +++---
 2 files changed, 9 insertions(+), 20 deletions(-)

--
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] 7+ messages in thread

* [PATCH RESEND 1/3] mm, x86: Fix warning in ioremap RAM check
  2015-07-16 23:23 [PATCH RESEND 0/3] mm, x86: Fix ioremap RAM check interfaces Toshi Kani
@ 2015-07-16 23:23 ` Toshi Kani
  2015-07-16 23:23 ` [PATCH RESEND 2/3] mm, x86: Remove region_is_ram() call from ioremap Toshi Kani
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Toshi Kani @ 2015-07-16 23:23 UTC (permalink / raw)
  To: tglx, mingo, hpa, akpm
  Cc: travis, roland, dan.j.williams, mcgrof, x86, linux-kernel,
	linux-mm, Toshi Kani, Borislav Petkov

__ioremap_caller() calls __ioremap_check_ram() through
walk_system_ram_range() to check if a target range is in RAM.
__ioremap_check_ram() has WARN_ONCE() in a wrong place where
it warns when the given range is not RAM.  This misplaced
warning is not exposed since walk_system_ram_range() only
calls __ioremap_check_ram() for RAM ranges.

Move the WARN_ONCE() to __ioremap_caller(), and update the
message to include the address range.

Signed-off-by: Toshi Kani <toshi.kani@hp.com>
Cc: Roland Dreier <roland@purestorage.com>
Cc: Luis R. Rodriguez <mcgrof@suse.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
---
 arch/x86/mm/ioremap.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index cc5ccc4..fd3df0d 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -63,8 +63,6 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
 		    !PageReserved(pfn_to_page(start_pfn + i)))
 			return 1;
 
-	WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
-
 	return 0;
 }
 
@@ -131,8 +129,11 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
 		pfn      = phys_addr >> PAGE_SHIFT;
 		last_pfn = last_addr >> PAGE_SHIFT;
 		if (walk_system_ram_range(pfn, last_pfn - pfn + 1, NULL,
-					  __ioremap_check_ram) == 1)
+					  __ioremap_check_ram) == 1) {
+			WARN_ONCE(1, "ioremap on RAM at 0x%llx - 0x%llx\n",
+					phys_addr, last_addr);
 			return NULL;
+		}
 	}
 	/*
 	 * Mappings have to be page-aligned

--
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 related	[flat|nested] 7+ messages in thread

* [PATCH RESEND 2/3] mm, x86: Remove region_is_ram() call from ioremap
  2015-07-16 23:23 [PATCH RESEND 0/3] mm, x86: Fix ioremap RAM check interfaces Toshi Kani
  2015-07-16 23:23 ` [PATCH RESEND 1/3] mm, x86: Fix warning in ioremap RAM check Toshi Kani
@ 2015-07-16 23:23 ` Toshi Kani
  2015-07-21 14:31   ` Thomas Gleixner
  2015-07-16 23:23 ` [PATCH RESEND 3/3] mm: Fix bugs in region_is_ram() Toshi Kani
  2015-07-18  1:23 ` [PATCH RESEND 0/3] mm, x86: Fix ioremap RAM check interfaces Dan Williams
  3 siblings, 1 reply; 7+ messages in thread
From: Toshi Kani @ 2015-07-16 23:23 UTC (permalink / raw)
  To: tglx, mingo, hpa, akpm
  Cc: travis, roland, dan.j.williams, mcgrof, x86, linux-kernel,
	linux-mm, Toshi Kani, Borislav Petkov

__ioremap_caller() calls region_is_ram() to walk through the
iomem_resource table to check if a target range is in RAM, which
was added to improve the lookup performance over page_is_ram()
(commit 906e36c5c717 "x86: use optimized ioresource lookup in
ioremap function").  page_is_ram() was no longer used when this
change was added, though.

__ioremap_caller() then calls walk_system_ram_range(), which had
replaced page_is_ram() to improve the lookup performance (commit
c81c8a1eeede "x86, ioremap: Speed up check for RAM pages").

Since both checks walk through the same iomem_resource table for
the same purpose, there is no need to call the two functions.
Furthermore, region_is_ram() always returns with -1, which makes
walk_system_ram_range() as the only check being used at this point.

Therefore, this patch changes __ioremap_caller() to call
walk_system_ram_range() only.

Note, removing the call to region_is_ram() is also necessary to
fix bugs in region_is_ram().  walk_system_ram_range() requires
RAM ranges be page-aligned in the iomem_resource table to work
properly.  This restriction has allowed multiple ioremaps to RAM
(setup_data) which are page-unaligned.  Using fixed region_is_ram()
will cause these callers to start failing.  After all ioremap
callers to setup_data are converted, __ioremap_caller() may call
region_is_ram() instead to remove this restriction.

Signed-off-by: Toshi Kani <toshi.kani@hp.com>
Cc: Roland Dreier <roland@purestorage.com>
Cc: Mike Travis <travis@sgi.com>
Cc: Luis R. Rodriguez <mcgrof@suse.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
---
 arch/x86/mm/ioremap.c |   24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index fd3df0d..b9d4a33 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -92,7 +92,6 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
 	pgprot_t prot;
 	int retval;
 	void __iomem *ret_addr;
-	int ram_region;
 
 	/* Don't allow wraparound or zero size */
 	last_addr = phys_addr + size - 1;
@@ -115,26 +114,15 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
 	/*
 	 * Don't allow anybody to remap normal RAM that we're using..
 	 */
-	/* First check if whole region can be identified as RAM or not */
-	ram_region = region_is_ram(phys_addr, size);
-	if (ram_region > 0) {
-		WARN_ONCE(1, "ioremap on RAM at 0x%lx - 0x%lx\n",
-				(unsigned long int)phys_addr,
-				(unsigned long int)last_addr);
-		return NULL;
-	}
-
-	/* If could not be identified(-1), check page by page */
-	if (ram_region < 0) {
-		pfn      = phys_addr >> PAGE_SHIFT;
-		last_pfn = last_addr >> PAGE_SHIFT;
-		if (walk_system_ram_range(pfn, last_pfn - pfn + 1, NULL,
+	pfn      = phys_addr >> PAGE_SHIFT;
+	last_pfn = last_addr >> PAGE_SHIFT;
+	if (walk_system_ram_range(pfn, last_pfn - pfn + 1, NULL,
 					  __ioremap_check_ram) == 1) {
-			WARN_ONCE(1, "ioremap on RAM at 0x%llx - 0x%llx\n",
+		WARN_ONCE(1, "ioremap on RAM at 0x%llx - 0x%llx\n",
 					phys_addr, last_addr);
-			return NULL;
-		}
+		return NULL;
 	}
+
 	/*
 	 * Mappings have to be page-aligned
 	 */

--
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 related	[flat|nested] 7+ messages in thread

* [PATCH RESEND 3/3] mm: Fix bugs in region_is_ram()
  2015-07-16 23:23 [PATCH RESEND 0/3] mm, x86: Fix ioremap RAM check interfaces Toshi Kani
  2015-07-16 23:23 ` [PATCH RESEND 1/3] mm, x86: Fix warning in ioremap RAM check Toshi Kani
  2015-07-16 23:23 ` [PATCH RESEND 2/3] mm, x86: Remove region_is_ram() call from ioremap Toshi Kani
@ 2015-07-16 23:23 ` Toshi Kani
  2015-07-18  1:23 ` [PATCH RESEND 0/3] mm, x86: Fix ioremap RAM check interfaces Dan Williams
  3 siblings, 0 replies; 7+ messages in thread
From: Toshi Kani @ 2015-07-16 23:23 UTC (permalink / raw)
  To: tglx, mingo, hpa, akpm
  Cc: travis, roland, dan.j.williams, mcgrof, x86, linux-kernel,
	linux-mm, Toshi Kani

region_is_ram() looks up the iomem_resource table to check if
a target range is in RAM.  However, it always returns with -1
due to invalid range checks.  It always breaks the loop at the
first entry of the table.

Another issue is that it compares p->flags and flags, but it
always fails.  The flags is declared as int, which makes it as
a negative value with IORESOURCE_BUSY (0x80000000) set while
p->flags is unsigned long.

Fix the range check and flags so that region_is_ram() works as
advertised.

Signed-off-by: Toshi Kani <toshi.kani@hp.com>
Cc: Mike Travis <travis@sgi.com>
Cc: Luis R. Rodriguez <mcgrof@suse.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 kernel/resource.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/resource.c b/kernel/resource.c
index 90552aa..fed052a 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -504,13 +504,13 @@ int region_is_ram(resource_size_t start, unsigned long size)
 {
 	struct resource *p;
 	resource_size_t end = start + size - 1;
-	int flags = IORESOURCE_MEM | IORESOURCE_BUSY;
+	unsigned long flags = IORESOURCE_MEM | IORESOURCE_BUSY;
 	const char *name = "System RAM";
 	int ret = -1;
 
 	read_lock(&resource_lock);
 	for (p = iomem_resource.child; p ; p = p->sibling) {
-		if (end < p->start)
+		if (p->end < start)
 			continue;
 
 		if (p->start <= start && end <= p->end) {
@@ -521,7 +521,7 @@ int region_is_ram(resource_size_t start, unsigned long size)
 				ret = 1;
 			break;
 		}
-		if (p->end < start)
+		if (end < p->start)
 			break;	/* not found */
 	}
 	read_unlock(&resource_lock);

--
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 related	[flat|nested] 7+ messages in thread

* Re: [PATCH RESEND 0/3] mm, x86: Fix ioremap RAM check interfaces
  2015-07-16 23:23 [PATCH RESEND 0/3] mm, x86: Fix ioremap RAM check interfaces Toshi Kani
                   ` (2 preceding siblings ...)
  2015-07-16 23:23 ` [PATCH RESEND 3/3] mm: Fix bugs in region_is_ram() Toshi Kani
@ 2015-07-18  1:23 ` Dan Williams
  3 siblings, 0 replies; 7+ messages in thread
From: Dan Williams @ 2015-07-18  1:23 UTC (permalink / raw)
  To: Toshi Kani
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Andrew Morton,
	travis, roland, Luis Rodriguez, X86 ML,
	linux-kernel@vger.kernel.org, Linux MM

On Thu, Jul 16, 2015 at 4:23 PM, Toshi Kani <toshi.kani@hp.com> wrote:
> ioremap() checks if a target range is in RAM and fails the request
> if true.  There are multiple issues in the iormap RAM check interfaces.
>
>  1. region_is_ram() always fails with -1.
>  2. The check calls two functions, region_is_ram() and
>     walk_system_ram_range(), which are redundant as both walk the
>     same iomem_resource table.
>  3. walk_system_ram_range() requires RAM ranges be page-aligned in
>     the iomem_resource table to work properly.  This restriction
>     has allowed multiple ioremaps to RAM which are page-unaligned.
>
> This patchset solves issue 1 and 2.  It does not address issue 3,
> but continues to allow the existing ioremaps to work until it is
> addressed.
>
> ---
> resend:
>  - Rebased to 4.2-rc2 (no change needed). Modified change logs.
>
> ---
> Toshi Kani (3):
>   1/3 mm, x86: Fix warning in ioremap RAM check
>   2/3 mm, x86: Remove region_is_ram() call from ioremap
>   3/3 mm: Fix bugs in region_is_ram()
>

For the series...

Reviewed-by: Dan Williams <dan.j.williams@intel.com>

I'm going to base my ioremap + memremap series on top of these fixes.

--
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] 7+ messages in thread

* Re: [PATCH RESEND 2/3] mm, x86: Remove region_is_ram() call from ioremap
  2015-07-16 23:23 ` [PATCH RESEND 2/3] mm, x86: Remove region_is_ram() call from ioremap Toshi Kani
@ 2015-07-21 14:31   ` Thomas Gleixner
  2015-07-21 15:07     ` Toshi Kani
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas Gleixner @ 2015-07-21 14:31 UTC (permalink / raw)
  To: Toshi Kani
  Cc: mingo, hpa, akpm, travis, roland, dan.j.williams, mcgrof, x86,
	linux-kernel, linux-mm, Borislav Petkov

On Thu, 16 Jul 2015, Toshi Kani wrote:
> Note, removing the call to region_is_ram() is also necessary to
> fix bugs in region_is_ram().  walk_system_ram_range() requires
> RAM ranges be page-aligned in the iomem_resource table to work
> properly.  This restriction has allowed multiple ioremaps to RAM
> (setup_data) which are page-unaligned.  Using fixed region_is_ram()
> will cause these callers to start failing.

Which callers? 

Thanks,

	tglx

--
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] 7+ messages in thread

* Re: [PATCH RESEND 2/3] mm, x86: Remove region_is_ram() call from ioremap
  2015-07-21 14:31   ` Thomas Gleixner
@ 2015-07-21 15:07     ` Toshi Kani
  0 siblings, 0 replies; 7+ messages in thread
From: Toshi Kani @ 2015-07-21 15:07 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: mingo, hpa, akpm, travis, roland, dan.j.williams, mcgrof, x86,
	linux-kernel, linux-mm, Borislav Petkov

On Tue, 2015-07-21 at 16:31 +0200, Thomas Gleixner wrote:
> On Thu, 16 Jul 2015, Toshi Kani wrote:
> > Note, removing the call to region_is_ram() is also necessary to
> > fix bugs in region_is_ram().  walk_system_ram_range() requires
> > RAM ranges be page-aligned in the iomem_resource table to work
> > properly.  This restriction has allowed multiple ioremaps to RAM
> > (setup_data) which are page-unaligned.  Using fixed region_is_ram()
> > will cause these callers to start failing.
> 
> Which callers? 

They are the callers I noticed.

 - Multiple ioremap calls from arch/x86/kernel/kdebugfs.c.
 - Multiple ioremap calls from arch/x86/kernel/ksysfs.c.
 - pcibios_add_device()

Thanks,
-Toshi


--
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] 7+ messages in thread

end of thread, other threads:[~2015-07-21 15:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-16 23:23 [PATCH RESEND 0/3] mm, x86: Fix ioremap RAM check interfaces Toshi Kani
2015-07-16 23:23 ` [PATCH RESEND 1/3] mm, x86: Fix warning in ioremap RAM check Toshi Kani
2015-07-16 23:23 ` [PATCH RESEND 2/3] mm, x86: Remove region_is_ram() call from ioremap Toshi Kani
2015-07-21 14:31   ` Thomas Gleixner
2015-07-21 15:07     ` Toshi Kani
2015-07-16 23:23 ` [PATCH RESEND 3/3] mm: Fix bugs in region_is_ram() Toshi Kani
2015-07-18  1:23 ` [PATCH RESEND 0/3] mm, x86: Fix ioremap RAM check interfaces Dan Williams

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