Commit e95d50d7 authored by Yishai Hadas's avatar Yishai Hadas Committed by Jason Gunthorpe

lib/scatterlist: Fix to merge contiguous pages into the last SG properly

When sg_alloc_append_table_from_pages() calls to pages_are_mergeable() in
its 'sgt_append->prv' flow to check whether it can merge contiguous pages
into the last SG, it passes the page arguments in the wrong order.

The first parameter should be the next candidate page to be merged to
the last page and not the opposite.

The current code leads to a corrupted SG which resulted in OOPs and
unexpected errors when non-contiguous pages are merged wrongly.

Fix to pass the page parameters in the right order.

Fixes: 1567b49d ("lib/scatterlist: add check when merging zone device pages")
Link: https://lore.kernel.org/r/20230105112339.107969-1-yishaih@nvidia.comSigned-off-by: default avatarYishai Hadas <yishaih@nvidia.com>
Reviewed-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Reviewed-by: default avatarLogan Gunthorpe <logang@deltatee.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 8de8482f
...@@ -476,7 +476,7 @@ int sg_alloc_append_table_from_pages(struct sg_append_table *sgt_append, ...@@ -476,7 +476,7 @@ int sg_alloc_append_table_from_pages(struct sg_append_table *sgt_append,
/* Merge contiguous pages into the last SG */ /* Merge contiguous pages into the last SG */
prv_len = sgt_append->prv->length; prv_len = sgt_append->prv->length;
last_pg = sg_page(sgt_append->prv); last_pg = sg_page(sgt_append->prv);
while (n_pages && pages_are_mergeable(last_pg, pages[0])) { while (n_pages && pages_are_mergeable(pages[0], last_pg)) {
if (sgt_append->prv->length + PAGE_SIZE > max_segment) if (sgt_append->prv->length + PAGE_SIZE > max_segment)
break; break;
sgt_append->prv->length += PAGE_SIZE; sgt_append->prv->length += PAGE_SIZE;
......
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