1. 26 Mar, 2020 3 commits
    • Daniel Vetter's avatar
      drm: add managed resources tied to drm_device · c6603c74
      Daniel Vetter authored
      We have lots of these. And the cleanup code tends to be of dubious
      quality. The biggest wrong pattern is that developers use devm_, which
      ties the release action to the underlying struct device, whereas
      all the userspace visible stuff attached to a drm_device can long
      outlive that one (e.g. after a hotunplug while userspace has open
      files and mmap'ed buffers). Give people what they want, but with more
      correctness.
      
      Mostly copied from devres.c, with types adjusted to fit drm_device and
      a few simplifications - I didn't (yet) copy over everything. Since
      the types don't match code sharing looked like a hopeless endeavour.
      
      For now it's only super simplified, no groups, you can't remove
      actions (but kfree exists, we'll need that soon). Plus all specific to
      drm_device ofc, including the logging. Which I didn't bother to make
      compile-time optional, since none of the other drm logging is compile
      time optional either.
      
      One tricky bit here is the chicken&egg between allocating your
      drm_device structure and initiliazing it with drm_dev_init. For
      perfect onion unwinding we'd need to have the action to kfree the
      allocation registered before drm_dev_init registers any of its own
      release handlers. But drm_dev_init doesn't know where exactly the
      drm_device is emebedded into the overall structure, and by the time it
      returns it'll all be too late. And forcing drivers to be able clean up
      everything except the one kzalloc is silly.
      
      Work around this by having a very special final_kfree pointer. This
      also avoids troubles with the list head possibly disappearing from
      underneath us when we release all resources attached to the
      drm_device.
      
      v2: Do all the kerneldoc at the end, to avoid lots of fairly pointless
      shuffling while getting everything into shape.
      
      v3: Add static to add/del_dr (Neil)
      Move typo fix to the right patch (Neil)
      
      v4: Enforce contract for drmm_add_final_kfree:
      
      Use ksize() to check that the drm_device is indeed contained somewhere
      in the final kfree(). Because we need that or the entire managed
      release logic blows up in a pile of use-after-frees. Motivated by a
      discussion with Laurent.
      
      v5: Review from Laurent:
      - %zu instead of casting size_t
      - header guards
      - sorting of includes
      - guarding of data assignment if we didn't allocate it for a NULL
        pointer
      - delete spurious newline
      - cast void* data parameter correctly in ->release call, no idea how
        this even worked before
      
      v6: Review from Sam
      - Add the kerneldoc for the managed sub-struct back in, even if it
        doesn't show up in the generated html somehow.
      - Explain why __always_inline.
      - Fix bisectability around the final kfree() in drm_dev_relase(). This
        is just interim code which will disappear again.
      - Some whitespace polish.
      - Add debug output when drmm_add_action or drmm_kmalloc fail.
      
      v7: My bisectability fix wasn't up to par as noticed by smatch.
      
      v8: Remove unecessary {} around if else
      
      v9: Use kstrdup_const, which requires kfree_const and introducing a free_dr()
      helper (Thomas).
      
      v10: kfree_const goes boom on the plain "kmalloc" assignment, somehow
      we need to wrap that in kstrdup_const() too!! Also renumber revision
      log, I somehow reset it midway thruh.
      Reviewed-by: default avatarSam Ravnborg <sam@ravnborg.org>
      Cc: Thomas Zimmermann <tzimmermann@suse.de>
      Cc: Dan Carpenter <dan.carpenter@oracle.com>
      Cc: Sam Ravnborg <sam@ravnborg.org>
      Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
      Cc: Neil Armstrong <narmstrong@baylibre.com
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: "Rafael J. Wysocki" <rafael@kernel.org>
      Signed-off-by: default avatarDaniel Vetter <daniel.vetter@intel.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20200324124540.3227396-1-daniel.vetter@ffwll.ch
      c6603c74
    • Daniel Vetter's avatar
      drm/i915: Don't clear drvdata in ->release · 0ce542f7
      Daniel Vetter authored
      For two reasons:
      
      - The driver core clears this already for us after we're unloaded in
        __device_release_driver().
      
      - It's way too late, the drm_device ->release callback might massively
        outlive the underlying physical device, since a drm_device can be
        kept alive by open drm_file or well really anything else userspace
        is still hanging onto. So if we clear this ourselves, we should
        clear it in the pci ->remove callback, not in the drm_device
        ->release callback.
      
      Looking at git history this was fixed in the driver core with
      
      commit 0998d063
      Author: Hans de Goede <hdegoede@redhat.com>
      Date:   Wed May 23 00:09:34 2012 +0200
      
          device-core: Ensure drvdata = NULL when no driver is bound
      
      v2: Cite the core fix in the commit message (Chris).
      
      v3: Fix commit message and unused variable warning (Jani).
      
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Chris Wilson <chris@chris-wilson.co.uk>
      Reviewed-by: default avatarJani Nikula <jani.nikula@intel.com>
      Signed-off-by: default avatarDaniel Vetter <daniel.vetter@intel.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20200323144950.3018436-3-daniel.vetter@ffwll.ch
      0ce542f7
    • Daniel Vetter's avatar
      mm/sl[uo]b: export __kmalloc_track(_node)_caller · fd7cb575
      Daniel Vetter authored
      slab does this already, and I want to use this in a memory allocation
      tracker in drm for stuff that's tied to the lifetime of a drm_device,
      not the underlying struct device. Kinda like devres, but for drm.
      Acked-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarDaniel Vetter <daniel.vetter@intel.com>
      Cc: Christoph Lameter <cl@linux.com>
      Cc: Pekka Enberg <penberg@kernel.org>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: linux-mm@kvack.org
      Link: https://patchwork.freedesktop.org/patch/msgid/20200323144950.3018436-2-daniel.vetter@ffwll.ch
      fd7cb575
  2. 24 Mar, 2020 7 commits
  3. 23 Mar, 2020 2 commits
  4. 22 Mar, 2020 5 commits
  5. 21 Mar, 2020 2 commits
  6. 20 Mar, 2020 10 commits
  7. 19 Mar, 2020 1 commit
  8. 18 Mar, 2020 10 commits