• Benjamin Herrenschmidt's avatar
    drm: Round size of SHM maps to PAGE_SIZE · b6741377
    Benjamin Herrenschmidt authored
    Currently, userspace can fail to obtain the SAREA mapping (among other
    reasons) if it passes SAREA_MAX to drmAddMap without aligning it to the
    page size. This breaks for example on PowerPC with 64K pages and radeon
    despite the kernel radeon actually doing the right rouding in the first
    place.
    
    The way SAREA_MAX is defined with a bunch of ifdef's and duplicated
    between libdrm and the X server is gross, ultimately it should be
    retrieved by userspace from the kernel, but in the meantime, we have
    plenty of existing userspace built with bad values that need to work.
    
    This patch works around broken userspace by rounding the requested size
    in drm_addmap_core() of any SHM map to the page size. Since the backing
    memory for SHM maps is also allocated within addmap_core, there is no
    danger of adjacent memory being exposed due to the increased map size.
    The only side effect is that drivers that previously tried to create or
    access SHM maps using a size < PAGE_SIZE and failed (getting -EINVAL),
    will now succeed at the cost of a little bit more memory used if that
    happens to be when the map is created.
    Signed-off-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
    Signed-off-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
    b6741377
drm_bufs.c 44.9 KB