All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] mm/page_alloc: avoid potential NULL pointer dereference
@ 2019-04-23 12:08 Andrey Ryabinin
  2019-04-23 12:08 ` [PATCH 2/2] mm/page_alloc: fix never set ALLOC_NOFRAGMENT flag Andrey Ryabinin
  2019-04-23 14:35 ` [PATCH 1/2] mm/page_alloc: avoid potential NULL pointer dereference Mel Gorman
  0 siblings, 2 replies; 9+ messages in thread
From: Andrey Ryabinin @ 2019-04-23 12:08 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Mel Gorman, linux-mm, linux-kernel, Andrey Ryabinin

ac.preferred_zoneref->zone passed to alloc_flags_nofragment() can be NULL.
'zone' pointer unconditionally derefernced in alloc_flags_nofragment().
Bail out on NULL zone to avoid potential crash.
Currently we don't see any crashes only because alloc_flags_nofragment()
has another bug which allows compiler to optimize away all accesses to
'zone'.

Fixes: 6bb154504f8b ("mm, page_alloc: spread allocations across zones before introducing fragmentation")
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 mm/page_alloc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 933bd42899e8..2b2c7065102f 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3461,6 +3461,9 @@ alloc_flags_nofragment(struct zone *zone, gfp_t gfp_mask)
 		alloc_flags |= ALLOC_KSWAPD;
 
 #ifdef CONFIG_ZONE_DMA32
+	if (!zone)
+		return alloc_flags;
+
 	if (zone_idx(zone) != ZONE_NORMAL)
 		goto out;
 
-- 
2.21.0


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

* [PATCH 2/2] mm/page_alloc: fix never set ALLOC_NOFRAGMENT flag
  2019-04-23 12:08 [PATCH 1/2] mm/page_alloc: avoid potential NULL pointer dereference Andrey Ryabinin
@ 2019-04-23 12:08 ` Andrey Ryabinin
  2019-04-23 14:35   ` Mel Gorman
  2019-04-23 19:01   ` Andrew Morton
  2019-04-23 14:35 ` [PATCH 1/2] mm/page_alloc: avoid potential NULL pointer dereference Mel Gorman
  1 sibling, 2 replies; 9+ messages in thread
From: Andrey Ryabinin @ 2019-04-23 12:08 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Mel Gorman, linux-mm, linux-kernel, Andrey Ryabinin

Commit 0a79cdad5eb2 ("mm: use alloc_flags to record if kswapd can wake")
removed setting of the ALLOC_NOFRAGMENT flag. Bring it back.

Fixes: 0a79cdad5eb2 ("mm: use alloc_flags to record if kswapd can wake")
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 mm/page_alloc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 2b2c7065102f..a85b8252c5ad 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3465,7 +3465,7 @@ alloc_flags_nofragment(struct zone *zone, gfp_t gfp_mask)
 		return alloc_flags;
 
 	if (zone_idx(zone) != ZONE_NORMAL)
-		goto out;
+		return alloc_flags;
 
 	/*
 	 * If ZONE_DMA32 exists, assume it is the one after ZONE_NORMAL and
@@ -3474,9 +3474,9 @@ alloc_flags_nofragment(struct zone *zone, gfp_t gfp_mask)
 	 */
 	BUILD_BUG_ON(ZONE_NORMAL - ZONE_DMA32 != 1);
 	if (nr_online_nodes > 1 && !populated_zone(--zone))
-		goto out;
+		return alloc_flags;
 
-out:
+	alloc_flags |= ALLOC_NOFRAGMENT;
 #endif /* CONFIG_ZONE_DMA32 */
 	return alloc_flags;
 }
-- 
2.21.0


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

* Re: [PATCH 2/2] mm/page_alloc: fix never set ALLOC_NOFRAGMENT flag
  2019-04-23 12:08 ` [PATCH 2/2] mm/page_alloc: fix never set ALLOC_NOFRAGMENT flag Andrey Ryabinin
@ 2019-04-23 14:35   ` Mel Gorman
  2019-04-23 19:01   ` Andrew Morton
  1 sibling, 0 replies; 9+ messages in thread
From: Mel Gorman @ 2019-04-23 14:35 UTC (permalink / raw)
  To: Andrey Ryabinin; +Cc: Andrew Morton, linux-mm, linux-kernel

On Tue, Apr 23, 2019 at 03:08:06PM +0300, Andrey Ryabinin wrote:
> Commit 0a79cdad5eb2 ("mm: use alloc_flags to record if kswapd can wake")
> removed setting of the ALLOC_NOFRAGMENT flag. Bring it back.
> 
> Fixes: 0a79cdad5eb2 ("mm: use alloc_flags to record if kswapd can wake")
> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>

Acked-by: Mel Gorman <mgorman@techsingularity.net>

-- 
Mel Gorman
SUSE Labs

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

* Re: [PATCH 1/2] mm/page_alloc: avoid potential NULL pointer dereference
  2019-04-23 12:08 [PATCH 1/2] mm/page_alloc: avoid potential NULL pointer dereference Andrey Ryabinin
  2019-04-23 12:08 ` [PATCH 2/2] mm/page_alloc: fix never set ALLOC_NOFRAGMENT flag Andrey Ryabinin
