Skip to contentSkip to conversation

tcmu: Oops in unmap_thread_fn()

PATCH Applied Dan Carpenter 5 participants 5 messages Aug 1, 2017 – Nov 8, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcmu: Oops in unmap_thread_fn()

Calling list_del() on the iterator pointer in list_for_each_entry() will cause an oops. We need to user the _safe() version for that.

Fixes c73d02f63c16 ("tcmu: Add fifo type waiter list support to avoid starvation")
drivers/target/target_core_user.c +2 -2
index 9258b7dd2c30..fd9fcea68d23 100644
@@ -1985,7 +1985,7 @@ static struct target_backend_ops tcmu_ops = {
 
 static int unmap_thread_fn(void *data)
 {
-	struct tcmu_dev *udev;
+	struct tcmu_dev *udev, *tmp;
 	loff_t off;
 	uint32_t start, end, block;
 	static uint32_t free_blocks;
@@ -2056,7 +2056,7 @@ static int unmap_thread_fn(void *data)
 		 * for the global data pool blocks.
 		 */
 		mutex_lock(&root_udev_waiter_mutex);
-		list_for_each_entry(udev, &root_udev_waiter, waiter) {
+		list_for_each_entry_safe(udev, tmp, &root_udev_waiter, waiter) {
 			mutex_lock(&udev->cmdr_lock);
 			if (udev->waiting_blocks < free_blocks) {
 				mutex_unlock(&udev->cmdr_lock);
#1 lore raw
Quoted 20 lines · Dan Carpenter

Calling list_del() on the iterator pointer in list_for_each_entry() will cause an oops. We need to user the _safe() version for that.

Fixes c73d02f63c16 ("tcmu: Add fifo type waiter list support to avoid starvation")
drivers/target/target_core_user.c +1 -1
index 9258b7dd2c30..fd9fcea68d23 100644
@@ -1985,7 +1985,7 @@ static struct target_backend_ops tcmu_ops = {
 
  static int unmap_thread_fn(void *data)
  {
-	struct tcmu_dev *udev;
+	struct tcmu_dev *udev, *tmp;
  	loff_t off;
  	uint32_t start, end, block;
  	static uint32_t free_blocks;

drivers/target/target_core_user.c static int unmap_thread_fn(void *data) · line 2062

Quoted 8 lines
drivers/target/target_core_user.c +1 -1
@@ -2056,7 +2056,7 @@ static int unmap_thread_fn(void *data)
  		 * for the global data pool blocks.
  		 */
  		mutex_lock(&root_udev_waiter_mutex);
-		list_for_each_entry(udev, &root_udev_waiter, waiter) {
+		list_for_each_entry_safe(udev, tmp, &root_udev_waiter, waiter) {
  			mutex_lock(&udev->cmdr_lock);
  			if (udev->waiting_blocks < free_blocks) {
  				mutex_unlock(&udev->cmdr_lock);

Good catch and it looks nice for me.

Thanks,

BRs
Xiubo

Reviewed-by on v1 1/1
#2 lore raw
In reply to Dan Carpenter
Quoted 21 lines · Dan Carpenter

Calling list_del() on the iterator pointer in list_for_each_entry() will cause an oops. We need to user the _safe() version for that.

Fixes c73d02f63c16 ("tcmu: Add fifo type waiter list support to avoid starvation")
drivers/target/target_core_user.c +1 -1
index 9258b7dd2c30..fd9fcea68d23 100644
@@ -1985,7 +1985,7 @@ static struct target_backend_ops tcmu_ops = {
 
 static int unmap_thread_fn(void *data)
 {
-	struct tcmu_dev *udev;
+	struct tcmu_dev *udev, *tmp;
 	loff_t off;
 	uint32_t start, end, block;
 	static uint32_t free_blocks;

drivers/target/target_core_user.c static int unmap_thread_fn(void *data) · line 2062

Quoted 8 lines
drivers/target/target_core_user.c +1 -1
@@ -2056,7 +2056,7 @@ static int unmap_thread_fn(void *data)
 		 * for the global data pool blocks.
 		 */
 		mutex_lock(&root_udev_waiter_mutex);
-		list_for_each_entry(udev, &root_udev_waiter, waiter) {
+		list_for_each_entry_safe(udev, tmp, &root_udev_waiter, waiter) {
 			mutex_lock(&udev->cmdr_lock);
 			if (udev->waiting_blocks < free_blocks) {
 				mutex_unlock(&udev->cmdr_lock);

Thanks.

#4 lore raw
Quoted 7 lines · Nicholas A. Bellinger
Quoted 6 lines · Dan Carpenter

Calling list_del() on the iterator pointer in list_for_each_entry() will cause an oops. We need to user the _safe() version for that.

Fixes c73d02f63c16 ("tcmu: Add fifo type waiter list support to avoid starvation")
Quoted 9 lines

Applied to target-pending/for-next.

Thanks DanC.

--
To unsubscribe from this list: send the line "unsubscribe target-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Also missing.

-Bryant