intel_th: msu: Prevent freeing buffers while locked windows exist
authorAlexander Shishkin <alexander.shishkin@linux.intel.com>
Fri, 5 Jul 2019 14:14:24 +0000 (17:14 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Jul 2019 11:03:19 +0000 (13:03 +0200)
We already prevent freeing buffers via sysfs interface in case there are
existing users or if trace is active. Treat the existence of locked windows
similarly and return -EBUSY on attempts to free the buffer. When the last
window is unlocked, the freeing will succeed.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20190705141425.19894-5-alexander.shishkin@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/hwtracing/intel_th/msu.c

index a6c0eb09c515893dcb8c1725cb3c34a961f60eb7..b200d9d1c7a0383426b7ce7b8a93ef1f56519d5e 100644 (file)
@@ -724,6 +724,11 @@ static int msc_win_set_lockout(struct msc_window *win,
 
        win->lockout = new;
 
+       if (old == expect && new == WIN_LOCKED)
+               atomic_inc(&win->msc->user_count);
+       else if (old == expect && old == WIN_LOCKED)
+               atomic_dec(&win->msc->user_count);
+
 unlock:
        spin_unlock_irqrestore(&win->lo_lock, flags);