diff options
author | Vitaly Kuznetsov <vkuznets@redhat.com> | 2015-03-27 12:10:13 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-04-03 10:18:02 -0400 |
commit | 0a1a86ac046091d7228c9f3a283dea5be96275dd (patch) | |
tree | cf4eca600c160ec8a00cbdd4f24794e246e0d822 | |
parent | 7fb0e1a65075a871c58cbcf8c877d1f9ae5cd83c (diff) |
Drivers: hv: hv_balloon: survive ballooning request with num_pages=0
... and simplify alloc_balloon_pages() interface by removing redundant
alloc_error from it.
If we happen to enter balloon_up() with balloon_wrk.num_pages = 0 we will enter
infinite 'while (!done)' loop as alloc_balloon_pages() will be always returning
0 and not setting alloc_error. We will also be sending a meaningless message to
the host on every iteration.
The 'alloc_unit == 1 && alloc_error -> num_ballooned == 0' change and
alloc_error elimination requires a special comment. We do alloc_balloon_pages()
with 2 different alloc_unit values and there are 4 different
alloc_balloon_pages() results, let's check them all.
alloc_unit = 512:
1) num_ballooned = 0, alloc_error = 0: we do 'alloc_unit=1' and retry pre- and
post-patch.
2) num_ballooned > 0, alloc_error = 0: we check 'num_ballooned == num_pages'
and act accordingly, pre- and post-patch.
3) num_ballooned > 0, alloc_error > 0: we report this chunk and remain within
the loop, no changes here.
4) num_ballooned = 0, alloc_error > 0: we do 'alloc_unit=1' and retry pre- and
post-patch.
alloc_unit = 1:
1) num_ballooned = 0, alloc_error = 0: this can happen in two cases: when we
passed 'num_pages=0' to alloc_balloon_pages() or when there was no space in
bl_resp to place a single response. The second option is not possible as
bl_resp is of PAGE_SIZE size and single response 'union dm_mem_page_range' is
8 bytes, but the first one is (in theory, I think that Hyper-V host never
places such requests). Pre-patch code loops forever, post-patch code sends
a reply with more_pages = 0 and finishes.
2) num_ballooned > 0, alloc_error = 0: we ran out of space in bl_resp, we
report partial success and remain within the loop, no changes pre- and
post-patch.
3) num_ballooned > 0, alloc_error > 0: pre-patch code finishes, post-patch code
does one more try and if there is no progress (we finish with
'num_ballooned = 0') we finish. So we try a bit harder with this patch.
4) num_ballooned = 0, alloc_error > 0: both pre- and post-patch code enter
'more_pages = 0' branch and finish.
So this patch has two real effects:
1) We reply with an empty response to 'num_pages=0' request.
2) We try a bit harder on alloc_unit=1 allocations (and reply with an empty
tail reply in case we fail).
An empty reply should be supported by host as we were able to send it even with
pre-patch code when we were not able to allocate a single page.
Suggested-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/hv/hv_balloon.c | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index 4f5323cedab3..74312c88534a 100644 --- a/drivers/hv/hv_balloon.c +++ b/drivers/hv/hv_balloon.c | |||
@@ -1081,9 +1081,9 @@ static void free_balloon_pages(struct hv_dynmem_device *dm, | |||
1081 | 1081 | ||
1082 | 1082 | ||
1083 | 1083 | ||
1084 | static int alloc_balloon_pages(struct hv_dynmem_device *dm, int num_pages, | 1084 | static int alloc_balloon_pages(struct hv_dynmem_device *dm, int num_pages, |
1085 | struct dm_balloon_response *bl_resp, int alloc_unit, | 1085 | struct dm_balloon_response *bl_resp, |
1086 | bool *alloc_error) | 1086 | int alloc_unit) |
1087 | { | 1087 | { |
1088 | int i = 0; | 1088 | int i = 0; |
1089 | struct page *pg; | 1089 | struct page *pg; |
@@ -1104,11 +1104,8 @@ static int alloc_balloon_pages(struct hv_dynmem_device *dm, int num_pages, | |||
1104 | __GFP_NOMEMALLOC | __GFP_NOWARN, | 1104 | __GFP_NOMEMALLOC | __GFP_NOWARN, |
1105 | get_order(alloc_unit << PAGE_SHIFT)); | 1105 | get_order(alloc_unit << PAGE_SHIFT)); |
1106 | 1106 | ||
1107 | if (!pg) { | 1107 | if (!pg) |
1108 | *alloc_error = true; | ||
1109 | return i * alloc_unit; | 1108 | return i * alloc_unit; |
1110 | } | ||
1111 | |||
1112 | 1109 | ||
1113 | dm->num_pages_ballooned += alloc_unit; | 1110 | dm->num_pages_ballooned += alloc_unit; |
1114 | 1111 | ||
@@ -1140,7 +1137,6 @@ static void balloon_up(struct work_struct *dummy) | |||
1140 | struct dm_balloon_response *bl_resp; | 1137 | struct dm_balloon_response *bl_resp; |
1141 | int alloc_unit; | 1138 | int alloc_unit; |
1142 | int ret; | 1139 | int ret; |
1143 | bool alloc_error; | ||
1144 | bool done = false; | 1140 | bool done = false; |
1145 | int i; | 1141 | int i; |
1146 | struct sysinfo val; | 1142 | struct sysinfo val; |
@@ -1173,18 +1169,15 @@ static void balloon_up(struct work_struct *dummy) | |||
1173 | 1169 | ||
1174 | 1170 | ||
1175 | num_pages -= num_ballooned; | 1171 | num_pages -= num_ballooned; |
1176 | alloc_error = false; | ||
1177 | num_ballooned = alloc_balloon_pages(&dm_device, num_pages, | 1172 | num_ballooned = alloc_balloon_pages(&dm_device, num_pages, |
1178 | bl_resp, alloc_unit, | 1173 | bl_resp, alloc_unit); |
1179 | &alloc_error); | ||
1180 | 1174 | ||
1181 | if (alloc_unit != 1 && num_ballooned == 0) { | 1175 | if (alloc_unit != 1 && num_ballooned == 0) { |
1182 | alloc_unit = 1; | 1176 | alloc_unit = 1; |
1183 | continue; | 1177 | continue; |
1184 | } | 1178 | } |
1185 | 1179 | ||
1186 | if ((alloc_unit == 1 && alloc_error) || | 1180 | if (num_ballooned == 0 || num_ballooned == num_pages) { |
1187 | (num_ballooned == num_pages)) { | ||
1188 | bl_resp->more_pages = 0; | 1181 | bl_resp->more_pages = 0; |
1189 | done = true; | 1182 | done = true; |
1190 | dm_device.state = DM_INITIALIZED; | 1183 | dm_device.state = DM_INITIALIZED; |