RDMA/core: Set sgtable nents when using ib_dma_virt_map_sg()
authorLogan Gunthorpe <logang@deltatee.com>
Wed, 13 Oct 2021 16:59:42 +0000 (10:59 -0600)
committerJason Gunthorpe <jgg@nvidia.com>
Wed, 13 Oct 2021 18:26:41 +0000 (15:26 -0300)
ib_dma_map_sgtable_attrs() should be mapping the sgls and setting nents
but the ib_uses_virt_dma() path falls back to ib_dma_virt_map_sg() which
will not set the nents in the sgtable.

Check the return value (per the map_sg calling convention) and set
sgt->nents appropriately on success.

Fixes: 79fbd3e1241c ("RDMA: Use the sg_table directly and remove the opencoded version from umem")
Link: https://lore.kernel.org/r/20211013165942.89806-1-logang@deltatee.com
Reported-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Tested-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
include/rdma/ib_verbs.h

index 7688720411a3e6e88d84d7cb567bd467b394f43a..61c73adccbbd93f35d9abb509155f1ff7084fb8f 100644 (file)
@@ -4105,8 +4105,13 @@ static inline int ib_dma_map_sgtable_attrs(struct ib_device *dev,
                                           enum dma_data_direction direction,
                                           unsigned long dma_attrs)
 {
+       int nents;
+
        if (ib_uses_virt_dma(dev)) {
-               ib_dma_virt_map_sg(dev, sgt->sgl, sgt->orig_nents);
+               nents = ib_dma_virt_map_sg(dev, sgt->sgl, sgt->orig_nents);
+               if (!nents)
+                       return -EIO;
+               sgt->nents = nents;
                return 0;
        }
        return dma_map_sgtable(dev->dma_device, sgt, direction, dma_attrs);