aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Beulich <JBeulich@suse.com>2016-05-04 09:02:36 -0400
committerDavid Vrabel <david.vrabel@citrix.com>2016-05-04 11:37:01 -0400
commit27e0e6385377c4dc68a4ddaf1a35a2dfa951f3c5 (patch)
tree940f070cecbb3f335be0c1f976a472c990ebf4ab
parentdfd74a1edfaba5864276a2859190a8d242d18952 (diff)
xen/evtchn: fix ring resize when binding new events
The copying of ring data was wrong for two cases: For a full ring nothing got copied at all (as in that case the canonicalized producer and consumer indexes are identical). And in case one or both of the canonicalized (after the resize) indexes would point into the second half of the buffer, the copied data ended up in the wrong (free) part of the new buffer. In both cases uninitialized data would get passed back to the caller. Fix this by simply copying the old ring contents twice: Once to the low half of the new buffer, and a second time to the high half. This addresses the inability to boot a HVM guest with 64 or more vCPUs. This regression was caused by 8620015499101090 (xen/evtchn: dynamically grow pending event channel ring). Reported-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Signed-off-by: Jan Beulich <jbeulich@suse.com> Cc: <stable@vger.kernel.org> # 4.4+ Signed-off-by: David Vrabel <david.vrabel@citrix.com>
-rw-r--r--drivers/xen/evtchn.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/drivers/xen/evtchn.c b/drivers/xen/evtchn.c
index 38272ad24551..f4edd6df3df2 100644
--- a/drivers/xen/evtchn.c
+++ b/drivers/xen/evtchn.c
@@ -316,7 +316,6 @@ static int evtchn_resize_ring(struct per_user_data *u)
316{ 316{
317 unsigned int new_size; 317 unsigned int new_size;
318 evtchn_port_t *new_ring, *old_ring; 318 evtchn_port_t *new_ring, *old_ring;
319 unsigned int p, c;
320 319
321 /* 320 /*
322 * Ensure the ring is large enough to capture all possible 321 * Ensure the ring is large enough to capture all possible
@@ -346,20 +345,17 @@ static int evtchn_resize_ring(struct per_user_data *u)
346 /* 345 /*
347 * Copy the old ring contents to the new ring. 346 * Copy the old ring contents to the new ring.
348 * 347 *
349 * If the ring contents crosses the end of the current ring, 348 * To take care of wrapping, a full ring, and the new index
350 * it needs to be copied in two chunks. 349 * pointing into the second half, simply copy the old contents
350 * twice.
351 * 351 *
352 * +---------+ +------------------+ 352 * +---------+ +------------------+
353 * |34567 12| -> | 1234567 | 353 * |34567 12| -> |34567 1234567 12|
354 * +-----p-c-+ +------------------+ 354 * +-----p-c-+ +-------c------p---+
355 */ 355 */
356 p = evtchn_ring_offset(u, u->ring_prod); 356 memcpy(new_ring, old_ring, u->ring_size * sizeof(*u->ring));
357 c = evtchn_ring_offset(u, u->ring_cons); 357 memcpy(new_ring + u->ring_size, old_ring,
358 if (p < c) { 358 u->ring_size * sizeof(*u->ring));
359 memcpy(new_ring + c, u->ring + c, (u->ring_size - c) * sizeof(*u->ring));
360 memcpy(new_ring + u->ring_size, u->ring, p * sizeof(*u->ring));
361 } else
362 memcpy(new_ring + c, u->ring + c, (p - c) * sizeof(*u->ring));
363 359
364 u->ring = new_ring; 360 u->ring = new_ring;
365 u->ring_size = new_size; 361 u->ring_size = new_size;