scsi: target: tcmu: scatter_/gather_data_area() rework
authorBodo Stroesser <bostroesser@gmail.com>
Mon, 19 Oct 2020 11:51:18 +0000 (13:51 +0200)
committerMartin K. Petersen <martin.petersen@oracle.com>
Mon, 26 Oct 2020 22:27:44 +0000 (18:27 -0400)
commitc8ed1ff88c02e55bf9fa3244624e431f4f374077
tree443941fd57f0b4339a69dc1a2ef6ecdb3bee45e2
parentb9dd44fd79a1ed7ee8e7c7644ddbd803b6acfd9c
scsi: target: tcmu: scatter_/gather_data_area() rework

scatter_data_area() and gather_data_area() are not easy to understand since
data is copied in nested loops over sg_list and tcmu dbi list. Since sg
list can contain only partly filled pages, the loop has to be prepared to
handle sg pages not matching dbi pages one by one.

Existing implementation uses kmap_atomic()/kunmap_atomic() due to
performance reasons. But instead of using these calls strictly nested for
sg and dpi pages, the code holds the mappings in an overlapping way, which
indeed is a bug that would trigger on archs using highmem.

The scatterlist lib contains the sg_miter_start/_next/_stop functions which
can be used to simplify such complicated loops.

The new code now processes the dbi list in the outer loop, while sg list is
handled by the inner one. That way the code can take advantage of the
sg_miter_* family calls.

Calling sg_miter_stop() after the end of the inner loop enforces strict
nesting of atomic kmaps.

Since the nested loops in scatter_/gather_data_area were very similar, I
replaced them by the new helper function tcmu_copy_data().

Link: https://lore.kernel.org/r/20201019115118.11949-1-bostroesser@gmail.com
Acked-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Bodo Stroesser <bostroesser@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/target/target_core_user.c