aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-03-23 14:08:40 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-03-23 14:08:40 -0400
commit97235e74c36df450229a58edd32e2ba38cc48c6e (patch)
tree15f0b88e619d21ad626720840acc7a17565206a4
parentcde00d2169b1f66349e1e89e2ef775f47e6ef27d (diff)
parent655296c8bbeffcf020558c4455305d597a73bde1 (diff)
Merge tag 'char-misc-4.16-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc
Pull hyperv fix from Greg KH: "This is a single hyperv bugfix for 4.16-rc7. It resolves an issue with the ring-buffer signaling to resolve reported problems. It's been in linux-next for a while now with no reported issues" * tag 'char-misc-4.16-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: Drivers: hv: vmbus: Fix ring buffer signaling
-rw-r--r--drivers/hv/ring_buffer.c52
1 files changed, 35 insertions, 17 deletions
diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index 50e071444a5c..8699bb969e7e 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -417,13 +417,24 @@ __hv_pkt_iter_next(struct vmbus_channel *channel,
417} 417}
418EXPORT_SYMBOL_GPL(__hv_pkt_iter_next); 418EXPORT_SYMBOL_GPL(__hv_pkt_iter_next);
419 419
420/* How many bytes were read in this iterator cycle */
421static u32 hv_pkt_iter_bytes_read(const struct hv_ring_buffer_info *rbi,
422 u32 start_read_index)
423{
424 if (rbi->priv_read_index >= start_read_index)
425 return rbi->priv_read_index - start_read_index;
426 else
427 return rbi->ring_datasize - start_read_index +
428 rbi->priv_read_index;
429}
430
420/* 431/*
421 * Update host ring buffer after iterating over packets. 432 * Update host ring buffer after iterating over packets.
422 */ 433 */
423void hv_pkt_iter_close(struct vmbus_channel *channel) 434void hv_pkt_iter_close(struct vmbus_channel *channel)
424{ 435{
425 struct hv_ring_buffer_info *rbi = &channel->inbound; 436 struct hv_ring_buffer_info *rbi = &channel->inbound;
426 u32 orig_write_sz = hv_get_bytes_to_write(rbi); 437 u32 curr_write_sz, pending_sz, bytes_read, start_read_index;
427 438
428 /* 439 /*
429 * Make sure all reads are done before we update the read index since 440 * Make sure all reads are done before we update the read index since
@@ -431,8 +442,12 @@ void hv_pkt_iter_close(struct vmbus_channel *channel)
431 * is updated. 442 * is updated.
432 */ 443 */
433 virt_rmb(); 444 virt_rmb();
445 start_read_index = rbi->ring_buffer->read_index;
434 rbi->ring_buffer->read_index = rbi->priv_read_index; 446 rbi->ring_buffer->read_index = rbi->priv_read_index;
435 447
448 if (!rbi->ring_buffer->feature_bits.feat_pending_send_sz)
449 return;
450
436 /* 451 /*
437 * Issue a full memory barrier before making the signaling decision. 452 * Issue a full memory barrier before making the signaling decision.
438 * Here is the reason for having this barrier: 453 * Here is the reason for having this barrier:
@@ -446,26 +461,29 @@ void hv_pkt_iter_close(struct vmbus_channel *channel)
446 */ 461 */
447 virt_mb(); 462 virt_mb();
448 463
449 /* If host has disabled notifications then skip */ 464 pending_sz = READ_ONCE(rbi->ring_buffer->pending_send_sz);
450 if (rbi->ring_buffer->interrupt_mask) 465 if (!pending_sz)
451 return; 466 return;
452 467
453 if (rbi->ring_buffer->feature_bits.feat_pending_send_sz) { 468 /*
454 u32 pending_sz = READ_ONCE(rbi->ring_buffer->pending_send_sz); 469 * Ensure the read of write_index in hv_get_bytes_to_write()
470 * happens after the read of pending_send_sz.
471 */
472 virt_rmb();
473 curr_write_sz = hv_get_bytes_to_write(rbi);
474 bytes_read = hv_pkt_iter_bytes_read(rbi, start_read_index);
455 475
456 /* 476 /*
457 * If there was space before we began iteration, 477 * If there was space before we began iteration,
458 * then host was not blocked. Also handles case where 478 * then host was not blocked.
459 * pending_sz is zero then host has nothing pending 479 */
460 * and does not need to be signaled.
461 */
462 if (orig_write_sz > pending_sz)
463 return;
464 480
465 /* If pending write will not fit, don't give false hope. */ 481 if (curr_write_sz - bytes_read > pending_sz)
466 if (hv_get_bytes_to_write(rbi) < pending_sz) 482 return;
467 return; 483
468 } 484 /* If pending write will not fit, don't give false hope. */
485 if (curr_write_sz <= pending_sz)
486 return;
469 487
470 vmbus_setevent(channel); 488 vmbus_setevent(channel);
471} 489}