linux-stable/drivers/xen
Demi Marie Obenour 79963021fd xen/gntdev: Avoid blocking in unmap_grant_pages()
commit dbe97cff7d upstream.

unmap_grant_pages() currently waits for the pages to no longer be used.
In https://github.com/QubesOS/qubes-issues/issues/7481, this lead to a
deadlock against i915: i915 was waiting for gntdev's MMU notifier to
finish, while gntdev was waiting for i915 to free its pages.  I also
believe this is responsible for various deadlocks I have experienced in
the past.

Avoid these problems by making unmap_grant_pages async.  This requires
making it return void, as any errors will not be available when the
function returns.  Fortunately, the only use of the return value is a
WARN_ON(), which can be replaced by a WARN_ON when the error is
detected.  Additionally, a failed call will not prevent further calls
from being made, but this is harmless.

Because unmap_grant_pages is now async, the grant handle will be sent to
INVALID_GRANT_HANDLE too late to prevent multiple unmaps of the same
handle.  Instead, a separate bool array is allocated for this purpose.
This wastes memory, but stuffing this information in padding bytes is
too fragile.  Furthermore, it is necessary to grab a reference to the
map before making the asynchronous call, and release the reference when
the call returns.

It is also necessary to guard against reentrancy in gntdev_map_put(),
and to handle the case where userspace tries to map a mapping whose
contents have not all been freed yet.

Fixes: 745282256c ("xen/gntdev: safely unmap grants in case they are still in use")
Cc: stable@vger.kernel.org
Signed-off-by: Demi Marie Obenour <demi@invisiblethingslab.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Link: https://lore.kernel.org/r/20220622022726.2538-1-demi@invisiblethingslab.com
Signed-off-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-07-07 17:52:20 +02:00
..
events
xen-pciback xen-pciback: Fix return in pm_ctrl_init() 2021-11-18 14:04:25 +01:00
xenbus xen/xenbus: don't let xenbus_grant_ring() remove grants in error case 2022-03-11 12:11:54 +01:00
xenfs
acpi.c
arm-device.c
balloon.c xen/balloon: add late_initcall_sync() for initial ballooning done 2021-11-18 14:03:49 +01:00
biomerge.c
cpu_hotplug.c
dbgp.c
efi.c
evtchn.c
features.c x86/xen: Remove undefined behavior in setup_features() 2022-06-29 08:59:48 +02:00
gntalloc.c xen/gntalloc: don't use gnttab_query_foreign_access() 2022-03-11 12:11:54 +01:00
gntdev-common.h xen/gntdev: Avoid blocking in unmap_grant_pages() 2022-07-07 17:52:20 +02:00
gntdev-dmabuf.c
gntdev-dmabuf.h
gntdev.c xen/gntdev: Avoid blocking in unmap_grant_pages() 2022-07-07 17:52:20 +02:00
grant-table.c xen/gnttab: fix gnttab_end_foreign_access() without page specified 2022-03-11 12:11:54 +01:00
Kconfig
Makefile
manage.c
mcelog.c
mem-reservation.c
pci.c
pcpu.c
platform-pci.c
privcmd-buf.c
privcmd.c xen/privcmd: fix error handling in mmap-resource processing 2021-10-13 10:04:23 +02:00
privcmd.h
pvcalls-back.c
pvcalls-front.c xen/pvcalls: use alloc/free_pages_exact() 2022-03-11 12:11:54 +01:00
pvcalls-front.h
swiotlb-xen.c
sys-hypervisor.c
time.c
unpopulated-alloc.c
xen-acpi-cpuhotplug.c
xen-acpi-memhotplug.c
xen-acpi-pad.c
xen-acpi-processor.c
xen-balloon.c
xen-front-pgdir-shbuf.c
xen-scsiback.c
xen-stub.c
xlate_mmu.c xen: unexport __init-annotated xen_xlate_map_ballooned_pages() 2022-06-14 18:32:40 +02:00