Commit graph

236 commits

Author SHA1 Message Date
Johan Hovold
dfcba8626f greybus: operation: fix broken response error messages
The operation type included in the error message printed for malformed
responses has never been correct. An uninitialised buffer was used to
retrieve the type, resulting in the type always being reported as 0.

Fix this by passing a properly aligned header to the response handler,
and drop the now redundant id and result parameters.

Fixes: cb0ef0c019ab ("operation: print message type on errors")
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-26 14:53:19 -07:00
David Lin
e514dec730 greybus: operation: print id when synchronous operation timeout
In case of a synchronous operation timeout error, it's helpful for
purpose of debugging to print the operation id in the error message, so
that we know if the response is received at a later time after operation
time out.

Testing Done:
 - Observe the error message below when response comes later after
operation timeout:

[  792.973978] greybus greybus1: 0/0:0: synchronous operation id 0x0005
of type 0x21 failed: -110
[  800.646694] greybus greybus1: 0/0:0: unexpected response id 0x0005
received

Signed-off-by: David Lin <dtwlin@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-22 13:57:11 -07:00
Viresh Kumar
05e3095563 greybus: Revert "greybus: ratelimit errors usually seen on unipro_reset"
This reverts commit 9b891f4fda8dfd6c1d8dc16479c5f6d418a9ccc7.

We discussed this over the other thread,

[PATCH 0/2] Improve watchdog's implementation a bit,

and decided that we shouldn't be trying to hide the watchdog reboot
problem by using such patches, rather we should make sure they occur
consistently so that the real problem can be fixed.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-23 14:06:08 -07:00
Vaibhav Hiremath
2d533cf16b greybus: ratelimit errors usually seen on unipro_reset
It is believed that excessive serial messages from greybus
on suspend/resume is leading to watchdog bite.
There is still discussion going on whether ratelimiting
prints would really fix anything, except it may reduce
traffic on serial console and probably bring out real issues
in the front.
So in order to meet the alpha requirement, we all decided to
get ratelimit change "as a TEMP fix" and decide later whether
we should revert back once we get proper suspend/resume implementation.

Please follow the discussion on Jira card SW-6261.

Testing Done: Build tested against ara/main branch.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Konstantin Buhchev <buhchev_konstantin@projectara.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-21 12:28:09 -07:00
Johan Hovold
dacf3eb7f3 greybus: fix tracepoint-related whitespace issues
Fix some whitespace issues introduced by the recent tracepoint changes.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-27 12:26:31 -07:00
Johan Hovold
3de5acfafb greybus: connection: implement proper connection closure
Implement proper connection closure, which includes sending ping
requests on the connection being tore down while coordinating with the
remote interface as well as the SVC.

This specifically implements the new ping operation, which in case of
offloaded connections is handled by the host-device driver in an
implementation-defined manner through a new callback.

Note that the normal connection tear-down procedure is executed in case
of failed connection establishment due to failed connected operation.
Specifically, the disconnecting request is sent also in case the
connected operation never succeeded. This is needed since the interface
may have enabled FCT flow upon receiving the connected request.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-27 12:24:17 -07:00
Johan Hovold
18079ece81 greybus: operation: add helper for creating core operations
Add a new core operation flag and a helper that core can use to create
core operations.

This will be used to implement the ping operations that core sends as
part of connection tear down.

Note that a new trace point is also added.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-27 12:21:16 -07:00
Johan Hovold
77bbbcf6d3 greybus: operation: restructure activation state handling
Restructure the operation activation state handling in preparation for a
new disconnecting state.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-27 12:21:16 -07:00
Johan Hovold
8890f95710 greybus: operation: clean up early connection-state check
Now that the legacy invalid state is gone, clean up the early
connection-state check in the receive path and explicitly drop incoming
messages for disabled connection.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-27 12:21:16 -07:00
Alex Elder
df732546ce greybus: tracing: fix a bad tracepoint
In gb_operation_put_active(), the wrong trace point is being called.
Fix that.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-26 22:37:19 -07:00
Alex Elder
f866e66f36 greybus: add operation traces
Define a new gb_operation event class, and define and use trace
events that record when an operation is created, finally destroyed,
and when its active count changes.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-20 17:12:25 -07:00
Johan Hovold
ef62adae82 greybus: operation: fix broken activation logic
An operation should only be added to the connection active list if the
connection is in the enabled state, or if it is in the enabled_tx state
and the operation is not incoming.

This fixes a race where an early or late incoming request could be added
to the active list while the connection is being enabled or disabled,
something which could lead to use-after-free issues or worse.

Note that the early connection-state checks in the receive path
limited the impact of this bug.

