History

Drivers: hv: vmbus: Fix race condition with new ring_buffer_info mutex

Fix a race condition that can result in a ring buffer pointer being set to null while a "_show" function is reading the ring buffer's data. This problem was discussed here: https://lkml.org/lkml/2018/10/18/779 To fix the race condition, add a new mutex lock to the "hv_ring_buffer_info" struct. Add a new function, "hv_ringbuffer_pre_init()", where a channel's inbound and outbound ring_buffer_info mutex locks are initialized. Acquire/release the locks in the "hv_ringbuffer_cleanup()" function, which is where the ring buffer pointers are set to null. Acquire/release the locks in the four channel-level "_show" functions that access ring buffer data. Remove the "const" qualifier from the "vmbus_channel" parameter and the "rbi" variable of the channel-level "_show" functions so that the locks can be acquired/released in these functions. Acquire/release the locks in hv_ringbuffer_get_debuginfo(). Remove the "const" qualifier from the "hv_ring_buffer_info" parameter so that the locks can be acquired/released in this function.

Kimberly Brown committed 7 years ago

Commit 14948e31 parent 4713eb75 files · +79 −32Browse files

Showing the changes to include/linux (1 of 5 files). Show all

Unified · Split

include/linux/hyperv.h+6−1
@@ -141,6 +141,11 @@ struct hv_ring_buffer_info { · 140 unmodified lines
141141
142142 u32 ring_datasize; /* < ring_size */
143143 u32 priv_read_index;
144+ /*
145+ * The ring buffer mutex lock. This lock prevents the ring buffer from
146+ * being freed while the ring buffer is being accessed.
147+ */
148+ struct mutex ring_buffer_mutex;
144149 };
145150
146151
@@ -1206,7 +1211,7 @@ struct hv_ring_buffer_debug_info { · 1059 unmodified lines
12061211 };
12071212
12081213
1209−int hv_ringbuffer_get_debuginfo(const struct hv_ring_buffer_info *ring_info,
1214+int hv_ringbuffer_get_debuginfo(struct hv_ring_buffer_info *ring_info,
12101215 struct hv_ring_buffer_debug_info *debug_info);
12111216
12121217 /* Vmbus interface */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t