Re: [PATCH] Drivers: hv: vmbus: Add mutex lock to channel show functions
From: Kimberly Brown
Date: Thu Jan 31 2019 - 12:47:14 EST
On Thu, Jan 31, 2019 at 04:45:35PM +0000, Michael Kelley wrote:
> From: Sasha Levin <sashal@xxxxxxxxxx> Sent: Thursday, January 31, 2019 7:20 AM
> >
> > I've queued this one for hyper-fixes, thanks all!
> >
>
> Actually, please hold off on queuing this one. In a conversation I had yesterday with Kim, they had identified a deadlock. Kim was going to be looking at some revisions to avoid the deadlock.
>
> Kim -- please confirm.
>
> Michael
This is correct. I need to send a v2 of this patch which addresses two
issues:
1) Check channel->state inside the mutex acquire/release in
vmbus_chan_attr_show().
2) Prevent a deadlock that can occur between the proposed mutex_lock()
call in the vmbus_chan_attr_show() function and the sysfs/kernfs functions.
I've identified two possible solutions to the deadlock:
1) Add a new mutex to the vmbus_channel struct which protects changes to
"channel->state". Use this new mutex in vmbus_chan_attr_show() instead of
"vmbus_connection.channel_mutex".
2) Use "vmbus_connection.channel_mutex" in vmbus_chan_attr_show() as
originally proposed, and acquire it with mutex_trylock(). If the mutex
cannot be acquired, return -EINVAL.
I'm leaning towards (2), using mutex_trylock(). "vmbus_connection.channel_mutex"
appears to be used only when a channel is being opened or closed, so
vmbus_chan_attr_show() should be able to acquire the mutex when the
channel is in use.
If anyone has suggestions, please let me know.
Thanks,
Kim