Commit 6467552c authored by Vlastimil Babka's avatar Vlastimil Babka Committed by Linus Torvalds

mm, compaction: fully assume capture is not NULL in compact_zone_order()

Dan reports:

The patch 5e1f0f09: "mm, compaction: capture a page under direct
compaction" from Mar 5, 2019, leads to the following Smatch complaint:

    mm/compaction.c:2321 compact_zone_order()
     error: we previously assumed 'capture' could be null (see line 2313)

mm/compaction.c
  2288  static enum compact_result compact_zone_order(struct zone *zone, int order,
  2289                  gfp_t gfp_mask, enum compact_priority prio,
  2290                  unsigned int alloc_flags, int classzone_idx,
  2291                  struct page **capture)
                                      ^^^^^^^

  2313		if (capture)
                    ^^^^^^^
Check for NULL

  2314			current->capture_control = &capc;
  2315
  2316		ret = compact_zone(&cc, &capc);
  2317
  2318		VM_BUG_ON(!list_empty(&cc.freepages));
  2319		VM_BUG_ON(!list_empty(&cc.migratepages));
  2320
  2321		*capture = capc.page;
                ^^^^^^^^
Unchecked dereference.

  2322		current->capture_control = NULL;
  2323

In practice this is not an issue, as the only caller path passes non-NULL
capture:

__alloc_pages_direct_compact()
  struct page *page = NULL;
  try_to_compact_pages(capture = &page);
    compact_zone_order(capture = capture);

So let's remove the unnecessary check, which should also make Smatch happy.

Fixes: 5e1f0f09 ("mm, compaction: capture a page under direct compaction")
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Suggested-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Acked-by: default avatarMel Gorman <mgorman@techsingularity.net>
Link: http://lkml.kernel.org/r/18b0df3c-0589-d96c-23fa-040798fee187@suse.czSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 1da2f328
...@@ -2314,7 +2314,6 @@ static enum compact_result compact_zone_order(struct zone *zone, int order, ...@@ -2314,7 +2314,6 @@ static enum compact_result compact_zone_order(struct zone *zone, int order,
.page = NULL, .page = NULL,
}; };
if (capture)
current->capture_control = &capc; current->capture_control = &capc;
ret = compact_zone(&cc, &capc); ret = compact_zone(&cc, &capc);
...@@ -2337,6 +2336,7 @@ int sysctl_extfrag_threshold = 500; ...@@ -2337,6 +2336,7 @@ int sysctl_extfrag_threshold = 500;
* @alloc_flags: The allocation flags of the current allocation * @alloc_flags: The allocation flags of the current allocation
* @ac: The context of current allocation * @ac: The context of current allocation
* @prio: Determines how hard direct compaction should try to succeed * @prio: Determines how hard direct compaction should try to succeed
* @capture: Pointer to free page created by compaction will be stored here
* *
* This is the main entry point for direct page compaction. * This is the main entry point for direct page compaction.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment