lib/scatterlist: Fix wrong update of orig_nents
authorMaor Gottlieb <maorg@nvidia.com>
Tue, 24 Aug 2021 14:25:30 +0000 (17:25 +0300)
committerJason Gunthorpe <jgg@nvidia.com>
Tue, 24 Aug 2021 22:52:40 +0000 (19:52 -0300)
commit3e302dbc6774a27edaea39a1d5107f0c12e35cf2
tree082ed97d3a748ff89836ba6a2d7954a16fb029c8
parent90e7a6de62781c27d6a111fccfb19b807f9b6887
lib/scatterlist: Fix wrong update of orig_nents

orig_nents should represent the number of entries with pages,
but __sg_alloc_table_from_pages sets orig_nents as the number of
total entries in the table. This is wrong when the API is used for
dynamic allocation where not all the table entries are mapped with
pages. It wasn't observed until now, since RDMA umem who uses this
API in the dynamic form doesn't use orig_nents implicit or explicit
by the scatterlist APIs.

Fix it by changing the append API to track the SG append table
state and have an API to free the append table according to the
total number of entries in the table.
Now all APIs set orig_nents as number of enries with pages.

Fixes: 07da1223ec93 ("lib/scatterlist: Add support in dynamic allocation of SG table from pages")
Link: https://lore.kernel.org/r/20210824142531.3877007-3-maorg@nvidia.com
Signed-off-by: Maor Gottlieb <maorg@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/core/umem.c
include/linux/scatterlist.h
include/rdma/ib_umem.h
lib/scatterlist.c
lib/sg_pool.c
tools/testing/scatterlist/main.c