coresight: Fix crash when Perf and sysfs modes are used concurrently
[platform/kernel/linux-starfive.git] / io_uring / sqpoll.c
index ee2d2c6..65b5dbe 100644 (file)
@@ -214,6 +214,7 @@ static bool io_sqd_handle_event(struct io_sq_data *sqd)
                        did_sig = get_signal(&ksig);
                cond_resched();
                mutex_lock(&sqd->lock);
+               sqd->sq_cpu = raw_smp_processor_id();
        }
        return did_sig || test_bit(IO_SQ_THREAD_SHOULD_STOP, &sqd->state);
 }
@@ -229,10 +230,15 @@ static int io_sq_thread(void *data)
        snprintf(buf, sizeof(buf), "iou-sqp-%d", sqd->task_pid);
        set_task_comm(current, buf);
 
-       if (sqd->sq_cpu != -1)
+       /* reset to our pid after we've set task_comm, for fdinfo */
+       sqd->task_pid = current->pid;
+
+       if (sqd->sq_cpu != -1) {
                set_cpus_allowed_ptr(current, cpumask_of(sqd->sq_cpu));
-       else
+       } else {
                set_cpus_allowed_ptr(current, cpu_online_mask);
+               sqd->sq_cpu = raw_smp_processor_id();
+       }
 
        mutex_lock(&sqd->lock);
        while (1) {
@@ -261,6 +267,7 @@ static int io_sq_thread(void *data)
                                mutex_unlock(&sqd->lock);
                                cond_resched();
                                mutex_lock(&sqd->lock);
+                               sqd->sq_cpu = raw_smp_processor_id();
                        }
                        continue;
                }
@@ -294,6 +301,7 @@ static int io_sq_thread(void *data)
                                mutex_unlock(&sqd->lock);
                                schedule();
                                mutex_lock(&sqd->lock);
+                               sqd->sq_cpu = raw_smp_processor_id();
                        }
                        list_for_each_entry(ctx, &sqd->ctx_list, sqd_list)
                                atomic_andnot(IORING_SQ_NEED_WAKEUP,
@@ -430,7 +438,9 @@ __cold int io_sqpoll_wq_cpu_affinity(struct io_ring_ctx *ctx,
 
        if (sqd) {
                io_sq_thread_park(sqd);
-               ret = io_wq_cpu_affinity(sqd->thread->io_uring, mask);
+               /* Don't set affinity for a dying thread */
+               if (sqd->thread)
+                       ret = io_wq_cpu_affinity(sqd->thread->io_uring, mask);
                io_sq_thread_unpark(sqd);
        }