Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7c7dfa62 authored by Tao,Zhang's avatar Tao,Zhang
Browse files

coresight: tmc-etr: Fix deadlock issue while reading from ETR



If ETR is being read repeatedly, at the same time, trying to reset
source link again and again, sometimes deadlock problems occur.
Beacause reset_source_sink_store holds coresight_mutex and waits
for mem_lock, meanwhile, tmc_read_prepare_etr holds mem_lock and
waits for coresight_mutex.

Change-Id: I8c70575b8a70d820748492313d6232923478ede3
Signed-off-by: default avatarTao,Zhang <taozha@codeaurora.org>
parent ad191fdc
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -2164,14 +2164,18 @@ int tmc_read_prepare_etr(struct tmc_drvdata *drvdata)
		goto out;
	}

	drvdata->reading = true;

	/* Disable the TMC if we are trying to read from a running session. */
	if (drvdata->mode == CS_MODE_SYSFS) {
		spin_unlock_irqrestore(&drvdata->spinlock, flags);
		mutex_unlock(&drvdata->mem_lock);
		coresight_disable_all_source_link();
		mutex_lock(&drvdata->mem_lock);
		spin_lock_irqsave(&drvdata->spinlock, flags);
		__tmc_etr_disable_hw(drvdata);
	}
	drvdata->reading = true;

out:
	spin_unlock_irqrestore(&drvdata->spinlock, flags);
	mutex_unlock(&drvdata->mem_lock);
@@ -2199,10 +2203,6 @@ int tmc_read_unprepare_etr(struct tmc_drvdata *drvdata)
		 * be NULL.
		 */
		__tmc_etr_enable_hw(drvdata);

		spin_unlock_irqrestore(&drvdata->spinlock, flags);
		coresight_enable_all_source_link();
		spin_lock_irqsave(&drvdata->spinlock, flags);
	} else {
		/*
		 * The ETR is not tracing and the buffer was just read.
@@ -2219,5 +2219,9 @@ int tmc_read_unprepare_etr(struct tmc_drvdata *drvdata)
		tmc_etr_free_sysfs_buf(sysfs_buf);

	mutex_unlock(&drvdata->mem_lock);

	if (drvdata->mode == CS_MODE_SYSFS)
		coresight_enable_all_source_link();

	return 0;
}