Ensure that we correctly handle racing invocations of the channel callback
when the channel is being closed. We do this using the channel's inbound_lock.
A side-effect of this strategy is that we avoid repeatedly picking up this lock
as we drain the inbound ring-buffer.
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
{
struct vmbus_channel_close_channel *msg;
int ret;
{
struct vmbus_channel_close_channel *msg;
int ret;
/* Stop callback and cancel the timer asap */
/* Stop callback and cancel the timer asap */
+ spin_lock_irqsave(&channel->inbound_lock, flags);
channel->onchannel_callback = NULL;
channel->onchannel_callback = NULL;
+ spin_unlock_irqrestore(&channel->inbound_lock, flags);
/* Send a closing message */
/* Send a closing message */
u32 packetlen;
u32 userlen;
int ret;
u32 packetlen;
u32 userlen;
int ret;
*buffer_actual_len = 0;
*requestid = 0;
*buffer_actual_len = 0;
*requestid = 0;
- spin_lock_irqsave(&channel->inbound_lock, flags);
ret = hv_ringbuffer_peek(&channel->inbound, &desc,
sizeof(struct vmpacket_descriptor));
ret = hv_ringbuffer_peek(&channel->inbound, &desc,
sizeof(struct vmpacket_descriptor));
- if (ret != 0) {
- spin_unlock_irqrestore(&channel->inbound_lock, flags);
packetlen = desc.len8 << 3;
userlen = packetlen - (desc.offset8 << 3);
packetlen = desc.len8 << 3;
userlen = packetlen - (desc.offset8 << 3);
*buffer_actual_len = userlen;
if (userlen > bufferlen) {
*buffer_actual_len = userlen;
if (userlen > bufferlen) {
- spin_unlock_irqrestore(&channel->inbound_lock, flags);
pr_err("Buffer too small - got %d needs %d\n",
bufferlen, userlen);
pr_err("Buffer too small - got %d needs %d\n",
bufferlen, userlen);
ret = hv_ringbuffer_read(&channel->inbound, buffer, userlen,
(desc.offset8 << 3));
ret = hv_ringbuffer_read(&channel->inbound, buffer, userlen,
(desc.offset8 << 3));
- spin_unlock_irqrestore(&channel->inbound_lock, flags);
u32 packetlen;
u32 userlen;
int ret;
u32 packetlen;
u32 userlen;
int ret;
*buffer_actual_len = 0;
*requestid = 0;
*buffer_actual_len = 0;
*requestid = 0;
- spin_lock_irqsave(&channel->inbound_lock, flags);
ret = hv_ringbuffer_peek(&channel->inbound, &desc,
sizeof(struct vmpacket_descriptor));
ret = hv_ringbuffer_peek(&channel->inbound, &desc,
sizeof(struct vmpacket_descriptor));
- if (ret != 0) {
- spin_unlock_irqrestore(&channel->inbound_lock, flags);
packetlen = desc.len8 << 3;
packetlen = desc.len8 << 3;
*buffer_actual_len = packetlen;
if (packetlen > bufferlen) {
*buffer_actual_len = packetlen;
if (packetlen > bufferlen) {
- spin_unlock_irqrestore(&channel->inbound_lock, flags);
-
pr_err("Buffer too small - needed %d bytes but "
"got space for only %d bytes\n",
packetlen, bufferlen);
pr_err("Buffer too small - needed %d bytes but "
"got space for only %d bytes\n",
packetlen, bufferlen);
/* Copy over the entire packet to the user buffer */
ret = hv_ringbuffer_read(&channel->inbound, buffer, packetlen, 0);
/* Copy over the entire packet to the user buffer */
ret = hv_ringbuffer_read(&channel->inbound, buffer, packetlen, 0);
- spin_unlock_irqrestore(&channel->inbound_lock, flags);
return 0;
}
EXPORT_SYMBOL_GPL(vmbus_recvpacket_raw);
return 0;
}
EXPORT_SYMBOL_GPL(vmbus_recvpacket_raw);
static void process_chn_event(u32 relid)
{
struct vmbus_channel *channel;
static void process_chn_event(u32 relid)
{
struct vmbus_channel *channel;
/*
* Find the channel based on this relid and invokes the
/*
* Find the channel based on this relid and invokes the
*/
channel = relid2channel(relid);
*/
channel = relid2channel(relid);
+ spin_lock_irqsave(&channel->inbound_lock, flags);
if (channel && (channel->onchannel_callback != NULL)) {
channel->onchannel_callback(channel->channel_callback_context);
} else {
pr_err("channel not found for relid - %u\n", relid);
}
if (channel && (channel->onchannel_callback != NULL)) {
channel->onchannel_callback(channel->channel_callback_context);
} else {
pr_err("channel not found for relid - %u\n", relid);
}
+ spin_unlock_irqrestore(&channel->inbound_lock, flags);
static struct netvsc_device *get_inbound_net_device(struct hv_device *device)
{
struct netvsc_device *net_device;
static struct netvsc_device *get_inbound_net_device(struct hv_device *device)
{
struct netvsc_device *net_device;
- spin_lock_irqsave(&device->channel->inbound_lock, flags);
net_device = device->ext;
if (!net_device)
net_device = device->ext;
if (!net_device)
net_device = NULL;
get_in_err:
net_device = NULL;
get_in_err:
- spin_unlock_irqrestore(&device->channel->inbound_lock, flags);
struct hv_device *device)
{
struct storvsc_device *stor_device;
struct hv_device *device)
{
struct storvsc_device *stor_device;
- spin_lock_irqsave(&device->channel->inbound_lock, flags);
stor_device = (struct storvsc_device *)device->ext;
if (!stor_device)
stor_device = (struct storvsc_device *)device->ext;
if (!stor_device)
stor_device = NULL;
get_in_err:
stor_device = NULL;
get_in_err:
- spin_unlock_irqrestore(&device->channel->inbound_lock, flags);