OSDN Git Service

xen/gntdev: replace global limit of mapped pages by limit per call
authorJuergen Gross <jgross@suse.com>
Thu, 7 Nov 2019 11:15:45 +0000 (12:15 +0100)
committerJuergen Gross <jgross@suse.com>
Mon, 2 Dec 2019 06:39:18 +0000 (07:39 +0100)
commit3b06ac6707c196b5036fe013c460da86c9060085
treed6f3af7ef5da97dd674cb2461e30db2297457fbc
parentd41b26d81a83e04500e926fbab746ae87c20bb0e
xen/gntdev: replace global limit of mapped pages by limit per call

Today there is a global limit of pages mapped via /dev/xen/gntdev set
to 1 million pages per default. There is no reason why that limit is
existing, as total number of grant mappings is limited by the
hypervisor anyway and preferring kernel mappings over userspace ones
doesn't make sense. It should be noted that the gntdev device is
usable by root only.

Additionally checking of that limit is fragile, as the number of pages
to map via one call is specified in a 32-bit unsigned variable which
isn't tested to stay within reasonable limits (the only test is the
value to be <= zero, which basically excludes only calls without any
mapping requested). So trying to map e.g. 0xffff0000 pages while
already nearly 1000000 pages are mapped will effectively lower the
global number of mapped pages such that a parallel call mapping a
reasonable amount of pages can succeed in spite of the global limit
being violated.

So drop the global limit and introduce per call limit instead. This
per call limit (default: 65536 grant mappings) protects against
allocating insane large arrays in the kernel for doing a hypercall
which will fail anyway in case a user is e.g. trying to map billions
of pages.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
drivers/xen/gntdev-common.h
drivers/xen/gntdev-dmabuf.c
drivers/xen/gntdev.c