Fixes: e903a2ce7379 ("connection: add unidirectional enabled state")
Reported-by: Alex Elder <elder@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-18 16:30:52 -07:00
Eli Sennesh
b0e97bce15 greybus: operation: rate-limit dev_err printing on the receive path
When we receive Greybus operations we don't recognize, requests or responses,
en masse, we can pile up a lot of dev_err() printk messages.  Doing so along
the gb_connection_recv() code path can delay receive processing by up to seven
milliseconds, starving the system of bulk-IN urbs.  Rate limit those printk
messages, ensuring that after too many repeated errors at the same place in
the code-path, we'll stop printing to the console at all and let the urbs get
returned.

This will help prevent denial-of-service attacks on the AP through the UniPro
network from malicious or malfunctioning modules.

Testing Done: 7 msec recv-to-resubmit-urb processing times go down to <20
usecs

Signed-off-by: Eli Sennesh <esennesh@leaflabs.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Mitchell Tasman <tasman@leaflabs.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-17 09:21:10 -07:00
Johan Hovold
ca1f8f8090 greybus: connection: add offloaded connection flag
Add an offloaded connection flag, which is used to mark a connection as
offloaded and prevent drivers from initiating operation over it.

This will be used for the audio and camera data connections.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-13 15:30:05 +02:00
David Lin
c77bac08ec greybus: operation: fix an inconsistent indent
This patch fixes an inconsistent indent.

Testing Done:
- Build & boot

Signed-off-by: David Lin <dtwlin@google.com>
Acked-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-09 08:55:12 +02:00
Johan Hovold
7adb32b429 greybus: operation: fix definition of the invalid type
The invalid request type has been redefined as 0x7f.

Also remove the redundant redefinition of the invalid type from the
operation header.

Note that operation type 0x00 has been repurposed for the new generic
ping operation, which will be used to implement proper connection tear
down.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-04-29 14:27:05 -07:00
Johan Hovold
5fdc027d54 greybus: operation: add helper functions for unidirectional operations
Add helper functions for initiating unidirectional operations and
waiting for them to have been acknowledged as sent by the host device.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-04-29 14:27:05 -07:00
Johan Hovold
3e2ee2c1e5 greybus: operation: add support for initiating unidirectional operations
Add support for initiating unidirectional operations, that is, sending
requests that do not require responses.

Note that we already handle incoming unidirectional operations.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-04-29 14:27:05 -07:00
Johan Hovold
613c15e86b greybus: operation: update gb_operation_request_send() documentation
Fix and update gb_operation_request_send() documentation and add
kernel-doc formatting.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-04-29 14:27:05 -07:00
Johan Hovold
410abddb03 greybus: fix outdated kernel-doc comment
Update the function name, which has gained a timeout suffix.

Also fix the kernel-doc formatting.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-04-29 14:27:05 -07:00
Johan Hovold
7e43e337a5 greybus: operation: add support for short responses
Add support for operations with short responses.

So far we have assumed that the initiator of an operation always knows
the exact size of the expected response. This is however not always the
case and we've worked around this limitation in a couple of places by,
for example, first requesting the size of a resource before fetching the
actual data.

To avoid such workarounds and simplify our protocols, add a
short-response flag that can be set when allocating an operation. When
this flag is set on an operation, core will accept a response that is
shorter than the size of the (pre-allocated) response payload buffer.

For now, we update the response-message payload_size field to reflect
the actual length of the response received.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-02-25 16:26:58 -08:00
Johan Hovold
34804efb0c greybus: operation: add temporary pointer to response handler
As a preparatory clean up, add a temporary variable to point to the
response message header.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-02-25 16:26:58 -08:00
Johan Hovold
b427572ebf greybus: core: add device prefix to error messages
Use dev_err and dev_warn where appropriate and remove now unused pr_fmt
defines.

Testing Done:
Tested on DB3.5 with the generic bridge firmware on APB2.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-02-11 21:44:17 -08:00
Johan Hovold
570dfa7c55 greybus: connection: add unidirectional enabled state
Add a new connection state ENABLED_TX in which only outgoing operations
are allowed.

This allows drivers to query the device during probe before allocating
their state containers without having to worry about racing incoming
requests.

Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-01-19 12:12:40 -08:00
Johan Hovold
bfa9a5e2d0 greybus: connection: add per-connection request handlers
Add a connection request-handler field to struct gb_connection that is
set when the connection is enabled.

