linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [patch] mm: fail GFP_DMA allocations when ZONE_DMA is not configured
@ 2011-04-14 21:46 David Rientjes
  2011-04-14 21:54 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: David Rientjes @ 2011-04-14 21:46 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Mel Gorman, KOSAKI Motohiro, KAMEZAWA Hiroyuki, Rik van Riel,
	linux-mm

The page allocator will improperly return a page from ZONE_NORMAL even 
when __GFP_DMA is passed if CONFIG_ZONE_DMA is disabled.  The caller 
expects DMA memory, perhaps for ISA devices with 16-bit address 
registers, and may get higher memory resulting in undefined behavior.

This patch causes the page allocator to return NULL in such circumstances 
with a warning emitted to the kernel log on the first occurrence.

Signed-off-by: David Rientjes <rientjes@google.com>
---
 mm/page_alloc.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2225,6 +2225,10 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
 
 	if (should_fail_alloc_page(gfp_mask, order))
 		return NULL;
+#ifndef CONFIG_ZONE_DMA
+	if (WARN_ON_ONCE(gfp_mask & __GFP_DMA))
+		return NULL;
+#endif
 
 	/*
 	 * Check the zones suitable for the gfp_mask contain at least one

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [patch] mm: fail GFP_DMA allocations when ZONE_DMA is not configured
  2011-04-14 21:46 [patch] mm: fail GFP_DMA allocations when ZONE_DMA is not configured David Rientjes
@ 2011-04-14 21:54 ` Andrew Morton
  2011-05-04 19:33   ` David Rientjes
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2011-04-14 21:54 UTC (permalink / raw)
  To: David Rientjes
  Cc: Mel Gorman, KOSAKI Motohiro, KAMEZAWA Hiroyuki, Rik van Riel,
	linux-mm

On Thu, 14 Apr 2011 14:46:56 -0700 (PDT)
David Rientjes <rientjes@google.com> wrote:

> The page allocator will improperly return a page from ZONE_NORMAL even 
> when __GFP_DMA is passed if CONFIG_ZONE_DMA is disabled.  The caller 
> expects DMA memory, perhaps for ISA devices with 16-bit address 
> registers, and may get higher memory resulting in undefined behavior.
> 
> This patch causes the page allocator to return NULL in such circumstances 
> with a warning emitted to the kernel log on the first occurrence.
> 
> Signed-off-by: David Rientjes <rientjes@google.com>
> ---
>  mm/page_alloc.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -2225,6 +2225,10 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
>  
>  	if (should_fail_alloc_page(gfp_mask, order))
>  		return NULL;
> +#ifndef CONFIG_ZONE_DMA
> +	if (WARN_ON_ONCE(gfp_mask & __GFP_DMA))
> +		return NULL;
> +#endif

Worried.  We have a large number of drivers which use GFP_DMA and I bet
some of them didn't really need to set it, and can use DMA32 memory. 
They will now break.

What is drivers/pci/intel-iommu.c doing with GFP_DMA btw?

How commonly are people disabling ZONE_DMA?

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [patch] mm: fail GFP_DMA allocations when ZONE_DMA is not configured
  2011-04-14 21:54 ` Andrew Morton
@ 2011-05-04 19:33   ` David Rientjes
  0 siblings, 0 replies; 3+ messages in thread
From: David Rientjes @ 2011-05-04 19:33 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Mel Gorman, KOSAKI Motohiro, KAMEZAWA Hiroyuki, Rik van Riel,
	Alex Williamson, David Woodhouse, linux-mm

On Thu, 14 Apr 2011, Andrew Morton wrote:

> > The page allocator will improperly return a page from ZONE_NORMAL even 
> > when __GFP_DMA is passed if CONFIG_ZONE_DMA is disabled.  The caller 
> > expects DMA memory, perhaps for ISA devices with 16-bit address 
> > registers, and may get higher memory resulting in undefined behavior.
> > 
> > This patch causes the page allocator to return NULL in such circumstances 
> > with a warning emitted to the kernel log on the first occurrence.
> > 
> > Signed-off-by: David Rientjes <rientjes@google.com>
> > ---
> >  mm/page_alloc.c |    4 ++++
> >  1 files changed, 4 insertions(+), 0 deletions(-)
> > 
> > diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> > --- a/mm/page_alloc.c
> > +++ b/mm/page_alloc.c
> > @@ -2225,6 +2225,10 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
> >  
> >  	if (should_fail_alloc_page(gfp_mask, order))
> >  		return NULL;
> > +#ifndef CONFIG_ZONE_DMA
> > +	if (WARN_ON_ONCE(gfp_mask & __GFP_DMA))
> > +		return NULL;
> > +#endif
> 
> Worried.  We have a large number of drivers which use GFP_DMA and I bet
> some of them didn't really need to set it, and can use DMA32 memory. 
> They will now break.
> 

They were already broken for CONFIG_ZONE_DMA=n since passing __GFP_DMA 
never guaranteed the memory came from ZONE_DMA32 (and would return 
ZONE_NORMAL memory even if CONFIG_ZONE_DMA32=n).

> What is drivers/pci/intel-iommu.c doing with GFP_DMA btw?
> 

Looks like if no identity mapping is needed for that device (using a 
non-identity mapping instead), then there is no lowmem restriction on its 
allocation; otherwise, we use lowmem is used when the device's mask 
specifically requires it.

Adding Alex and David to the cc.

> How commonly are people disabling ZONE_DMA?
> 

Probably not that much, it's usually def_bool y everywhere and just 
implicitly on.  I'm changing that for x86 on a CONFIG_EXPERT kernel so 
that we can avoid a ZONE_DMA entirely; that prevents reserving memory we 
don't need with the lowmem reserve by default, we can eliminate the DMA 
slab caches, etc.  Google has been running with CONFIG_ZONE_DMA=n for a 
couple years because we simply don't need it.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2011-05-04 19:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-14 21:46 [patch] mm: fail GFP_DMA allocations when ZONE_DMA is not configured David Rientjes
2011-04-14 21:54 ` Andrew Morton
2011-05-04 19:33   ` David Rientjes

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