15 Jul, 2020

1 commit


21 May, 2020

1 commit

  • Some users want to pass NULL to drm_gem_object_put(), but those using
    __drm_gem_object_put() did not. Compromise, have both and let the
    compiler sort it out.

    drm_gem_fb_destroy() calls drm_gem_object_put() with NULL obj causing:
    [ 11.584209] BUG: kernel NULL pointer dereference, address: 0000000000000000
    [ 11.584213] #PF: supervisor write access in kernel mode
    [ 11.584215] #PF: error_code(0x0002) - not-present page
    [ 11.584216] PGD 0 P4D 0
    [ 11.584220] Oops: 0002 [#1] SMP NOPTI
    [ 11.584223] CPU: 7 PID: 1571 Comm: gnome-shell Tainted: G E 5.7.0-rc1-1-default+ #27
    [ 11.584225] Hardware name: Micro-Star International Co., Ltd. MS-7A31/X370 XPOWER GAMING TITANIUM (MS-7A31), BIOS 1.MR 12/03/2019
    [ 11.584237] RIP: 0010:drm_gem_fb_destroy+0x28/0x70 [drm_kms_helper]

    [ 11.584256] Call Trace:
    [ 11.584279] drm_mode_rmfb+0x189/0x1c0 [drm]
    [ 11.584299] ? drm_mode_rmfb+0x1c0/0x1c0 [drm]
    [ 11.584314] drm_ioctl_kernel+0xaa/0xf0 [drm]
    [ 11.584329] drm_ioctl+0x1ff/0x3b0 [drm]
    [ 11.584347] ? drm_mode_rmfb+0x1c0/0x1c0 [drm]
    [ 11.584421] amdgpu_drm_ioctl+0x49/0x80 [amdgpu]
    [ 11.584427] ksys_ioctl+0x87/0xc0
    [ 11.584430] __x64_sys_ioctl+0x16/0x20
    [ 11.584434] do_syscall_64+0x5f/0x240
    [ 11.584438] entry_SYSCALL_64_after_hwframe+0x44/0xa9
    [ 11.584440] RIP: 0033:0x7f0ef80f7227

    Reported-by: Nirmoy Das
    Fixes: b5d250744ccc ("drm/gem: fold drm_gem_object_put_unlocked and __drm_gem_object_put()")
    Signed-off-by: Chris Wilson
    Cc: Nirmoy Das
    Cc: Emil Velikov
    Cc: Christian König .
    Acked-by: Nirmoy Das
    Reviewed-by: Emil Velikov
    Link: https://patchwork.freedesktop.org/patch/msgid/20200520142347.29060-1-chris@chris-wilson.co.uk

    Chris Wilson
     

20 May, 2020

6 commits

  • As of last commit, all the drivers have been updated away from the
    _unlocked helper. As such we can now remove the transient #define.

    v2: keep sed and #define removal separate

    Cc: David Airlie
    Cc: Daniel Vetter
    Signed-off-by: Emil Velikov
    Acked-by: Sam Ravnborg (v1)
    Acked-by: Thomas Zimmermann
    Link: https://patchwork.freedesktop.org/patch/msgid/20200515095118.2743122-39-emil.l.velikov@gmail.com

    Emil Velikov
     
  • Spelling out _unlocked for each and every driver is a annoying.
    Especially if we consider how many drivers, do not know (or need to)
    about the horror stories involving struct_mutex.

    Just drop the suffix. It makes the API cleaner.

    Done via the following script:

    __from=drm_gem_object_put_unlocked
    __to=drm_gem_object_put
    for __file in $(git grep --name-only $__from); do
    sed -i "s/$__from/$__to/g" $__file;
    done

    Pay special attention to the compat #define

    v2: keep sed and #define removal separate

    Cc: David Airlie
    Cc: Daniel Vetter
    Signed-off-by: Emil Velikov
    Acked-by: Sam Ravnborg (v1)
    Reviewed-by: Steven Price
    Acked-by: Thomas Zimmermann
    Link: https://patchwork.freedesktop.org/patch/msgid/20200515095118.2743122-14-emil.l.velikov@gmail.com

    Emil Velikov
     
  • Spelling out _unlocked for each and every driver is a annoying.
    Especially if we consider how many drivers, do not know (or need to)
    about the horror stories involving struct_mutex.

    Add helper, which will allow us to transition the drivers one by one,
    dropping the suffix.

    v2: add missing space after function name (Jani)

    Signed-off-by: Emil Velikov
    Acked-by: Sam Ravnborg (v1)
    Reviewed-by: Steven Price
    Acked-by: Thomas Zimmermann
    Link: https://patchwork.freedesktop.org/patch/msgid/20200515095118.2743122-13-emil.l.velikov@gmail.com

    Emil Velikov
     
  • Vast majority of DRM (core and drivers) are struct_mutex free.

    As such we have only a handful of cases where the locked helper should
    be used. Make that stand out a little bit better.

    Done via the following script:

    __from=drm_gem_object_put
    __to=drm_gem_object_put_locked

    for __file in $(git grep --name-only --word-regexp $__from); do
    sed -i "s/\/$__to/g" $__file;
    done

    Cc: Rob Clark
    Cc: Sean Paul
    Cc: linux-arm-msm@vger.kernel.org
    Signed-off-by: Emil Velikov
    Acked-by: Sam Ravnborg
    Reviewed-by: Steven Price
    Acked-by: Thomas Zimmermann
    Link: https://patchwork.freedesktop.org/patch/msgid/20200515095118.2743122-12-emil.l.velikov@gmail.com

    Emil Velikov
     
  • With earlier patch we removed the overhead so now we can lift the helper
    into the header effectively folding it with __drm_object_put.

    v2: drop struct_mutex references (Daniel)

    Signed-off-by: Emil Velikov
    Acked-by: Sam Ravnborg (v1)
    Reviewed-by: Daniel Vetter
    Acked-by: Thomas Zimmermann
    Link: https://patchwork.freedesktop.org/patch/msgid/20200515095118.2743122-11-emil.l.velikov@gmail.com

    Emil Velikov
     
  • No drivers set the callback, so remove it all together.

    Signed-off-by: Emil Velikov
    Acked-by: Sam Ravnborg
    Reviewed-by: Thomas Zimmermann
    Reviewed-by: Daniel Vetter
    Link: https://patchwork.freedesktop.org/patch/msgid/20200515095118.2743122-10-emil.l.velikov@gmail.com

    Emil Velikov
     

06 Dec, 2019

1 commit

  • The fake offset is going to stay, so change the calling convention for
    drm_gem_object_funcs.mmap to include the fake offset. Update all users
    accordingly.

    Note that this reverts 83b8a6f242ea ("drm/gem: Fix mmap fake offset
    handling for drm_gem_object_funcs.mmap") and on top then adds the fake
    offset to drm_gem_prime_mmap to make sure all paths leading to
    obj->funcs->mmap are consistent.

    v3: move fake-offset tweak in drm_gem_prime_mmap() so we have this code
    only once in the function (Rob Herring).

    Fixes: 83b8a6f242ea ("drm/gem: Fix mmap fake offset handling for drm_gem_object_funcs.mmap")
    Cc: Daniel Vetter
    Cc: Rob Herring
    Signed-off-by: Gerd Hoffmann
    Reviewed-by: Daniel Vetter
    Link: http://patchwork.freedesktop.org/patch/msgid/20191127092523.5620-2-kraxel@redhat.com

    Gerd Hoffmann
     

30 Oct, 2019

1 commit

  • Commit c40069cb7bd6 ("drm: add mmap() to drm_gem_object_funcs")
    introduced a GEM object mmap() hook which is expected to subtract the
    fake offset from vm_pgoff. However, for mmap() on dmabufs, there is not
    a fake offset.

    To fix this, let's always call mmap() object callback with an offset of 0,
    and leave it up to drm_gem_mmap_obj() to remove the fake offset.

    TTM still needs the fake offset, so we have to add it back until that's
    fixed.

    Fixes: c40069cb7bd6 ("drm: add mmap() to drm_gem_object_funcs")
    Cc: Gerd Hoffmann
    Cc: Daniel Vetter
    Signed-off-by: Rob Herring
    Acked-by: Gerd Hoffmann
    Reviewed-by: Daniel Vetter
    Link: https://patchwork.freedesktop.org/patch/msgid/20191024191859.31700-1-robh@kernel.org

    Rob Herring
     

17 Oct, 2019

1 commit

  • drm_gem_object_funcs->vm_ops alone can't handle everything which needs
    to be done for mmap(), tweaking vm_flags for example. So add a new
    mmap() callback to drm_gem_object_funcs where this code can go to.

    Note that the vm_ops field is not used in case the mmap callback is
    present, it is expected that the callback sets vma->vm_ops instead.

    Also setting vm_flags and vm_page_prot is the job of the new callback.
    so drivers have more control over these flags.

    drm_gem_mmap_obj() will use the new callback for object specific mmap
    setup. With this in place the need for driver-speific fops->mmap
    callbacks goes away, drm_gem_mmap can be hooked instead.

    drm_gem_prime_mmap() will use the new callback too to just mmap gem
    objects directly instead of jumping though loops to make
    drm_gem_object_lookup() and fops->mmap work.

    Signed-off-by: Gerd Hoffmann
    Reviewed-by: Daniel Vetter
    Link: http://patchwork.freedesktop.org/patch/msgid/20191016115203.20095-2-kraxel@redhat.com

    Gerd Hoffmann
     

13 Aug, 2019

1 commit


07 Aug, 2019

2 commits


04 Jul, 2019

1 commit


29 Jun, 2019

1 commit


21 Jun, 2019

1 commit

  • Yes this is a bit a big patch, but since it's essentially a complete
    rewrite of all the prime docs I didn't see how to better split it up.

    Changes:
    - Consistently point to drm_gem_object_funcs as the preferred hooks,
    where applicable.

    - Document all the hooks in &drm_driver that lacked kerneldoc.

    - Completely new overview section, which now also includes the cleaned
    up lifetime/reference counting subchapter. I also mentioned the weak
    references in there due to the lookup caches.

    - Completely rewritten helper intro section, highlight the
    import/export related functionality.

    - Polish for all the functions and more cross references.

    I also sprinkled a bunch of todos all over.

    Most important: 0 code changes in here. The cleanup motivated by
    reading and improving all this will follow later on.

    v2: Actually update the prime helper docs. Plus add a few FIXMEs that
    I won't address right away in subsequent cleanup patches.

    v3:
    - Split out the function moving. This patch is now exclusively
    documentation changes.
    - Typos and nits (Sam).

    v4: Polish suggestions from Noralf.

    Acked-by: Gerd Hoffmann
    Acked-by: Emil Velikov
    Acked-by: Noralf Trønnes
    Cc: Thomas Zimmermann
    Cc: Gerd Hoffmann
    Cc: Noralf Trønnes
    Cc: Sam Ravnborg
    Cc: Eric Anholt
    Cc: Emil Velikov
    Signed-off-by: Daniel Vetter
    Link: https://patchwork.freedesktop.org/patch/msgid/20190620124615.24434-1-daniel.vetter@ffwll.ch

    Daniel Vetter
     

17 Jun, 2019

1 commit


17 Apr, 2019

1 commit

  • I needed to add implicit dependency support for v3d, and Rob Herring
    has been working on it for panfrost, and I had recently looked at the
    lima implementation so I think this will be a good intersection of
    what we all want and simplify our scheduler implementations.

    v2: Rebase on xa_limit_32b API change, and tiny checkpatch cleanups on
    the way in (unsigned int vs unsigned, extra return before
    EXPORT_SYMBOL_GPL)

    Signed-off-by: Eric Anholt
    Link: https://patchwork.freedesktop.org/patch/msgid/20190401222635.25013-6-eric@anholt.net
    Reviewed-and-tested-by: Qiang Yu (v1)

    Eric Anholt
     

13 Apr, 2019

1 commit

  • Similar to the single handle drm_gem_object_lookup(),
    drm_gem_objects_lookup() takes an array of handles and returns an array
    of GEM objects.

    v2:
    - Take the userspace pointer directly and allocate the array.
    - Expand the function documentation.

    Cc: Maarten Lankhorst
    Cc: Maxime Ripard
    Cc: Sean Paul
    Cc: David Airlie
    Cc: Daniel Vetter
    Acked-by: Alyssa Rosenzweig
    Acked-by: Tomeu Vizoso
    Signed-off-by: Rob Herring
    Link: https://patchwork.freedesktop.org/patch/msgid/20190409205427.6943-3-robh@kernel.org

    Rob Herring
     

15 Mar, 2019

1 commit

  • Now that we have the reservation object in the GEM object, it's easy
    to provide a helper for this common case. Noticed while reviewing
    panfrost and lima drivers. This particular version came out of v3d,
    which in turn was a copy from vc4.

    v2: Fix kerneldoc warnings.

    Signed-off-by: Eric Anholt
    Link: https://patchwork.freedesktop.org/patch/msgid/20190308161716.2466-2-eric@anholt.net
    Acked-by: Rob Herring (v1)

    Eric Anholt
     

19 Feb, 2019

1 commit

  • Many users of drm_gem_object embed a struct reservation_object into
    their subclassed struct, so let's add one to struct drm_gem_object.
    This will allow removing the reservation object from the subclasses
    and removing the ->gem_prime_res_obj callback.

    With the addition, add a drm_gem_reservation_object_wait() helper
    function for drivers to use in wait ioctls.

    Cc: Maarten Lankhorst
    Cc: Maxime Ripard
    Cc: Sean Paul
    Cc: David Airlie
    Cc: Daniel Vetter
    Signed-off-by: Rob Herring
    Acked-by: Daniel Vetter
    Reviewed-by: Eric Anholt
    Reviewed-by: Christian Gmeiner
    Link: https://patchwork.freedesktop.org/patch/msgid/20190202154158.10443-2-robh@kernel.org
    Signed-off-by: Maxime Ripard

    Rob Herring
     

25 Nov, 2018

1 commit


20 Nov, 2018

1 commit

  • This adds an optional function table on GEM objects.
    The main benefit is for drivers that support more than one type of
    memory (shmem,vram,cma) for their buffers depending on the hardware it
    runs on. With the callbacks attached to the GEM object itself, it is
    easier to have core helpers for the the various buffer types. The driver
    only has to make the decision about buffer type on GEM object creation
    and all other callbacks can be handled by the chosen helper.

    drm_driver->gem_prime_res_obj has not been added since there's a todo to
    put a reservation_object into drm_gem_object.

    v3: Add todo entry

    v2: Drop drm_gem_object_funcs->prime_mmap in favour of
    drm_gem_prime_mmap() (Daniel Vetter)

    v1:
    - drm_gem_object_funcs.map -> .prime_map let it only do PRIME mmap like
    the function it superseeds (Daniel Vetter)
    - Flip around the if ladders and make obj->funcs the first choice
    highlighting the fact that this the new default way of doing it
    (Daniel Vetter)

    Signed-off-by: Noralf Trønnes
    Acked-by: Daniel Vetter
    Acked-by: Christian König
    Link: https://patchwork.freedesktop.org/patch/msgid/20181110145647.17580-4-noralf@tronnes.org

    Noralf Trønnes
     

16 Feb, 2018

1 commit

  • i915 is the only driver using those fields in the drm_gem_object
    structure, so they only waste memory for all other drivers.

    Move the fields into drm_i915_gem_object instead and patch the i915 code
    with the following sed commands:

    sed -i "s/obj->base.read_domains/obj->read_domains/g" drivers/gpu/drm/i915/*.c drivers/gpu/drm/i915/*/*.c
    sed -i "s/obj->base.write_domain/obj->write_domain/g" drivers/gpu/drm/i915/*.c drivers/gpu/drm/i915/*/*.c

    Change is only compile tested.

    v2: move fields around as suggested by Chris.

    Signed-off-by: Christian König
    Reviewed-by: Chris Wilson
    Link: https://patchwork.freedesktop.org/patch/msgid/20180216124338.9087-1-christian.koenig@amd.com
    Signed-off-by: Chris Wilson

    Christian König
     

29 Jul, 2017

1 commit

  • Add a common drm_driver.dumb_map_offset function for GEM backed drivers.

    Signed-off-by: Noralf Trønnes
    Reviewed-by: Philipp Zabel
    Reviewed-by: Laurent Pinchart
    Reviewed-by: Sean Paul
    Link: https://patchwork.freedesktop.org/patch/msgid/1500837417-40580-2-git-send-email-noralf@tronnes.org

    Noralf Trønnes
     

06 Jul, 2017

1 commit


14 Mar, 2017

1 commit

  • Sadly there's only 1 driver which can use it, everyone else is special
    for some reason:

    - gma500 has a horrible runtime PM ioctl wrapper that probably doesn't
    really work but meh.
    - i915 needs special compat_ioctl handler because regrets.
    - arcgpu needs to fixup the pgprot because (no idea why it can't do
    that in the fault handler like everyone else).
    - tegra does even worse stuff with pgprot
    - udl does something with vm_flags too ...
    - cma helpers, etnaviv, mtk, msm, rockchip, omap all implement some
    variation on prefaulting.
    - exynos is exynos, I got lost in the midlayers.
    - vc4 has to reinvent half of cma helpers because those are too much
    midlayer, plus vm_flags dances.
    - vgem also seems unhappy with the default vm_flags.

    So pretty sad divergence and I'm sure we could do better, but not
    really an idea. Oh well, maybe this macro here helps to encourage more
    consistency at least going forward.

    Reviewed-by: Sean Paul
    Reviewed-by: Liviu Dudau
    Signed-off-by: Daniel Vetter
    Link: http://patchwork.freedesktop.org/patch/msgid/20170308141257.12119-25-daniel.vetter@ffwll.ch

    Daniel Vetter
     

09 Mar, 2017

1 commit

  • Plus a little bit more documentation.

    v2: Untangle the missing forward decls to make drm_prime|gem.h
    free-standing.

    Reviewed-by: Gustavo Padovan
    Signed-off-by: Daniel Vetter
    Link: http://patchwork.freedesktop.org/patch/msgid/20170308141257.12119-3-daniel.vetter@ffwll.ch

    Daniel Vetter
     

28 Feb, 2017

1 commit

  • For consistency with other reference counting APIs in the kernel, add
    drm_gem_object_get() and drm_gem_object_put(), as well as an unlocked
    variant of the latter, to reference count GEM buffer objects.

    Compatibility aliases are added to keep existing code working. To help
    speed up the transition, all the instances of the old functions in the
    DRM core are already replaced in this commit.

    The existing semantic patch for the DRM subsystem-wide conversion is
    extended to account for these new helpers.

    Reviewed-by: Sean Paul
    Acked-by: Christian König
    Signed-off-by: Thierry Reding
    Link: http://patchwork.freedesktop.org/patch/msgid/20170228144643.5668-6-thierry.reding@gmail.com

    Thierry Reding
     

25 Jan, 2017

1 commit

  • I just learned that &struct_name.member_name works and looks pretty
    even. It doesn't (yet) link to the member directly though, which would
    be really good for big structures or vfunc tables (where the
    per-member kerneldoc tends to be long).

    Also some minor drive-by polish where it makes sense, I read a lot
    of docs ...

    Cc: Jani Nikula
    Cc: Chris Wilson
    Reviewed-by: Gustavo Padovan
    Signed-off-by: Daniel Vetter
    Link: http://patchwork.freedesktop.org/patch/msgid/20170125062657.19270-5-daniel.vetter@ffwll.ch

    Daniel Vetter
     

16 Aug, 2016

1 commit

  • These are the leftovers I could only track down using keep_warnings =
    True. For some of them we might want to update our style guide on how
    to reference structures and constants, not sure ...

    Cc: Markus Heiser
    Cc: Jonathan Corbet
    Cc: linux-doc@vger.kernel.org
    Reviewed-by: Sean Paul
    Signed-off-by: Daniel Vetter
    Link: http://patchwork.freedesktop.org/patch/msgid/1471034937-651-1-git-send-email-daniel.vetter@ffwll.ch

    Daniel Vetter
     

17 May, 2016

1 commit

  • drm_gem_object_lookup() has never required the drm_device for its file
    local translation of the user handle to the GEM object. Let's remove the
    unused parameter and save some space.

    Signed-off-by: Chris Wilson
    Cc: dri-devel@lists.freedesktop.org
    Cc: Dave Airlie
    Cc: Daniel Vetter
    [danvet: Fixup kerneldoc too.]
    Signed-off-by: Daniel Vetter

    Chris Wilson
     

04 May, 2016

1 commit

  • Finally all the core gem and a lot of drivers are entirely free of
    dev->struct_mutex depencies, and we can start to have an entirely
    lockless unref path.

    To make sure that no one who touches the core code accidentally breaks
    existing drivers which still require dev->struct_mutex I've made the
    might_lock check unconditional.

    While at it de-inline the ref/unref functions, they've become a bit
    too big.

    v2: Make it not leak like a sieve.

    v3: Review from Lucas:
    - drop != NULL in pointer checks.
    - fixup copypasted kerneldoc to actually match the functions.

    v4:
    Add __drm_gem_object_unreference as a fastpath helper for drivers who
    abolished dev->struct_mutex, requested by Chris.

    v5: Fix silly mistake in drm_gem_object_unreference_unlocked caught by
    intel-gfx CI - I checked for gem_free_object instead of
    gem_free_object_unlocked ...

    Cc: Chris Wilson
    Cc: Alex Deucher
    Cc: Lucas Stach
    Reviewed-by: Lucas Stach (v3)
    Reviewed-by: Chris Wilson (v4)
    Reviewed-by: Alex Deucher
    Signed-off-by: Daniel Vetter
    Signed-off-by: Daniel Vetter
    Link: http://patchwork.freedesktop.org/patch/msgid/1462178451-1765-1-git-send-email-daniel.vetter@ffwll.ch

    Daniel Vetter
     

24 Nov, 2015

1 commit

  • I just realized that I've forgotten to update all the gem refcounting
    docs. For pennance also add pretty docs for the overall drm_gem_object
    structure, with a few links thrown in fore good.

    As usually we need to make sure the kerneldoc reference is at most a
    sect2 for otherwise it won't be listed.

    Signed-off-by: Daniel Vetter
    Link: http://patchwork.freedesktop.org/patch/msgid/1445533889-7661-1-git-send-email-daniel.vetter@ffwll.ch
    Reviewed-by: Alex Deucher
    Signed-off-by: Daniel Vetter

    Daniel Vetter
     

19 Oct, 2015

1 commit

  • Pretty soon only some drivers will need dev->struct_mutex in their
    gem_free_object callbacks. Hence it's really important to make sure
    everything still keeps getting this right.

    v2: Don't check for locking before we check for non-NULL obj. Spotted
    by Dan Carpenter.

    Link: http://mid.gmane.org/1444894601-5200-10-git-send-email-daniel.vetter@ffwll.ch
    Reviewed-by: David Herrmann
    Signed-off-by: Daniel Vetter

    Daniel Vetter
     

08 Apr, 2015

1 commit


24 Dec, 2014

1 commit


21 Nov, 2014

1 commit

  • It happens on occasion that developers of generic user-space applications
    abuse the dumb buffer API to get hold of drm buffers that they can both
    mmap() and use for GPU acceleration, using the assumptions that dumb buffers
    and buffers available for GPU are
    a) The same type and can be aribtrarily type-casted.
    b) fully coherent.

    This patch makes the most widely used drivers warn nicely when that happens,
    the next step will be to fail.

    v2: Move drmP.h changes to drm_gem.h. Fix Radeon dumb mmap breakage.

    Signed-off-by: Thomas Hellstrom
    Acked-by: Daniel Vetter
    Acked-by: Alex Deucher
    Signed-off-by: Dave Airlie

    Thomas Hellstrom
     

24 Sep, 2014

1 commit