1. 01 6月, 2016 1 次提交
    • R
      HID: uhid: fix timeout when probe races with IO · 67f8ecc5
      Roderick Colenbrander 提交于
      Many devices use userspace bluetooth stacks like BlueZ or Bluedroid in combination
      with uhid. If any of these stacks is used with a HID device for which the driver
      performs a HID request as part .probe (or technically another HID operation),
      this results in a deadlock situation. The deadlock results in a 5 second timeout
      for I/O operations in HID drivers, so isn't fatal, but none of the I/O operations
      have a chance of succeeding.
      
      The root cause for the problem is that uhid only allows for one request to be
      processed at a time per uhid instance and locks out other operations. This means
      that if a user space is creating a new HID device through 'UHID_CREATE', which
      ultimately triggers '.probe' through the HID layer. Then any HID request e.g. a
      read for calibration data would trigger a HID operation on uhid again, but it
      won't go out to userspace, because it is still stuck in UHID_CREATE.
      In addition bluetooth stacks are typically single threaded, so they wouldn't be
      able to handle any requests while waiting on uhid.
      
      Lucikly the UHID spec is somewhat flexible and allows for fixing the issue,
      without breaking user space. The idea which the patch implements as discussed
      with David Herrmann is to decouple adding of a hid device (which triggers .probe)
      from UHID_CREATE. The work will kick off roughly once UHID_CREATE completed (or
      else will wait a tiny bit of time in .probe for a lock). A HID driver has to call
      HID to call 'hid_hw_start()' as part of .probe once it is ready for I/O, which
      triggers UHID_START to user space. Any HID operations should function now within
      .probe and won't deadlock because userspace is stuck on UHID_CREATE.
      
      We verified this patch on Bluedroid with Android 6.0 and on desktop Linux with
      BlueZ stacks. Prior to the patch they had the deadlock issue.
      
      [jkosina@suse.cz: reword subject]
      Signed-off-by: NRoderick Colenbrander <roderick.colenbrander@sony.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      67f8ecc5
  2. 23 3月, 2016 1 次提交
  3. 02 10月, 2014 1 次提交
  4. 25 8月, 2014 10 次提交
    • D
      HID: uhid: report to user-space whether reports are numbered · c2b2f16c
      David Herrmann 提交于
      This makes UHID_START include a "dev_flags" field that describes details
      of the hid-device in the kernel. The first flags we introduce describe
      whether a given report-type uses numbered reports. This is useful for
      transport layers that force report-numbers and therefore might have to
      prefix kernel-provided HID-messages with the report-number.
      
      Currently, only HoG needs this and the spec only talks about "global
      report numbers". That is, it's a global boolean not a per-type boolean.
      However, given the quirks we already have in kernel-space, a per-type
      value seems much more appropriate.
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      c2b2f16c
    • D
      HID: uhid: implement SET_REPORT · 11c22155
      David Herrmann 提交于
      We so far lacked support for hid_hw_raw_request(..., HID_REQ_SET_REPORT);
      Add support for it and simply forward the request to user-space. Note that
      SET_REPORT is synchronous, just like GET_REPORT, even though it does not
      provide any data back besides an error code.
      
      If a transport layer does SET_REPORT asynchronously, they can just ACK it
      immediately by writing an uhid_set_report_reply to uhid.
      
      This patch re-uses the synchronous uhid-report infrastructure to query
      user-space. Note that this means you cannot run SET_REPORT and GET_REPORT
      in parallel. However, that has always been a restriction of HID and due to
      its blocking nature, this is just fine. Maybe some future transport layer
      supports parallel requests (very unlikely), however, until then lets not
      over-complicate things and avoid request-lookup-tables.
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      11c22155
    • D
      HID: uhid: rename uhid_raw_request to uhid_hid_raw_request · 7c4003bc
      David Herrmann 提交于
      We use strict prefixed in uhid.c:
        uhid_char_*: implement char-dev callbacks
        uhid_dev_*: implement uhid device management and runtime
        uhid_hid_*: implement hid-dev callbacks
      
      uhid_raw_request is an hid callback, so rename it to uhid_hid_raw_request.
      
      While at it, move it closer to it's extracted helpers and keep the same
      order as in "struct hid_driver".
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      7c4003bc
    • D
      HID: uhid: add ABI compatible UHID_GET_REPORT replacing UHID_FEATURE · fa71f32b
      David Herrmann 提交于
      The old hdev->hid_get_raw_report() was broken by design. It was never
      clear what kind of HW request it should trigger. Benjamin fixed that with
      the core HID cleanup, though we never really adjusted uhid.
      
      Unfortunately, our old UHID_FEATURE command was modelled around the broken
      hid_get_raw_report(). We converted it silently to the new GET_REPORT and
      nothing broke. Make this explicit by renaming UHID_FEATURE to
      UHID_GET_REPORT and UHID_FEATURE_ANSWER to UHID_GET_REPORT_REPLY.
      
      Note that this is 100% ABI compatible to UHID_FEATURE. This is just a
      rename. But we have to keep the old definitions around to not break API.
      
      >From now on, UHID_GET_REPORT must trigger a GET_REPORT request on the
      user-space hardware layer. All the ambiguity due to the weird "feature"
      name should be gone now.
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      fa71f32b
    • D
      HID: uhid: invert report_done and make non-atomic · 5942b849
      David Herrmann 提交于
      All accesses to @report_done are protected by qlock (or report-contexts).
      No need to use an atomic.
      
      While at it, invert the logic and call it "report_running". This is
      similar to the uhid->running field and easier to read.
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      5942b849
    • D
      HID: uhid: turn report_id into u32 · 8cad5b01
      David Herrmann 提交于
      All accesses to @report_id are protected by @qlock. No need to use an
      atomic.
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      8cad5b01
    • D
      HID: uhid: avoid magic-numbers when setting strings · 25be7fe2
      David Herrmann 提交于
      Avoid hard-coding the target buffer sizes and use sizeof() instead. This
      also makes us future-proof to buffer-extensions later on.
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      25be7fe2
    • D
      HID: uhid: avoid dangling pointers in uhid context · 41c4a464
      David Herrmann 提交于
      Avoid keeping uhid->rd_data and uhid->rd_size set in case
      uhid_dev_create2() fails. This is non-critical as we never flip
      uhid->running and thus never enter uhid_dev_destroy(). However, it's much
      nicer for debugging if pointers are only set if they point to valid data.
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      41c4a464
    • D
      HID: uhid: forward create_req to create2_req · 56c47754
      David Herrmann 提交于
      Instead of hard-coding the uhid_dev_create() function twice, copy any
      create_req into a create2_req structure and forward it.
      
      We allocate uhid_create_req on the stack here, but that should be fine.
      Unlike uhid_create2_req it is fairly small (<1KB) and it's only used
      temporarily to swap entries. uhid_dev_create2() doesn't access it.
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      56c47754
    • D
      HID: uhid: simplify report-cb shutdown · 0e0d7520
      David Herrmann 提交于
      The report-query is blocking, so when user-space destroys a device we have
      to wake up any blocking kernel context that is currently in the report-cb.
      We used some broken correlation between @report_done and @running so far.
      Replace it by a much more obvious use.
      
      We now wake up the report-cb if either @report_done or @running is set.
      wake_up() and wait_event() serve as implicit barriers (as they always do)
      so no need to use smp_rmb/wmb directly.
      
      Note that @report_done is never reset by anyone but the report-cb, thus
      it cannot flip twice while we wait for it. And whenever we set @running,
      we afterwards synchronously remove the HID device. Therefore, we wait for
      all report-cbs to finish before we return. This way, @running can never
      flip to true while we wait for it.
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      0e0d7520
  5. 27 5月, 2014 1 次提交
  6. 02 4月, 2014 1 次提交
    • P
      HID: uhid: Add UHID_CREATE2 + UHID_INPUT2 · 4522643a
      Petri Gynther 提交于
      UHID_CREATE2:
      HID report descriptor data (rd_data) is an array in struct uhid_create2_req,
      instead of a pointer. Enables use from languages that don't support pointers,
      e.g. Python.
      
      UHID_INPUT2:
      Data array is the last field of struct uhid_input2_req. Enables userspace to
      write only the required bytes to kernel (ev.type + ev.u.input2.size + the part
      of the data array that matters), instead of the entire struct uhid_input2_req.
      
      Note:
      UHID_CREATE2 increases the total size of struct uhid_event slightly, thus
      increasing the size of messages that are queued for userspace. However, this
      won't affect the userspace processing of these events.
      
      [Jiri Kosina <jkosina@suse.cz>: adjust to hid_get_raw_report() and
      				hid_output_raw_report() API changes]
      Signed-off-by: NPetri Gynther <pgynther@google.com>
      Reviewed-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      4522643a
  7. 14 3月, 2014 1 次提交
  8. 17 2月, 2014 5 次提交
  9. 29 1月, 2014 1 次提交
  10. 27 11月, 2013 1 次提交
  11. 26 9月, 2013 1 次提交
    • D
      HID: uhid: allocate static minor · 19872d20
      David Herrmann 提交于
      udev has this nice feature of creating "dead" /dev/<node> device-nodes if
      it finds a devnode:<node> modalias. Once the node is accessed, the kernel
      automatically loads the module that provides the node. However, this
      requires udev to know the major:minor code to use for the node. This
      feature was introduced by:
      
        commit 578454ff
        Author: Kay Sievers <kay.sievers@vrfy.org>
        Date:   Thu May 20 18:07:20 2010 +0200
      
            driver core: add devname module aliases to allow module on-demand auto-loading
      
      However, uhid uses dynamic minor numbers so this doesn't actually work. We
      need to load uhid to know which minor it's going to use.
      
      Hence, allocate a static minor (just like uinput does) and we're good
      to go.
      Reported-by: NTom Gundersen <teg@jklm.no>
      Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      19872d20
  12. 02 9月, 2013 1 次提交
  13. 31 7月, 2013 1 次提交
  14. 18 2月, 2013 1 次提交
  15. 20 7月, 2012 1 次提交
  16. 18 6月, 2012 12 次提交