1. 08 7月, 2010 1 次提交
  2. 21 6月, 2010 6 次提交
    • S
      firewire: cdev: fix ABI for FCP and address range mapping, add fw_cdev_event_request2 · e205597d
      Stefan Richter 提交于
      The problem:
      
      A target-like userspace driver, e.g. AV/C target or SBP-2/3 target,
      needs to be able to act as responder and requester.  In the latter role,
      it needs to send requests to nods from which it received requests.  This
      is currently impossible because fw_cdev_event_request lacks information
      about sender node ID.
      Reported-by: NJay Fenlason <fenlason@redhat.com>
      
      Libffado + libraw1394 + firewire-core is currently unable to drive two
      or more audio devices on the same bus.
      Reported-by: NArnold Krille <arnold@arnoldarts.de>
      
      This is because libffado requires destination node ID of FCP requests
      and sender node ID of FCP responses to match.  It even prohibits
      libffado from working with a bus on which libraw1394 opens a /dev/fw* as
      default ioctl device that does not correspond with the audio device.
      This is because libraw1394 does not receive the sender node ID from the
      kernel.
      
      Moreover, fw_cdev_event_request makes it impossible to tell unicast and
      broadcast write requests apart.
      
      The fix:
      
      Add a replacement of struct fw_cdev_event_request request, boringly
      called struct fw_cdev_event_request2.  The new event will be sent to a
      userspace client instead of the old one if the client claims
      compatibility with <linux/firewire-cdev.h> ABI version 4 or later.
      
      libraw1394 needs to be extended to make use of the new event, in order
      to properly support libffado and other FCP or address range mapping
      users who require correct sender node IDs.
      
      Further notes:
      
      While we are at it, change back the range of possible values of
      fw_cdev_event_request.tcode to 0x0...0xb like in ABI version <= 3.
      The preceding change "firewire: expose extended tcode of incoming lock
      requests to (userspace) drivers" expanded it to 0x0...0x17 which could
      catch sloppily coded clients by surprise.  The extended range of codes
      is only used in the new fw_cdev_event_request2.tcode.
      
      Jay and I also suggested an alternative approach to fix the ABI for
      incoming requests:  Add an FW_CDEV_IOC_GET_REQUEST_INFO ioctl which can
      be called after reception of an fw_cdev_event_request, before issuing of
      the closing FW_CDEV_IOC_SEND_RESPONSE ioctl.  The new ioctl would reveal
      the vital information about a request that fw_cdev_event_request lacks.
      Jay showed an implementation of this approach.
      
      The former event approach adds 27 LOC of rather trivial code to
      core-cdev.c, the ioctl approach 34 LOC, some of which is nontrivial.
      The ioctl approach would certainly also add more LOC to userspace
      programs which require the expanded information on inbound requests.
      This approach is probably only on the lighter-weight side in case of
      clients that want to be compatible with kernels that lack the new
      capability, like libraw1394.  However, the code to be added to such
      libraw1394-like clients in case of the event approach is a straight-
      forward additional switch () case in its event handler.
      Signed-off-by: NStefan Richter <stefanr@s5r6.in-berlin.de>
      e205597d
    • S
      firewire: cdev: freeze FW_CDEV_VERSION due to libraw1394 bug · 604f4516
      Stefan Richter 提交于
      libraw1394 v2.0.0...v2.0.5 takes FW_CDEV_VERSION from an externally
      installed header file and uses it to declare its own implementation
      level in FW_CDEV_IOC_GET_INFO.  This is wrong; it should set the real
      version for which it was actually written.
      
      If we add features to the kernel ABI that require the kernel to check
      a client's implementation level, we can not trust the client version if
      it was set from FW_CDEV_VERSION.
      
      Hence freeze FW_CDEV_VERSION at the current value (no damage has been
      done yet), clearly document FW_CDEV_VERSION as a dummy version and what
      clients are expected to do with fw_cdev_get_info.version, and use a new
      defined constant (which is not placed into the exported header file) as
      kernel implementation level.
      
      Note, in order to check in client program source code which features are
      present in an externally installed linux/firewire-cdev.h, use
      preprocessor directives like
        #ifdef FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE
      or
        #ifdef FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED
      instead of a check of FW_CDEV_VERSION.
      Signed-off-by: NStefan Richter <stefanr@s5r6.in-berlin.de>
      604f4516
    • S
      firewire: cdev: count references of cards during inbound transactions · 0244f573
      Stefan Richter 提交于
      If a request comes in to an address range managed by a userspace driver
      i.e. <linux/firewire-cdev.h> client, the card instance of request and
      response may differ from the card instance of the client device.
      Therefore we need to take a reference of the card until the response was
      sent.
      
      I thought about putting the reference counting into core-transaction.c,
      but the various high-level drivers besides cdev clients (firewire-net,
      firewire-sbp2, firedtv) use the card pointer in their fw_address_handler
      address_callback method only to look up devices of which they already
      hold the necessary references.  So this seems to be a specific
      firewire-cdev issue which is better addressed locally.
      
      We do not need the reference
        - in case of FCP_REQUEST or FCP_RESPONSE requests because then the
          firewire-core will send the split transaction response for us
          already in the context of the request handler,
        - if it is the same card as the client device's because we hold a
          card reference indirectly via teh client->device reference.
      To keep things simple, we take the reference nevertheless.
      
      Jay Fenlason wrote:
      > there's no way for the core to tell cdev "this card is gone,
      > kill any inbound transactions on it", while cdev holds the transaction
      > open until userspace issues a SEND_RESPONSE ioctl, which may be a very,
      > very long time.  But when it does, it calls fw_send_response(), which
      > will dereference the card...
      >
      > So how unhappy are we about userspace potentially holding a fw_card
      > open forever?
      
      While termination of inbound transcations at card removal could be
      implemented, it is IMO not worth the effort.  Currently, the effect of
      holding a reference of a card that has been removed is to block the
      process that called the pci_remove of the card.  This is
        - either a user process ran by root.  Root can find and kill processes
          that have /dev/fw* open, if desired.
        - a kernel thread (which one?) in case of hot removal of a PCCard or
          ExpressCard.
      The latter case could be a problem indeed.  firewire-core's card
      shutdown and card release should probably be improved not to block in
      shutdown, just to defer freeing of memory until release.
      
      This is not a new problem though; the same already always happens with
      the client->device->card without the need of inbound transactions or
      other special conditions involved, other than the client not closing the
      file.
      Signed-off-by: NStefan Richter <stefanr@s5r6.in-berlin.de>
      0244f573
    • J
      firewire: cdev: fix responses to nodes at different card · 08bd34c9
      Jay Fenlason 提交于
      My box has two firewire cards in it: card0 and card1.
      My application opens /dev/fw0 (card 0) and allocates an address space.
      The core makes the address space available on both cards.
      Along comes the remote device, which sends a READ_QUADLET_REQUEST to
      card1.  The request gets passed up to my application, which calls
      ioctl_send_response().
      
      ioctl_send_response() then calls fw_send_response() with card0,
      because that's the card it's bound to.
      Card0's driver drops the response, because it isn't part of
      a transaction that it has outstanding.
      
      So in core-cdev: handle_request(), we need to stash the
      card of the inbound request in the struct inbound_transaction_resource and
      use that card to send the response to.
      
      The hard part will be refcounting the card correctly
      so it can't get deallocated while we hold a pointer to it.
      
      Here's a trivial patch, which does not do the card refcounting, but at
      least demonstrates what the problem is.
      
      Note that we can't depend on the fact that the core-cdev:client
      structure holds a card open, because in this case the card it holds
      open is not the card the request came in on.
      
      ..and there's no way for the core to tell cdev "this card is gone,
      kill any inbound transactions on it", while cdev holds the transaction
      open until userspace issues a SEND_RESPONSE ioctl, which may be a very,
      very long time.  But when it does, it calls fw_send_response(), which
      will dereference the card...
      
      So how unhappy are we about userspace potentially holding a fw_card
      open forever?
      Signed-off-by: NJay Fenlason <fenlason@redhat.com>
      
      Reference counting to be addressed in a separate change.
      
      Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de> (whitespace)
      08bd34c9
    • C
      firewire: cdev: fix race in iso context creation · bdfe273e
      Clemens Ladisch 提交于
      Protect the client's iso context pointer against a race that can happen
      when more than one creation call is executed at the same time.
      Signed-off-by: NClemens Ladisch <clemens@ladisch.de>
      Signed-off-by: NStefan Richter <stefanr@s5r6.in-berlin.de>
      bdfe273e
    • S
      firewire: remove an unused function argument · 33e553fe
      Stefan Richter 提交于
      void (*fw_address_callback_t)(..., int speed, ...) is the speed that a
      remote node chose to transmit a request to us.  In case of split
      transactions, firewire-core will transmit the response at that speed.
      
      Upper layer drivers on the other hand (firewire-net, -sbp2, firedtv, and
      userspace drivers) cannot do anything useful with that speed datum,
      except log it for debug purposes.  But data that is merely potentially
      (not even actually) used for debug purposes does not belong into the API.
      Signed-off-by: NStefan Richter <stefanr@s5r6.in-berlin.de>
      33e553fe
  3. 20 6月, 2010 1 次提交
  4. 19 6月, 2010 1 次提交
  5. 10 6月, 2010 2 次提交
  6. 10 4月, 2010 4 次提交
  7. 25 2月, 2010 3 次提交
  8. 21 2月, 2010 2 次提交
    • S
      firewire: remove incomplete Bus_Time CSR support · 168cf9af
      Stefan Richter 提交于
      The current implementation of Bus_Time read access was buggy since it
      did not ensure that Bus_Time.second_count_hi and second_count_lo came
      from the same 128 seconds period.
      Reported-by: NHåkan Johansson <f96hajo@chalmers.se>
      
      Instead of a fix, remove Bus_Time register support altogether.  The spec
      requires all cycle master capable nodes to implement this (all Linux
      nodes are cycle master capable) while it also says that it "may" be
      initialized by the bus manager or by the IRM standing in for a bus
      manager.  (Neither Linux' firewire-core nor ieee1394 nodemgr implement
      this.)
      
      Since we cannot rely on Bus_Time having been initialized by a bus
      manager, it is better to return an error instead of a nonsensical value
      on a read request to Bus_Time.
      
      Alternatively, we could fix the Bus_Time read integrity bug _and_
      implement (a) cycle master's write support of the register as well as
      (b) bus manager's Bus_Time initialization service, i.e. preservation of
      the Bus_Time when the cycle master node of a bus changes.  However, that
      would be quite some code for a feature that is unreliable to begin with
      and very likely unused in practice.
      Signed-off-by: NStefan Richter <stefanr@s5r6.in-berlin.de>
      168cf9af
    • S
      firewire: get_cycle_timer optimization and cleanup · 4a9bde9b
      Stefan Richter 提交于
      ohci:  Break out of the retry loop if too many attempts were necessary.
      This may theoretically happen if the chip is fatally defective or if the
      get_cycle_timer ioctl was performed after a CardBus controller was
      ejected.
      
      Also micro-optimize the loop by re-using the last two register reads in
      the next iteration, remove a questionable inline keyword, and shuffle a
      comment around.
      
      core:  ioctl_get_cycle_timer() is always called with interrupts on,
      therefore local_irq_save() can be replaced by local_irq_disable().
      Disabled local IRQs imply disabled preemption, hence preempt_disable()
      can be removed.
      Signed-off-by: NStefan Richter <stefanr@s5r6.in-berlin.de>
      4a9bde9b
  9. 27 1月, 2010 1 次提交
    • S
      firewire: core: fix use-after-free regression in FCP handler · 281e2032
      Stefan Richter 提交于
      Commit db5d247a "firewire: fix use of multiple AV/C devices, allow
      multiple FCP listeners" introduced a regression into 2.6.33-rc3:
      The core freed payloads of incoming requests to FCP_Request or
      FCP_Response before a userspace driver accessed them.
      
      We need to copy such payloads for each registered userspace client
      and free the copies according to the lifetime rules of non-FCP client
      request resources.
      
      (This could possibly be optimized by reference counts instead of
      copies.)
      
      The presently only kernelspace driver which listens for FCP requests,
      firedtv, was not affected because it already copies FCP frames into an
      own buffer before returning to firewire-core's FCP handler dispatcher.
      Signed-off-by: NStefan Richter <stefanr@s5r6.in-berlin.de>
      281e2032
  10. 30 12月, 2009 2 次提交
    • S
      firewire: cdev: fix another memory leak in an error path · cf0e575d
      Stefan Richter 提交于
      If copy_from_user in an FW_CDEV_IOC_SEND_RESPONSE ioctl failed, the
      fw_request pointed to by the inbound_transaction_resource is no
      longer referenced and needs to be freed.
      Signed-off-by: NStefan Richter <stefanr@s5r6.in-berlin.de>
      cf0e575d
    • C
      firewire: fix use of multiple AV/C devices, allow multiple FCP listeners · db5d247a
      Clemens Ladisch 提交于
      Control of more than one AV/C device at once --- e.g. camcorders, tape
      decks, audio devices, TV tuners --- failed or worked only unreliably,
      depending on driver implementation.  This affected kernelspace and
      userspace drivers alike and was caused by firewire-core's inability to
      accept multiple registrations of FCP listeners.
      
      The fix allows multiple address handlers to be registered for the FCP
      command and response registers.  When a request for these registers is
      received, all handlers are invoked, and the Firewire response is
      generated by the core and not by any handler.
      
      The cdev API does not change, i.e., userspace is still expected to send
      a response for FCP requests; this response is silently ignored.
      Signed-off-by: NClemens Ladisch <clemens@ladisch.de>
      Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de> (changelog, rebased, whitespace)
      db5d247a
  11. 31 10月, 2009 1 次提交
  12. 15 10月, 2009 3 次提交
  13. 05 10月, 2009 1 次提交
  14. 26 6月, 2009 1 次提交
    • S
      firewire: core: do not DMA-map stack addresses · 6fdc0370
      Stefan Richter 提交于
      The DMA mapping API cannot map on-stack addresses, as explained in
      Documentation/DMA-mapping.txt.  Convert the two cases of on-stack packet
      payload buffers in firewire-core (payload of lock requests in the bus
      manager work and in iso resource management) to slab-allocated memory.
      
      There are a number on-stack buffers for quadlet write or quadlet read
      requests in firewire-core and firewire-sbp2.  These are harmless; they
      are copied to/ from card driver internal DMA buffers since quadlet
      payloads are inlined with packet headers.
      Signed-off-by: NStefan Richter <stefanr@s5r6.in-berlin.de>
      6fdc0370
  15. 07 6月, 2009 1 次提交
  16. 05 6月, 2009 2 次提交
    • S
      firewire: rename source files · e71d31da
      Stefan Richter 提交于
      The source files of firewire-core, firewire-ohci, firewire-sbp2, i.e.
       "drivers/firewire/fw-*.c"
      are renamed to
       "drivers/firewire/core-*.c",
       "drivers/firewire/ohci.c",
       "drivers/firewire/sbp2.c".
      
      The old fw- prefix was redundant to the directory name.  The new core-
      prefix distinguishes the files according to which driver they belong to.
      
      This change comes a little late, but still before further firewire
      drivers are added as anticipated RSN.
      Signed-off-by: NStefan Richter <stefanr@s5r6.in-berlin.de>
      e71d31da
    • S
      firewire: reorganize header files · 77c9a5da
      Stefan Richter 提交于
      The three header files of firewire-core, i.e.
       "drivers/firewire/fw-device.h",
       "drivers/firewire/fw-topology.h",
       "drivers/firewire/fw-transaction.h",
      are replaced by
       "drivers/firewire/core.h",
       "include/linux/firewire.h".
      
      The latter includes everything which a firewire high-level driver (like
      firewire-sbp2) needs besides linux/firewire-constants.h, while core.h
      contains the rest which is needed by firewire-core itself and by low-
      level drivers (card drivers) like firewire-ohci.
      
      High-level drivers can now also reside outside of drivers/firewire
      without having to add drivers/firewire to the header file search path in
      makefiles.  At least the firedtv driver will be such a driver.
      
      I also considered to spread the contents of core.h over several files,
      one for each .c file where the respective implementation resides.  But
      it turned out that most core .c files will end up including most of the
      core .h files.  Also, the combined core.h isn't unreasonably big, and it
      will lose more of its contents to linux/firewire.h anyway soon when more
      firewire drivers are added.  (IP-over-1394, firedtv, and there are plans
      for one or two more.)
      
      Furthermore, fw-ohci.h is renamed to ohci.h.  The name of core.h and
      ohci.h is chosen with regard to name changes of the .c files in a
      follow-up change.
      Signed-off-by: NStefan Richter <stefanr@s5r6.in-berlin.de>
      77c9a5da
  17. 17 5月, 2009 1 次提交
    • S
      firewire: core: improve check for local node · 92368890
      Stefan Richter 提交于
      My recently added test for a device being local in fw-cdev.c got it
      slightly wrong:  Comparisons of node IDs are only valid if the
      generation is current, which I forgot to check.  Normally, serialization
      by card->lock takes care of this, but a device in FW_DEVICE_GONE state
      will necessarily have a wrong generation and invalid node_id.
      
      The "is it local?" check is made 100% correct and simpler now by means
      of a struct fw_device flag which is set at fw_device creation.
      
      Besides the fw-cdev site which was to be fixed, there is another site
      which can make use of the new flag, and an RFC-2734 driver will benefit
      from it too.
      Signed-off-by: NStefan Richter <stefanr@s5r6.in-berlin.de>
      92368890
  18. 25 3月, 2009 7 次提交
    • S
      firewire: cdev: add closure to async stream ioctl · 18e9b10f
      Stefan Richter 提交于
      This changes the as yet unreleased FW_CDEV_IOC_SEND_STREAM_PACKET ioctl
      to generate an fw_cdev_event_response event just like the other two
      ioctls for asynchronous request transmission do.  This way, clients get
      feedback on successful or unsuccessful transmission.
      
      This also adds input validation for length, tag, channel, sy, speed.
      Signed-off-by: NStefan Richter <stefanr@s5r6.in-berlin.de>
      18e9b10f
    • S
      firewire: cdev: simplify FW_CDEV_IOC_SEND_REQUEST return value · 664d8010
      Stefan Richter 提交于
      This changes the ioctl() return value of FW_CDEV_IOC_SEND_REQUEST and of
      the as yet unreleased FW_CDEV_IOC_SEND_BROADCAST_REQUEST.  They used to
      return
      	sizeof(struct fw_cdev_send_request *) + data_length
      
      which is obviously a failed attempt to emulate the return value of
      raw1394's respective interface which uses write() instead of ioctl().
      
      However, the first summand, as size of a kernel pointer, is entirely
      meaningless to clients and the second summand is already known to
      clients.  And the result does not resemble raw1394's write() return
      code anyway.
      
      So simplify it to a constant non-negative value, i.e. 0.  The only
      dangers here would be that future client implementations check for error
      by ret != 0 instead of ret < 0 when running on top of an old kernel; or
      that current clients interpret ret = 0 or more as failure.  But both are
      hypothetical cases which don't justify to return irritating values.
      
      While we touch this code, also remove "& 0x1f" from tcode in the call of
      fw_send_request.  The tcode cannot be bigger than 0x1f at this point.
      Signed-off-by: NStefan Richter <stefanr@s5r6.in-berlin.de>
      664d8010
    • S
      firewire: cdev: fix race of ioctl_send_request with bus reset · 207fbefb
      Stefan Richter 提交于
      The bus reset handler concurrently frees client->device->node.  Use
      device->node_id instead.  This is equivalent to device->node->node_id
      while device->generation is current.
      Signed-off-by: NStefan Richter <stefanr@s5r6.in-berlin.de>
      207fbefb
    • S
      firewire: cdev: secure add_descriptor ioctl · de487da8
      Stefan Richter 提交于
      The access permissions and ownership or ACL of /dev/fw* character device
      files will typically be set based on the device type of the respective
      nodes, as obtained by firewire-core from descriptors in the device's
      configuration ROM.  An example policy is to deny write permission by
      default but grant write permission to files of AV/C video and audio
      devices and IIDC video devices.
      
      The FW_CDEV_IOC_ADD_DESCRIPTOR ioctl could be used to partly subvert
      such a policy:  Find a device file with relaxed permissions, use the
      ioctl to add a descriptor with AV/C marker to the local node's ROM, thus
      gain access to the local node's character device file.  (This is only
      possible if there are udev scripts installed which actively relax
      permissions for known device types and if there is a device of such a
      type connected.)
      
      Accessibility of the local node's device file is relevant to host
      security if the host contains two or more IEEE 1394 link layer
      controllers which are plugged into a single bus.
      
      Therefore change the ABI to deny FW_CDEV_IOC_ADD_DESCRIPTOR if the file
      belongs to a remote node.  (This change has no impact on known
      implementers of the ABI:  None of them uses the ioctl yet.)
      
      Also clarify the documentation:  The ioctl affects all local nodes, not
      just one local node.
      
      Cc: stable@kernel.org
      Signed-off-by: NStefan Richter <stefanr@s5r6.in-berlin.de>
      de487da8
    • S
      firewire: cdev: amendment to "add ioctl to query maximum transmission speed" · c8a25900
      Stefan Richter 提交于
      The as yet unreleased FW_CDEV_IOC_GET_SPEED ioctl puts only a single
      integer into the parameter buffer.  We can use ioctl()'s return value
      instead.
      
      (Also: Some whitespace change in firewire-cdev.h.)
      Signed-off-by: NStefan Richter <stefanr@s5r6.in-berlin.de>
      c8a25900
    • J
      firewire: implement asynchronous stream transmission · f8c2287c
      Jay Fenlason 提交于
      Allow userspace and other firewire drivers (fw-ipv4 I'm looking at
      you!) to send Asynchronous Transmit Streams as described in 7.8.3 of
      release 1.1 of the 1394 Open Host Controller Interface Specification.
      Signed-off-by: NJay Fenlason <fenlason@redhat.com>
      Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de> (tweaks)
      f8c2287c
    • S
      firewire: cdev: simplify a schedule_delayed_work wrapper · 81610b8f
      Stefan Richter 提交于
      The kernel API documentation says that queue_delayed_work() returns 0
      (only) if the work was already queued.  The return codes of
      schedule_delayed_work() are not documented but the same.
      
      In init_iso_resource(), the work has never been queued yet, hence we
      can assume schedule_delayed_work() to be a guaranteed success there.
      Signed-off-by: NStefan Richter <stefanr@s5r6.in-berlin.de>
      81610b8f