Unverified Commit 28f89d80 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!1986 tracing: Fix race issue between cpu buffer write and swap

parents ecedbab0 0cd59e11
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -7068,6 +7068,11 @@ static int tracing_snapshot_open(struct inode *inode, struct file *file)
	return ret;
}

static void tracing_swap_cpu_buffer(void *tr)
{
	update_max_tr_single((struct trace_array *)tr, current, smp_processor_id());
}

static ssize_t
tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt,
		       loff_t *ppos)
@@ -7126,13 +7131,15 @@ tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt,
			ret = tracing_alloc_snapshot_instance(tr);
		if (ret < 0)
			break;
		local_irq_disable();
		/* Now, we're going to swap */
		if (iter->cpu_file == RING_BUFFER_ALL_CPUS)
		if (iter->cpu_file == RING_BUFFER_ALL_CPUS) {
			local_irq_disable();
			update_max_tr(tr, current, smp_processor_id(), NULL);
		else
			update_max_tr_single(tr, current, iter->cpu_file);
			local_irq_enable();
		} else {
			smp_call_function_single(iter->cpu_file, tracing_swap_cpu_buffer,
						 (void *)tr, 1);
		}
		break;
	default:
		if (tr->allocated_snapshot) {