@ 2019-04-23 14:35 ` Mel Gorman
  1 sibling, 0 replies; 9+ messages in thread
From: Mel Gorman @ 2019-04-23 14:35 UTC (permalink / raw)
  To: Andrey Ryabinin; +Cc: Andrew Morton, linux-mm, linux-kernel

On Tue, Apr 23, 2019 at 03:08:05PM +0300, Andrey Ryabinin wrote:
> ac.preferred_zoneref->zone passed to alloc_flags_nofragment() can be NULL.
> 'zone' pointer unconditionally derefernced in alloc_flags_nofragment().
> Bail out on NULL zone to avoid potential crash.
> Currently we don't see any crashes only because alloc_flags_nofragment()
> has another bug which allows compiler to optimize away all accesses to
> 'zone'.
> 
> Fixes: 6bb154504f8b ("mm, page_alloc: spread allocations across zones before introducing fragmentation")
> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>

Acked-by: Mel Gorman <mgorman@techsingularity.net>

-- 
Mel Gorman
SUSE Labs

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

* Re: [PATCH 2/2] mm/page_alloc: fix never set ALLOC_NOFRAGMENT flag
  2019-04-23 12:08 ` [PATCH 2/2] mm/page_alloc: fix never set ALLOC_NOFRAGMENT flag Andrey Ryabinin
  2019-04-23 14:35   ` Mel Gorman
@ 2019-04-23 19:01   ` Andrew Morton
  2019-04-24  9:04     ` Mel Gorman
  1 sibling, 1 reply; 9+ messages in thread
From: Andrew Morton @ 2019-04-23 19:01 UTC (permalink / raw)
  To: Andrey Ryabinin; +Cc: Mel Gorman, linux-mm, linux-kernel

On Tue, 23 Apr 2019 15:08:06 +0300 Andrey Ryabinin <aryabinin@virtuozzo.com> wrote:

> Commit 0a79cdad5eb2 ("mm: use alloc_flags to record if kswapd can wake")
> removed setting of the ALLOC_NOFRAGMENT flag. Bring it back.

What are the runtime effects of this fix?

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

* Re: [PATCH 2/2] mm/page_alloc: fix never set ALLOC_NOFRAGMENT flag
  2019-04-23 19:01   ` Andrew Morton
@ 2019-04-24  9:04     ` Mel Gorman
  2019-04-24 22:46       ` Andrew Morton
  0 siblings, 1 reply; 9+ messages in thread
From: Mel Gorman @ 2019-04-24  9:04 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Andrey Ryabinin, linux-mm, linux-kernel

On Tue, Apr 23, 2019 at 12:01:43PM -0700, Andrew Morton wrote:
> On Tue, 23 Apr 2019 15:08:06 +0300 Andrey Ryabinin <aryabinin@virtuozzo.com> wrote:
> 
> > Commit 0a79cdad5eb2 ("mm: use alloc_flags to record if kswapd can wake")
> > removed setting of the ALLOC_NOFRAGMENT flag. Bring it back.
> 
> What are the runtime effects of this fix?

The runtime effect is that ALLOC_NOFRAGMENT behaviour is restored so
that allocations are spread across local zones to avoid fragmentation
due to mixing pageblocks as long as possible.

-- 
Mel Gorman
SUSE Labs

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

* Re: [PATCH 2/2] mm/page_alloc: fix never set ALLOC_NOFRAGMENT flag
  2019-04-24  9:04     ` Mel Gorman
@ 2019-04-24 22:46       ` Andrew Morton
  2019-04-24 23:40         ` Mel Gorman
  0 siblings, 1 reply; 9+ messages in thread
From: Andrew Morton @ 2019-04-24 22:46 UTC (permalink / raw)
  To: Mel Gorman; +Cc: Andrey Ryabinin, linux-mm, linux-kernel

On Wed, 24 Apr 2019 10:04:03 +0100 Mel Gorman <mgorman@techsingularity.net> wrote:

> On Tue, Apr 23, 2019 at 12:01:43PM -0700, Andrew Morton wrote:
> > On Tue, 23 Apr 2019 15:08:06 +0300 Andrey Ryabinin <aryabinin@virtuozzo.com> wrote:
> > 
> > > Commit 0a79cdad5eb2 ("mm: use alloc_flags to record if kswapd can wake")
> > > removed setting of the ALLOC_NOFRAGMENT flag. Bring it back.
> > 
> > What are the runtime effects of this fix?
> 
> The runtime effect is that ALLOC_NOFRAGMENT behaviour is restored so
> that allocations are spread across local zones to avoid fragmentation
> due to mixing pageblocks as long as possible.

OK, thanks.  Is this worth a -stable backport?

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

* Re: [PATCH 2/2] mm/page_alloc: fix never set ALLOC_NOFRAGMENT flag
  2019-04-24 22:46       ` Andrew Morton
