Skip to content

Commit ce2f46f

Browse files
Oleksandr Andrushchenkojgross1
authored andcommitted
xen/gntdev: fix unmap notification order
While working with Xen's libxenvchan library I have faced an issue with unmap notifications sent in wrong order if both UNMAP_NOTIFY_SEND_EVENT and UNMAP_NOTIFY_CLEAR_BYTE were requested: first we send an event channel notification and then clear the notification byte which renders in the below inconsistency (cli_live is the byte which was requested to be cleared on unmap): [ 444.514243] gntdev_put_map UNMAP_NOTIFY_SEND_EVENT map->notify.event 6 libxenvchan_is_open cli_live 1 [ 444.515239] __unmap_grant_pages UNMAP_NOTIFY_CLEAR_BYTE at 14 Thus it is not possible to reliably implement the checks like - wait for the notification (UNMAP_NOTIFY_SEND_EVENT) - check the variable (UNMAP_NOTIFY_CLEAR_BYTE) because it is possible that the variable gets checked before it is cleared by the kernel. To fix that we need to re-order the notifications, so the variable is first gets cleared and then the event channel notification is sent. With this fix I can see the correct order of execution: [ 54.522611] __unmap_grant_pages UNMAP_NOTIFY_CLEAR_BYTE at 14 [ 54.537966] gntdev_put_map UNMAP_NOTIFY_SEND_EVENT map->notify.event 6 libxenvchan_is_open cli_live 0 Cc: [email protected] Signed-off-by: Oleksandr Andrushchenko <[email protected]> Reviewed-by: Boris Ostrovsky <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Juergen Gross <[email protected]>
1 parent c9e6606 commit ce2f46f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/xen/gntdev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,13 @@ void gntdev_put_map(struct gntdev_priv *priv, struct gntdev_grant_map *map)
250250
if (!refcount_dec_and_test(&map->users))
251251
return;
252252

253+
if (map->pages && !use_ptemod)
254+
unmap_grant_pages(map, 0, map->count);
255+
253256
if (map->notify.flags & UNMAP_NOTIFY_SEND_EVENT) {
254257
notify_remote_via_evtchn(map->notify.event);
255258
evtchn_put(map->notify.event);
256259
}
257-
258-
if (map->pages && !use_ptemod)
259-
unmap_grant_pages(map, 0, map->count);
260260
gntdev_free_map(map);
261261
}
262262

0 commit comments

Comments
 (0)