[PATCH 3/7] drm/udl: import prime-fds with proper page-alignment

David Herrmann dh.herrmann at gmail.com
Thu Jan 23 04:51:59 PST 2014


Hi

On Tue, Jan 21, 2014 at 10:41 AM, Daniel Vetter <daniel at ffwll.ch> wrote:
> On Mon, Jan 20, 2014 at 08:26:25PM +0100, David Herrmann wrote:
>> Instead of rounding down to the next lower page-boundary, round up.
>> dma-buf guarantees that we can map buffers in multiples of a page, so if
>> an exporter does not page-align, do it ourselves.
>>
>> This avoids issues if the exported buffer contains an unaligned size and
>> we crop it. In this case, the buffer is too small for the UDL CRTC. So we
>> round up to page-size now and avoid black borders. Worst case is we end up
>> reading out some random kernel memory, but we can never fault as the whole
>> page has the same access-rights. And in this case it's an issue of the
>> buggy exporting driver, not the importing one.
>>
>> Signed-off-by: David Herrmann <dh.herrmann at gmail.com>
>> ---
>>  drivers/gpu/drm/udl/udl_gem.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/udl/udl_gem.c b/drivers/gpu/drm/udl/udl_gem.c
>> index df963a1..1069e57 100644
>> --- a/drivers/gpu/drm/udl/udl_gem.c
>> +++ b/drivers/gpu/drm/udl/udl_gem.c
>> @@ -227,7 +227,7 @@ static int udl_prime_create(struct drm_device *dev,
>>       struct udl_gem_object *obj;
>>       int npages;
>>
>> -     npages = size / PAGE_SIZE;
>> +     npages = PAGE_ALIGN(size) >> PAGE_SHIFT;
>
> Imo the proper patch would be to reject exporting anything which isn't
> page-aligned as a dma-buf in the driver core (together with a quick review
> of the docs to make sure this requirement is clear). This is just a bug in
> the exporter.

Ok, I've dropped this one for now. I think the best way to deal with
it is to make dma_buf disallow any non-aligned sizes during
initialization. So we should just assume it's always page-aligned.

Thanks
David


More information about the dri-devel mailing list