This is a step towards removing the legacy protocol abstraction from
core, and will also be used to implement unidirectional connection
states (e.g. only outgoing operations are allowed).

Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-01-19 12:12:40 -08:00
Viresh Kumar
2f3db927cd greybus: don't use %h and %hh for printing short and char variables
Because the width of our fields is already known, we can use %0Nx (for
hex) to print N bytes and %u (for unsigned decimal), instead of using %h
and %hh, which isn't that readable.

This patch makes following changes:
- s/%hx/%04x
- s/%04hx/%04x
- s/%hhx/%02x
- s/%02hhx/%02x
- s/%hhu/%u
- s/%hu/%u
- s/%x/%02x for u8 value (only at a single place)

Suggested-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-12-04 16:23:36 -08:00
Johan Hovold
25cdd7aa5e greybus: operation: handle static connections
Use the host-device device and connection name for error messages, as
the operation code can not assume that a connection has a bundle.

Note that the "initial" svc connection has never had a bundle.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-11-25 15:34:19 -08:00
Johan Hovold
2537636aba greybus: hd: rename host-device structure
Rename host-device structure gb_host_device to match our other
structures.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-11-04 20:25:57 -08:00
Greg Kroah-Hartman
c3aa655665 greybus: operation: use the bundle struct device instead of the connector
We are removing struct device from the gb_connection structure in the
near future.  The gb_bundle structure's struct device should be used as
a replacement.

This patch moves the operation code to use to use the bundle pointer
instead of the connection pointer when printing out error messages.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Alex Elder <elder@linaro.org>
2015-10-15 09:19:15 -07:00
Johan Hovold
0b1118a9ef greybus: operation: clean up error messages
Clean up and improve error messages.

Demote a warning message to warning level.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-10-14 12:01:15 -07:00
Johan Hovold
ff65e20ee5 greybus: operation: drop OOM-response FIXME
Drop FIXME about sending responses in OOM situations.

If we fail to allocate an operation for an incoming request, we have
bigger problems than to worry about sending a response.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-10-14 12:01:15 -07:00
Johan Hovold
6ab1ce4d54 greybus: operation: remove gb_operation_destroy
Remove legacy interface to "destroy" operations, which is now just a
wrapper for gb_operation_put.

The old interface name hides the fact that all operations are refcounted
and may live on even after having "destroyed" them.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-09-29 19:14:26 +02:00
Bryan O'Donoghue
5c8ad599b9 greybus: operation, core: hook tracepoints into message opertions
This patch hooks tracepoints for greybus messages

- trace_gb_message_send
- trace_gb_message_recv_request
- trace_gb_message_recv_response
- trace_gb_message_cancel_outgoing
- trace_gb_message_cancel_incoming

It provides standard tracepoints at

/sys/kernel/debug/tracing/events/greybus/gb_message_send
/sys/kernel/debug/tracing/events/greybus/gb_message_recv_response
/sys/kernel/debug/tracing/events/greybus/gb_message_recv_request
/sys/kernel/debug/tracing/events/greybus/gb_message_cancel_outgoing
/sys/kernel/debug/tracing/events/greybus/gb_message_cancel_incoming

Giving outputs like

gb_message_recv_request: greybus:1-1.1:0 op=0001 if_id=0000 hd_id=0000 l=2
gb_message_send: greybus:1-1.1:0 op=0001 if_id=0000 hd_id=0000 l=2

Similarly perf events can be viewed with standard perf tools e.g.

root@beaglebone:~# perf list 'greybus:*'
  greybus:gb_message_send                            [Tracepoint event]
  greybus:gb_message_recv_request                    [Tracepoint event]
  greybus:gb_message_recv_response                   [Tracepoint event]
  greybus:gb_message_cancel_outgoing                 [Tracepoint event]
  greybus:gb_message_cancel_incoming                 [Tracepoint event]

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-09-18 14:07:28 -07:00
Viresh Kumar
4be6ea54d4 greybus: operation: Fix wrong order of arguments
The order of arguments is wrong and that shows up as a warning only on
64 bit machines.

Fixes: cb0ef0c019ab ("operation: print message type on errors")
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-08-18 09:31:07 -07:00
Viresh Kumar
21e3a3ed9b greybus: operation: print message type on errors
This can be very useful debug information, print it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-08-14 14:34:14 -07:00
Johan Hovold
701615f82f greybus: operation: add completion work queue
Add dedicated bound work queue for operation completions and use the
connection work queues for incoming requests only.

There is no need to keep responses ordered internally or with respect to
requests. Instead allow operations to complete as soon as possible when
a response arrives (or the operation is cancelled).

Note that this also allows synchronous requests to be submitted from
request handlers as responses will no longer be blocked on the same
single-threaded work queue. Similarly, operations can now also be
cancelled from a request handler.