@ 2019-04-24 23:40         ` Mel Gorman
  2019-04-25 21:09           ` Andrew Morton
  0 siblings, 1 reply; 9+ messages in thread
From: Mel Gorman @ 2019-04-24 23:40 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Andrey Ryabinin, linux-mm, linux-kernel

On Wed, Apr 24, 2019 at 03:46:24PM -0700, Andrew Morton wrote:
> On Wed, 24 Apr 2019 10:04:03 +0100 Mel Gorman <mgorman@techsingularity.net> wrote:
> 
> > On Tue, Apr 23, 2019 at 12:01:43PM -0700, Andrew Morton wrote:
> > > On Tue, 23 Apr 2019 15:08:06 +0300 Andrey Ryabinin <aryabinin@virtuozzo.com> wrote:
> > > 
> > > > Commit 0a79cdad5eb2 ("mm: use alloc_flags to record if kswapd can wake")
> > > > removed setting of the ALLOC_NOFRAGMENT flag. Bring it back.
> > > 
> > > What are the runtime effects of this fix?
> > 
> > The runtime effect is that ALLOC_NOFRAGMENT behaviour is restored so
> > that allocations are spread across local zones to avoid fragmentation
> > due to mixing pageblocks as long as possible.
> 
> OK, thanks.  Is this worth a -stable backport?

Yes, but only for 5.0 obviously and both should be included if that is
the case. I did not push for it initially as problems in this area are
hard for a general user to detect and people have not complained about
5.0's fragmentation handling.

-- 
Mel Gorman
SUSE Labs

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

* Re: [PATCH 2/2] mm/page_alloc: fix never set ALLOC_NOFRAGMENT flag
  2019-04-24 23:40         ` Mel Gorman
@ 2019-04-25 21:09           ` Andrew Morton
  0 siblings, 0 replies; 9+ messages in thread
From: Andrew Morton @ 2019-04-25 21:09 UTC (permalink / raw)
  To: Mel Gorman; +Cc: Andrey Ryabinin, linux-mm, linux-kernel

On Thu, 25 Apr 2019 00:40:53 +0100 Mel Gorman <mgorman@techsingularity.net> wrote:

> On Wed, Apr 24, 2019 at 03:46:24PM -0700, Andrew Morton wrote:
> > On Wed, 24 Apr 2019 10:04:03 +0100 Mel Gorman <mgorman@techsingularity.net> wrote:
> > 
> > > On Tue, Apr 23, 2019 at 12:01:43PM -0700, Andrew Morton wrote:
> > > > On Tue, 23 Apr 2019 15:08:06 +0300 Andrey Ryabinin <aryabinin@virtuozzo.com> wrote:
> > > > 
> > > > > Commit 0a79cdad5eb2 ("mm: use alloc_flags to record if kswapd can wake")
> > > > > removed setting of the ALLOC_NOFRAGMENT flag. Bring it back.
> > > > 
> > > > What are the runtime effects of this fix?
> > > 
> > > The runtime effect is that ALLOC_NOFRAGMENT behaviour is restored so
> > > that allocations are spread across local zones to avoid fragmentation
> > > due to mixing pageblocks as long as possible.
> > 
> > OK, thanks.  Is this worth a -stable backport?
> 
> Yes, but only for 5.0 obviously and both should be included if that is
> the case. I did not push for it initially as problems in this area are
> hard for a general user to detect and people have not complained about
> 5.0's fragmentation handling.

Ah, OK.  0a79cdad5eb2 didn't have a -stable tag so I suppose we can
leave this patch un-stabled.

If they went and backported 0a79cdad5eb2 anyway, let's hope the scripts
are smart enough to catch this patch's Fixes: link.


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

end of thread, other threads:[~2019-04-25 21:09 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-23 12:08 [PATCH 1/2] mm/page_alloc: avoid potential NULL pointer dereference Andrey Ryabinin
2019-04-23 12:08 ` [PATCH 2/2] mm/page_alloc: fix never set ALLOC_NOFRAGMENT flag Andrey Ryabinin
2019-04-23 14:35   ` Mel Gorman
2019-04-23 19:01   ` Andrew Morton
2019-04-24  9:04     ` Mel Gorman
2019-04-24 22:46       ` Andrew Morton
2019-04-24 23:40         ` Mel Gorman
2019-04-25 21:09           ` Andrew Morton
2019-04-23 14:35 ` [PATCH 1/2] mm/page_alloc: avoid potential NULL pointer dereference Mel Gorman

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.