1. 08 8月, 2014 1 次提交
    • D
      Revert "drm: drop redundant drm_file->is_master" · 7963e9db
      Dave Airlie 提交于
      This reverts commit 48ba8137.
      
      Thanks to Chris:
      "drm_file->is_master is not synomous with having drm_file->master ==
      drm_file->minor->master. This is because drm_file->master is the same
      for all drm_files of the same generation and so when there is a master,
      every drm_file believes itself to be the master. Confusion ensues and
      things go pear shaped when one file is closed and there is no master
      anymore."
      
      Conflicts:
      	drivers/gpu/drm/drm_drv.c
      	drivers/gpu/drm/drm_stub.c
      7963e9db
  2. 06 8月, 2014 1 次提交
  3. 05 8月, 2014 5 次提交
    • D
      drm: move module initialization to drm_stub.c · 1b7199fe
      David Herrmann 提交于
      Most of the new DRM management functions are nowadays in drm_stub.c. By
      moving the core module initialization to drm_stub.c we can make several
      global variables static and keep the stub-open helper local.
      
      The core files now look like this:
        drm_stub.c: Core management
         drm_drv.c: Ioctl dispatcher
       drm_ioctl.c: Actual ioctl backends
        drm_fops.c: Char-dev file-operations
      
      A follow-up patch will move what is left from drm_drv.c into drm_ioctl.c.
      Acked-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      Reviewed-by: NAlex Deucher <alexander.deucher@amd.com>
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      1b7199fe
    • D
      drm: don't de-authenticate clients on master-close · 3cb01a98
      David Herrmann 提交于
      If an active DRM-Master closes its device, we deauthenticate all clients
      on that master. However, if an inactive DRM-Master closes its device, we
      do nothing. This is quite inconsistent and breaks several scenarios:
      
       1) If this was used as security mechanism, it fails horribly if a master
          closes a device while VT switched away. Furthermore, none of the few
          drivers using ->master_*() callbacks seems to require it, anyway.
      
       2) If you spawn weston (or any other non-UMS compositor) in background
          while another compositor is active, both will get assigned to the
          same "drm_master" object. If the foreground compositor now exits, all
          clients of both the foreground AND background compositor will be
          de-authenticated leading to unexpected behavior.
      
      Stop this non-sense and keep clients authenticated. We don't do this when
      dropping DRM-Master (i.e., switching VTs) so don't do it on active-close
      either!
      Reviewed-by: NAlex Deucher <alexander.deucher@amd.com>
      Reviewed-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      3cb01a98
    • D
      drm: drop redundant drm_file->is_master · 48ba8137
      David Herrmann 提交于
      The drm_file->is_master field is redundant as it's equivalent to:
          drm_file->master && drm_file->master == drm_file->minor->master
      
      1) "=>"
        Whenever we set drm_file->is_master, we also set:
            drm_file->minor->master = drm_file->master;
      
        Whenever we clear drm_file->is_master, we also call:
            drm_master_put(&drm_file->minor->master);
        which implicitly clears it to NULL.
      
      2) "<="
        minor->master cannot be set if it is non-NULL. Therefore, it stays as
        is unless a file drops it.
      
        If minor->master is NULL, it is only set by places that also adjust
        drm_file->is_master.
      
      Therefore, we can safely drop is_master and replace it by an inline helper
      that matches:
          drm_file->master && drm_file->master == drm_file->minor->master
      Reviewed-by: NAlex Deucher <alexander.deucher@amd.com>
      Reviewed-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      48ba8137
    • D
      drm: extract legacy ctxbitmap flushing · 9f8d21ea
      David Herrmann 提交于
      The ctxbitmap code is only used by legacy drivers so lets try to keep it
      as separated as possible. Furthermore, the locking is non-obvious and
      kinda weird with ctxlist_mutex *and* struct_mutex. Keeping all ctxbitmap
      access in one file is much easier to review and makes drm_release() more
      readable.
      Reviewed-by: NAlex Deucher <alexander.deucher@amd.com>
      Reviewed-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      9f8d21ea
    • C
      drm: Unlink dead file_priv from list of active files first · dff01de1
      Chris Wilson 提交于
      In order to prevent external observers walking the list of open DRM
      files from seeing an invalid drm_file_private in the process of being
      torndown, the first operation we need to take is to unlink the
      drm_file_private from that list.
      
      	general protection fault: 0000 [#1] PREEMPT SMP
      	Modules linked in: i915 i2c_algo_bit drm_kms_helper drm lpc_ich mfd_core nls_iso8859_1 i2c_hid video hid_generic usbhid hid e1000e ahci ptp libahci pps_core
      	CPU: 3 PID: 8220 Comm: cat Not tainted 3.16.0-rc6+ #4
      	Hardware name: Intel Corporation Shark Bay Client platform/WhiteTip Mountain 1, BIOS HSWLPTU1.86C.0119.R00.1303230105 03/23/2013
      	task: ffff8800219642c0 ti: ffff880047024000 task.ti: ffff880047024000
      	RIP: 0010:[<ffffffffa0137c70>]  [<ffffffffa0137c70>] per_file_stats+0x110/0x160 [i915]
      	RSP: 0018:ffff880047027d48  EFLAGS: 00010246
      	RAX: 6b6b6b6b6b6b6b6b RBX: ffff880047027e30 RCX: 0000000000000000
      	RDX: 0000000000000001 RSI: 0000000000000000 RDI: ffff88003a05cd00
      	RBP: ffff880047027d58 R08: 0000000000000001 R09: 0000000000000000
      	R10: ffff8800219642c0 R11: 0000000000000000 R12: ffff88003a05cd00
      	R13: 0000000000000000 R14: ffff88003a05cd00 R15: ffff880047027d88
      	FS:  00007f5f73a13740(0000) GS:ffff88014e380000(0000) knlGS:0000000000000000
      	CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      	CR2: 00000000023ff038 CR3: 0000000021a4b000 CR4: 00000000001407e0
      	Stack:
      	 0000000000000001 000000000000ffff ffff880047027dc8 ffffffff813438e4
      	 ffff880047027e30 ffffffffa0137b60 ffff880021a8af58 ffff880021a8f1a0
      	 ffff8800a2061fb0 ffff8800a2062048 ffff8800a2061fb0 ffff8800a1e23478
      	Call Trace:
      	 [<ffffffff813438e4>] idr_for_each+0xf4/0x180
      	 [<ffffffffa0137b60>] ? i915_gem_stolen_list_info+0x1f0/0x1f0 [i915]
      	 [<ffffffffa013a17a>] i915_gem_object_info+0x5ca/0x6a0 [i915]
      	 [<ffffffff81193ec5>] seq_read+0xf5/0x3a0
      	 [<ffffffff8116d950>] vfs_read+0x90/0x150
      	 [<ffffffff8116e509>] SyS_read+0x49/0xb0
      	 [<ffffffff815d8622>] tracesys+0xd0/0xd5
      	Code: 01 00 00 49 39 84 24 08 01 00 00 74 55 49 8b 84 24 b8 00 00 00 48 01 43 18 31 c0 5b 41 5c 5d c3 0f 1f 00 49 8b 44 24 08 4c 89 e7 <48> 8b 70 28 48 81 c6 48 80 00 00 e8 80 14 01 00 84 c0 74 bc 49
      	RIP  [<ffffffffa0137c70>] per_file_stats+0x110/0x160 [i915]
      	RSP <ffff880047027d48>
      Reported-by: N"Ursulin, Tvrtko" <tvrtko.ursulin@intel.com>
      Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=81712Signed-off-by: NChris Wilson <chris@chris-wilson.co.uk>
      Cc: "Ursulin, Tvrtko" <tvrtko.ursulin@intel.com>
      Reviewed-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NDave Airlie <airlied@redhat.com>
      dff01de1
  4. 02 8月, 2014 1 次提交
    • D
      drm: drop i386 verification · 1eac8877
      David Herrmann 提交于
      Linux doesn't run on i386, anymore. See:
      
          commit d55c5a93
          Author: H. Peter Anvin <hpa@linux.intel.com>
          Date:   Wed Nov 28 11:50:24 2012 -0800
      
              x86, 386 removal: Remove CONFIG_CMPXCHG
      
              All 486+ CPUs support CMPXCHG, so remove the fallback 386 support
              code.
      
      Furthermore, as the commit-message states, all 486+ CPUs support the
      CMPXCHG instruction and thus even legacy DRM can run fine.
      
      Drop the now superfluous "x86 == 3" check.
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NDave Airlie <airlied@redhat.com>
      1eac8877
  5. 29 4月, 2014 1 次提交
  6. 28 3月, 2014 3 次提交
  7. 16 3月, 2014 5 次提交
    • D
      drm: make minors independent of global lock · 0d639883
      David Herrmann 提交于
      We used to protect minor-lookup and setup by the global drm lock. To
      continue our attempts of dropping drm_global_mutex, this patch makes the
      minor management independent of it. Furthermore, we make it all atomic and
      switch to spin-locks instead of a mutex.
      
      Now that minor-lookup is independent, we also move the
      "drm_is_unplugged()" test into the minor-lookup path. There is no reason
      to ever return a minor for unplugged objects, so keep that logic internal.
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      0d639883
    • D
      drm: remove redundant minor->device field · 5817878c
      David Herrmann 提交于
      Whenever we access minor->device, we are in a minor->kdev->...->fops
      callback so the minor->kdev pointer *must* be valid. Thus, simply use
      minor->kdev->devt instead of minor->device and remove the redundant field.
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Reviewed-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      5817878c
    • D
      drm: add minor-lookup/release helpers · 1616c525
      David Herrmann 提交于
      Instead of accessing drm_minors_idr directly, this adds a small helper to
      hide the internals. This will help us later to remove the drm_global_mutex
      requirement for minor-lookup.
      
      Furthermore, this also makes sure that minor->dev is always valid and
      takes a reference-count to the device as long as the minor is used in an
      open-file. This way, "struct file*"->private_data->dev is guaranteed to be
      valid (which it has to, as we cannot reset it).
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Reviewed-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      1616c525
    • D
      drm: skip redundant minor-lookup in open path · f4aede2e
      David Herrmann 提交于
      The drm_open_helper() function is only used internally for drm_open() so
      we can safely pass in the minor-object directly instead of the minor-id.
      This way, we avoid the additional minor IDR lookup, which we already do
      twice in drm_stub_open() and drm_open().
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Reviewed-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      f4aede2e
    • D
      drm: use anon-inode instead of relying on cdevs · 6796cb16
      David Herrmann 提交于
      DRM drivers share a common address_space across all character-devices of a
      single DRM device. This allows simple buffer eviction and mapping-control.
      However, DRM core currently waits for the first ->open() on any char-dev
      to mark the underlying inode as backing inode of the device. This delayed
      initialization causes ugly conditions all over the place:
        if (dev->dev_mapping)
          do_sth();
      
      To avoid delayed initialization and to stop reusing the inode of the
      char-dev, we allocate an anonymous inode for each DRM device and reset
      filp->f_mapping to it on ->open().
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      6796cb16
  8. 15 2月, 2014 1 次提交
  9. 18 12月, 2013 3 次提交
  10. 06 11月, 2013 2 次提交
  11. 25 10月, 2013 1 次提交
  12. 09 10月, 2013 3 次提交
  13. 20 9月, 2013 1 次提交
  14. 30 8月, 2013 1 次提交
    • D
      drm: implement experimental render nodes · 1793126f
      David Herrmann 提交于
      Render nodes provide an API for userspace to use non-privileged GPU
      commands without any running DRM-Master. It is useful for offscreen
      rendering, GPGPU clients, and normal render clients which do not perform
      modesetting.
      
      Compared to legacy clients, render clients no longer need any
      authentication to perform client ioctls. Instead, user-space controls
      render/client access to GPUs via filesystem access-modes on the
      render-node. Once a render-node was opened, a client has full access to
      the client/render operations on the GPU. However, no modesetting or ioctls
      that affect global state are allowed on render nodes.
      
      To prevent privilege-escalation, drivers must explicitly state that they
      support render nodes. They must mark their render-only ioctls as
      DRM_RENDER_ALLOW so render clients can use them. Furthermore, they must
      support clients without any attached master.
      
      If filesystem access-modes are not enough for fine-grained access control
      to render nodes (very unlikely, considering the versaitlity of FS-ACLs),
      you may still fall-back to fd-passing from server to client (which allows
      arbitrary access-control). However, note that revoking access is
      currently impossible and unlikely to get implemented.
      
      Note: Render clients no longer have any associated DRM-Master as they are
      supposed to be independent of any server state. DRM core highly depends on
      file_priv->master to be non-NULL for modesetting/ctx/etc. commands.
      Therefore, drivers must be very careful to not require DRM-Master if they
      support DRIVER_RENDER.
      
      So far render-nodes are protected by "drm_rnodes". As long as this
      module-parameter is not set to 1, a driver will not create render nodes.
      This allows us to experiment with the API a bit before we stabilize it.
      
      v2: drop insecure GEM_FLINK to force use of dmabuf
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NDave Airlie <airlied@redhat.com>
      1793126f
  15. 29 8月, 2013 1 次提交
  16. 21 8月, 2013 1 次提交
    • D
      drm/prime: proper locking+refcounting for obj->dma_buf link · 319c933c
      Daniel Vetter 提交于
      The export dma-buf cache is semantically similar to an flink name. So
      semantically it makes sense to treat it the same and remove the name
      (i.e. the dma_buf pointer) and its references when the last gem handle
      disappears.
      
      Again we need to be careful, but double so: Not just could someone
      race and export with a gem close ioctl (so we need to recheck
      obj->handle_count again when assigning the new name), but multiple
      exports can also race against each another. This is prevented by
      holding the dev->object_name_lock across the entire section which
      touches obj->dma_buf.
      
      With the new scheme we also need to reinstate the obj->dma_buf link at
      import time (in case the only reference userspace has held in-between
      was through the dma-buf fd and not through any native gem handle). For
      simplicity we don't check whether it's a native object but
      unconditionally set up that link - with the new scheme of removing the
      obj->dma_buf reference when the last handle disappears we can do that.
      
      To make it clear that this is not just for exported buffers anymore
      als rename it from export_dma_buf to dma_buf.
      
      To make sure that now one can race a fd_to_handle or handle_to_fd with
      gem_close we use the same tricks as in flink of extending the
      dev->object_name_locking critical section. With this change we finally
      have a guaranteed 1:1 relationship (at least for native objects)
      between gem objects and dma-bufs, even accounting for races (which can
      happen since the dma-buf itself holds a reference while in-flight).
      
      This prevent igt/prime_self_import/export-vs-gem_close-race from
      Oopsing the kernel. There is still a leak though since the per-file
      priv dma-buf/handle cache handling is racy. That will be fixed in a
      later patch.
      
      v2: Remove the bogus dma_buf_put from the export_and_register_object
      failure path if we've raced with the handle count dropping to 0.
      Signed-off-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: NDave Airlie <airlied@redhat.com>
      319c933c
  17. 19 8月, 2013 5 次提交
    • D
      drm: move dev data clearing from drm_setup to lastclose · f336ab76
      Daniel Vetter 提交于
      We kzalloc this structure, and for real kms devices we should never
      loose track of things really.
      
      But ums/legacy drivers rely on the drm core to clean up a bit of cruft
      between lastclose and firstopen (i.e. when X is being restarted), so
      keep this around. But give it a clear drm_legacy_ prefix and
      conditionalize the code on !DRIVER_MODESET.
      
      Cc: David Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      Reviewed-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NDave Airlie <airlied@redhat.com>
      f336ab76
    • D
      drm: don't call ->firstopen for KMS drivers · 7d14bb6b
      Daniel Vetter 提交于
      It has way too much potential for driver writers to do stupid things
      like delayed hw setup because the load sequence is somehow racy (e.g.
      the imx driver in staging). So don't call it for modesetting drivers,
      which reduces the complexity of the drm core -> driver interface a
      notch.
      
      v2: Don't forget to update DocBook.
      
      v3: Go with Laurent's slightly more elaborate proposal for the DocBook
      update. Add a few words on top of his diff to elaborate a bit on what
      KMS drivers should and shouldn't do in lastclose. There was already a
      paragraph present talking about restoring properties, I've simply
      extended that one.
      
      Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
      Acked-by: NLaurent Pinchart <laurent.pinchart@ideasonboard.com>
      Signed-off-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: NDave Airlie <airlied@redhat.com>
      7d14bb6b
    • D
      drm: remove FASYNC support · b0e898ac
      Daniel Vetter 提交于
      So I've stumbled over drm_fasync and wondered what it does. Digging
      that up is quite a story.
      
      First I've had to read up on what this does and ended up being rather
      bewildered why peopled loved signals so much back in the days that
      they've created SIGIO just for that ...
      
      Then I wondered how this ever works, and what that strange "No-op."
      comment right above it should mean. After all calling the core fasync
      helper is pretty obviously not a noop. After reading through the
      kernels FASYNC implementation I've noticed that signals are only sent
      out to the processes attached with FASYNC by calling kill_fasync.
      
      No merged drm driver has ever done that.
      
      After more digging I've found out that the only driver that ever used
      this is the so called GAMMA driver. I've frankly never heard of such a
      gpu brand ever before. Now FASYNC seems to not have been the only bad
      thing with that driver, since Dave Airlie removed it from the drm
      driver with prejudice:
      
      commit 1430163b4bbf7b00367ea1066c1c5fe85dbeefed
      Author: Dave Airlie <airlied@linux.ie>
      Date:   Sun Aug 29 12:04:35 2004 +0000
      
          Drop GAMMA DRM from a great height ...
      
      Long story short, the drm fasync support seems to be doing absolutely
      nothing. And the only user of it was never merged into the upstream
      kernel. And we don't need any fops->fasync callback since the fcntl
      implementation in the kernel already implements the noop case
      correctly.
      
      So stop this particular cargo-cult and rip it all out.
      
      v2: Kill drm_fasync assignments in rcar (newly added) and imx drivers
      (somehow I've missed that one in staging). Also drop the reference in
      the drm DocBook. ARM compile-fail reported by Rob Clark.
      
      v3: Move the removal of dev->buf_asnyc assignment in drm_setup to this
      patch here.
      
      v4: Actually git add ... tsk.
      
      Cc: Dave Airlie <airlied@linux.ie>
      Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
      Cc: Rob Clark <robdclark@gmail.com>
      Acked-by: NLaurent Pinchart <laurent.pinchart@ideasonboard.com>
      Signed-off-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      Reviewed-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NDave Airlie <airlied@redhat.com>
      b0e898ac
    • D
      drm: mark context support as a legacy subsystem · 7c510133
      Daniel Vetter 提交于
      So after a lot of digging around in git histories it looks like this
      has only ever be used by dri1 render clients. Hence we can fully
      disable the entire thing for modesetting drivers and so greatly reduce
      the attack surface for potential exploits (or at least tools like
      trinity ...).
      
      Also add the drm_legacy prefix for functions which are called from
      common code. To further reduce the impact on common code also extract
      all the ctx release handling into a function (instead of only
      releasing individual handles) and make ctxbitmap_cleanup return void -
      it can never fail.
      Reviewed-by: NEric Anholt <eric@anholt.net>
      Signed-off-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: NDave Airlie <airlied@redhat.com>
      7c510133
    • D
      drm: mark dma setup/teardown as legacy systems · e2e99a82
      Daniel Vetter 提交于
      And hide the checks a bit better. This was already disallowed for
      modesetting drivers, so no functinal change here.
      Reviewed-by: NEric Anholt <eric@anholt.net>
      Signed-off-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: NDave Airlie <airlied@redhat.com>
      e2e99a82
  18. 23 7月, 2013 4 次提交