Tested-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-23 12:55:25 -07:00
Johan Hovold
5a5bc354c6 greybus: operation: use per-connection work queues
Replace the global operation work queue with per-connection work queues.

There is no need to keep operations strictly ordered across connections,
something which only adds unnecessary latency.

Tested-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-23 12:55:25 -07:00
Johan Hovold
a4e08469eb greybus: operation: clean up greybus_message_sent
Add connection variable to greybus_message_sent.

This will be put to more use by a follow-up up patch.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Tested-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-22 11:10:33 -07:00
Johan Hovold
b4bd734ea6 greybus: operation: fix operation ordering
Make the operation work queue single threaded.

The operation work queue was meant to be single threaded, but due to a
missing flag instead allowed one active task per CPU, something which
could lead to requests being processed out of order on SMP systems.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Tested-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-22 11:10:33 -07:00
Johan Hovold
b84abdcb41 greybus: operation: fix atomic message submission
The recently added GFP-flags argument to gb_message_send was never used.

Fixes: 9218fac2a24d ("operation: allow atomic request submissions")
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-20 16:14:29 -07:00
Johan Hovold
1c7658cf51 greybus: operation: fix atomic response allocation
Response allocation also needs a GFP-flags argument as a response is
allocated as part of an outgoing operation.

Fixes: 9aa174d202e5 ("operation: allow atomic operation allocations")
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-20 16:14:29 -07:00
Johan Hovold
129a06f541 greybus: operation: add gb_operation_sync_timeout helper
Add gb_operation_sync_timeout convenience function, which allows drivers
to configure the operation timeout.

Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-15 12:39:13 -07:00
Johan Hovold
4f2c08aba7 greybus: operation: allow drivers to define custom timeouts
Add new interface gb_operation_request_send_sync_timeout, which allows
drivers to define a custom operation timeout instead of the default
one-second timeout.

The timeout is expected to depend on protocol and operation and
therefore needs to be configurable.

Note that that a timeout of zero is used to wait indefinitely.

Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-15 12:39:13 -07:00
Johan Hovold
5a3be769e9 greybus: operation: split incoming and outgoing cancellation
Split incoming and outgoing operation-cancellation helpers.

Incoming operations are only cancelled as part of connection tear down
and is specifically not needed in the driver API.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-15 12:39:13 -07:00
Johan Hovold
0eb8c11598 greybus: operation: fix response-cancellation race
Make sure the request handler has submitted the response before
cancelling it during operation cancellation.

This prevents cancelling not-yet-submitted messages. It currently also
avoids us ending up with an active message on a stalled connection (e.g.
due to E2EFC).

Note that the call to gb_operation_result_set() is now redundant but is
kept as a precaution to guarantee that a response has indeed been
allocated as part of response submission.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-15 12:39:13 -07:00
Johan Hovold
3325a4ad71 greybus: operation: fix operation look-up race
Make sure to fully initialise the operation before adding it to the
active list when sending a request.

The operation should be fully initialised before adding it to the active
list to avoid racing with operation look up when receiving a response,
something which could potentially lead to a match against some earlier
(or intermediate) value of the id field.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-15 12:39:13 -07:00
Johan Hovold
008974cb52 greybus: operation: fix connection tear down
Fix connection tear down, which was done in an unsafe way that could
result in use-after-free as the per-connection list of operations was
iterated without any locking or refcounting.

Specifically, the operations list was iterated without holding any locks or
operation refcounts even though operations were being both removed from
the list and deallocated during per-operation cancellation. Any
operation completing during tear down could also cause corruption.

Change the per-connection operation list to only contain active
operations and use the recently introduced active counter to maintain
the list.

Add new helper that is called on connection tear down to cancel all
outstanding operations in a safe way by using proper locks and making
sure to hold a reference to any operation being cancelled.

Note that by verifying the connection state before incrementing the
active count we can make sure that all active operations have been
cancelled and that no new ones have been started when the helper
returns.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-15 12:39:13 -07:00
Johan Hovold
886c6069bc greybus: operation: suppress response submission on connection tear down
Suppress response submission on connection tear down as we do with
requests.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-15 12:39:13 -07:00
Johan Hovold
c600e535a7 greybus: operation: clean up operation work function
Call request handler helper explicitly from the work function rather
than overload the operation completion callback.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-15 12:39:13 -07:00
Johan Hovold
db1481ba7f greybus: operation: complete operations on cancellation
Make sure to call the operation completion callback also when the
operation is being cancelled.

The completion callback may need to release resources allocated at
submission and the driver should be informed that the operation has
failed due to cancellation.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-15 12:39:13 -07:00