Commit graph

52 commits

Author SHA1 Message Date
Dhoat Harpal
4172e2077f soc: qcom: glink: Initialize local state while fetching ctx
Initialization of channel's local state is not done at the time of
fetching context from list of channels. This leads to race condition
if remote close happens during this time. Remote close will check if
local state is not open then delete channel from list. This leads to
use after free scenerio.

Initialize local state at the time of fetching channel context from
list of channels.

CRs-Fixed: 2155992
Change-Id: If113daba129191bd67ef2460eb4e87c2d5614403
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2019-05-04 13:29:25 -07:00
Linux Build Service Account
879163d599 Merge "soc: qcom: glink: Add sub system up notification in glink" 2018-01-13 03:50:13 -08:00
Dhoat Harpal
f43f048321 soc: qcom: glink: Add sub system up notification in glink
Glink does not wait for pil to inform about subsystem up. It triggers
link up on first interrupt processed after ssr, this can cause stability
issues if some delayed interrupt is processed after ssr.

Glink waits for PIL to notify about subsystem up and initializes
its state only after that.

CRs-Fixed: 2165753
Change-Id: I71614e6d7e68bf2fa12ac7f27894492019bd3829
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2018-01-10 18:45:11 +05:30
Dhoat Harpal
5916f7a1f2 soc: qcom: glink: Modify glink logging in tx_common
Glink log in tx_common uses context based logging after
wait_for_completion_timeout. This can lead to use after free
scenerio, since transport of context can be freed during wait time.

Use glink error logging.

CRs-Fixed: 2164929
Change-Id: If66bcb7cba1772c2648c143f43a3b88af0799844
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2018-01-03 02:59:31 -08:00
Dhoat Harpal
9ed4818826 soc: qcom: glink: Add downvote of transport during SSR
During SSR, down vote transport of xprt is not called.
This leads to transport not being able to go to idle state.

Downvote of transport is called in SSR path.

CRs-Fixed: 2131780
Change-Id: Ic374073187aab95b700aa3f795787819f34d3c3c
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2017-10-26 19:21:44 +05:30
Dhoat Harpal
10181e6279 soc: qcom: glink: Free if_ptr before freeing dummy transport
Dummy transport is only way to access if_ptr. When dummy
transport is freed, if_ptr allocated for dummy transport is
not freed. This result in memory leak.

kfree of if_ptr is called before freeing dummy transport.

CRs-Fixed: 2116744
Change-Id: I832e0fcde418b7c3d992f50e817866bc9075da3c
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2017-09-28 07:57:52 -07:00
Dhoat Harpal
664fcc0919 soc: qcom: glink: Free data memory before freeing intent
Data of intent is not freed even in purge_intent_list. This results
in memory leak.

Kfree is done for data before freeing intent.

CRs-Fixed: 2116744
Change-Id: Ib99261208df1cc9b63b4cd0a35ac0c7942efb4a8
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2017-09-28 07:57:21 -07:00
Dhoat Harpal
e8574a4350 soc: qcom: glink: Initialize dummy xprt with dummy functions
Few function pointers are left uninitialized in dummy transport.
System can crash if these function pointer get dereferenced.

Initialize all the function pointers which can get called, with
dummy functions.

CRs-Fixed: 2067859
Change-Id: I9172776d9ffa0af5deb9898125fc6403fdcdee0f
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2017-08-21 21:05:29 +05:30
Linux Build Service Account
586584b2b2 Merge "soc: qcom: glink: Move get reference to valid location" 2017-06-29 03:32:32 -07:00
Dhoat Harpal
18c0e843c5 soc: qcom: glink: Move get reference to valid location
In function ch_name_to_ch_ctx_create reference for ctx is taken
without checking if ctx is valid. This leads to possible NULL pointer
dereference.

Take reference only when it is verified that ctx is not NULL.

CRs-Fixed: 2059742
Change-Id: I15998780b602e325a90e7c8c303cd442c5381fe8
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2017-06-27 15:01:24 +05:30
Dhoat Harpal
dcff893174 soc: qcom: glink: Remove magic number logic
Possible use after free issue while accessing magic number,
if the ctx is already freed.

Magic number check is removed.

CRs-Fixed: 2061287
Change-Id: Ie157a930c7eb310829766319e0af742114337e6c
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2017-06-23 20:40:16 +05:30
Linux Build Service Account
7ebaed16ad Merge "soc: qcom: glink: Move tx_info allocation in beginning" 2017-06-22 23:41:00 -07:00
Dhoat Harpal
e41b2890f8 soc: qcom: glink: Move tx_info allocation in beginning
TX_info is allocated after pop remote intent, this can cause problem
when there is no memory for allocation then glink has to push back the
intent, which again needs memory.

Tx_info allocation is moved before op remote intent.

CRs-Fixed: 2063427
Change-Id: I4f174c4b0143454596ac8f7a1c639c853b98a2ce
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2017-06-20 21:40:39 +05:30
Dhoat Harpal
bb73294fb7 soc: qcom: glink: Move ctx initialization of xprt ptr
In glink_open function, channel context initialization with transport
pointer is done quite after after its creation. This create race condition,
if parallel thread try to use transport pointer of ctx.

Ctx is initialized with transport pointer right at the time of its
creation.

CRs-Fixed: 2061645
Change-Id: Idcddf1ab10b8673a20bc1f23d8702bf870f79dbd
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2017-06-19 21:49:09 +05:30
Dhoat Harpal
a9d98d446b soc: qcom: glink: Reset qos rate when xprt is down
Reset for qos rate of xprt is not done duering SSR, this leads to
exhaustion of qos bandwidth when multiple SSR happens.

Reset qos rate of xprt to zero when link goes down.

CRs-Fixed: 2061061
Change-Id: Ibabca5584b01eb93a5b7fcc8a5304136ef400ba0
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2017-06-14 19:31:10 +05:30
Chris Lew
a3b6b4e493 soc: qcom: glink: Add new APIs to toggle RX thread priority
Low latency use cases are failing because glink RX thread to handle
the TX Done command is not being scheduled during high system load.
These new APIs allow clients to specify if they need the RX glink
thread to be Realtime

CRs-Fixed: 2050701
Change-Id: I6bd4023394e9ee617797826687f34abaee3fe65d
Signed-off-by: Chris Lew <clew@codeaurora.org>
2017-05-23 10:45:33 -07:00
Dhoat Harpal
eddbad962a soc: qcom: glink: Get additional reference in glink open
Inside glink_open reference for channel context is only initialized,
but additional reference is not taken. It creates the possibility of use
after free if SSR happens before glink_open function completes.

Additional reference is taken to ensure context stay valid during
glink_open, even if SSR happens.

CRs-Fixed: 2031123
Change-Id: I94650d2f937416aff33a82073c4db76fab0d0e96
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2017-04-11 14:58:54 +05:30
Linux Build Service Account
88e4d16567 Merge "soc: qcom: glink: Move channel to dummy xprt with lock" 2017-03-06 22:43:29 -08:00
Dhoat Harpal
ab59b289fe soc: qcom: glink: Move channel to dummy xprt with lock
In core_channel_cleanup function channel is moved to dummy xprt
without taking channel lock. This leads to race condition where
transport poniter is pointing to dummy but channel still belong
to old transport.

Channel is moved to dummy with channel lock.

CRs-Fixed: 2005731
Change-Id: I91903140c1bfa29d909847f318d1339bb717fffc
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2017-03-06 14:30:48 +05:30
Chris Lew
6979b9ae1c soc: qcom: glink: Fix uninitialized variable usage
Initialize values for variables that may be used with out
the value being set in glink corner cases.

CRs-Fixed: 2004073
Change-Id: If0e813bf1601dd6c1288bc22864ddd2fb3dbf90f
Signed-off-by: Chris Lew <clew@codeaurora.org>
2017-02-22 13:30:00 -08:00
Dhoat Harpal
cd5bd5f58a soc: qcom: glink: Change cleanup sequence in remote close
In function glink_core_remote_close_common, notify_state callback
is called before clearing wait queue. This leads to deadlock if client
want to synchronize tx and state notify function.

Complete_all is called before notify client about state change,
so that all pending requests from client will be cleared.

CRs-Fixed: 1107652
Change-Id: Ia6c4a305eb42c014a928bad36491e6e5f6eac9d5
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2017-01-05 14:48:19 +05:30
Linux Build Service Account
421c7867d1 Merge "soc: qcom: glink: Add pending remote done packets to intent purge" 2016-12-19 00:44:42 -08:00
Chris Lew
fbc3530d4f soc: qcom: glink: Add pending remote done packets to intent purge
Glink clients are not notified of tx transactions that are waiting
for remote rx done commands during SSR. This change adds a
notify_tx_abort call for any pending packets during intent purge.

Change-Id: I6a6ba17e2dffddc5cdc2de00da737fedf03c9476
Signed-off-by: Chris Lew <clew@codeaurora.org>
2016-11-30 18:03:18 -08:00
Dhoat Harpal
6bf0e69ea6 soc: qcom: glink: add NULL check for edge_ctx
In function edge_name_to_ctx_create, NULL check is missing after
kzalloc for edge_ctx variable.

NULL check validation is added.

CRs-Fixed: 1086686
Change-Id: Icbffbd9d02df97bda531353c41a7025b95a53991
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2016-11-28 18:12:44 +05:30
Dhoat Harpal
6998b685f2 soc: qcom: glink: Fix incorrect call to deinit function
In function glink_core_register_transport, deinit function for qos
configuration is called before initializing qos configuration.

Call to glink_core_deinit_xprt_qos_cfg function is removed.

CRs-Fixed: 1088375
Change-Id: Ifffab071efed56541e763e4f6f51aa45d7a6678b
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2016-11-10 20:24:36 +05:30
Linux Build Service Account
b2799f1e25 Merge "soc: qcom: glink: Fix ctx initialization with magic number" 2016-10-14 03:40:30 -07:00
Linux Build Service Account
cade0ea953 Merge "soc: qcom: glink: Fix uninitialzed return value" 2016-10-13 19:11:23 -07:00
Dhoat Harpal
28494e0862 soc: qcom: glink: Fix ctx initialization with magic number
Glink channel context is initialized with magic number after sending
open command to remote side.

Initialization is fixed and happen before sending open command.

CRs-Fixed: 1075481
Change-Id: Ia6b28a3b35a4093aea7af1cffea2a5e093d33ccd
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2016-10-07 16:52:56 +05:30
Dhoat Harpal
3cc9716866 soc: qcom: glink: Fix uninitialzed return value.
Initialize the return value in the glink tx scheduler
function.

CRs-Fixed: 1067981
Change-Id: I3f78196927501f582c36d5815096581185d797b4
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2016-09-23 18:29:06 +05:30
Chris Lew
1941719e78 soc: qcom: glink: Fix uninitialzed return value
Initialize the return value in the glink tx scheduler
function.

CRs-Fixed: 1067981
Change-Id: I7cad7a724666f34bce73d40e4975373604fb1e87
Signed-off-by: Chris Lew <clew@codeaurora.org>
2016-09-22 16:54:38 -07:00
Dhoat Harpal
9026b491f3 soc: qcom: glink: Fix list corruption for tx_info
Inside glink_scheduler_tx tx_info is not validated after tx operation
and taking spin lock, since there are two functions which can release
the reference for tx_info while glink_scheduler_tx thread is preempted.
These functions are ch_purge_intent_lists and
ch_remove_tx_pending_remote_done.

Validate tx_info from tx_active list after tx operation and taking
spin lock.

CRs-Fixed: 1061565
Change-Id: I80c64d66625b9fe9205e8ffaa7cfc851e06fcb94
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2016-09-14 17:02:45 +05:30
Linux Build Service Account
08223d34ed Merge "soc: qcom: glink: Reduce code under spinlock" 2016-09-09 11:53:08 -07:00
Linux Build Service Account
d95f7bea18 Merge "soc: qcom: glink: Validate ctx before using" 2016-09-02 13:52:25 -07:00
Dhoat Harpal
4f6f2d2a7b soc: qcom: glink: Reduce code under spinlock
Glink core channel cleanup has a lot of code under spinlock with
preemption disabled this leads to deadlock scenerio.

Spinklock is used only for critical section, rest of the code is
be without spinlock.

CRs-Fixed: 1060407
Change-Id: I577dbff1cf2ee3711e1879aaa6dc48c72f98b98c
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2016-09-02 18:01:10 +05:30
Dhoat Harpal
6111a89212 soc: qcom: glink: Validate ctx before using
Glink does not validate the received handle from client apis.
This leads to possibility of illegal memeory access.

Magic number is added along with rcu lock to validate handle
received from client.

CRs-Fixed: 1047743
Change-Id: I08c854d5885672cbe5410efe0736640b55de8bbb
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2016-08-24 18:29:47 +05:30
Dhoat Harpal
4669c62339 soc: qcom: glink: Best Fit approach to find intent
Using first fit algorithm to select the remote rx intent from the
list is not optimal way.

Optimize the selection of intent from list using the best fit algorithm.

CRs-Fixed: 1058750
Change-Id: I7b2a70188975b75a0fbcd2a6cb26f28cc0258532
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2016-08-24 17:47:16 +05:30
Karthikeyan Ramasubramanian
43c0652c76 soc: qcom: glink_spi_xprt: Add support for GLink SPI Transport
GLink SPI Transport enables point-to-point communication with an
external subsystem that uses SPI bus to interface. This enables
multiplexing multiple logical channels over the SPI bus.

CRs-Fixed: 1045916
Change-Id: I1936bb0542bcd531726bf987ef806969ce96d498
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
2016-08-04 10:29:52 -06:00
Karthikeyan Ramasubramanian
a1fa510e64 soc: qcom: glink: Receive remote rx_intent with a cookie
Currently the remote rx_intent is stored with the primary information.
The transport cannot provide a cookie to be retrieved and used later during
transmission.

Add support to receive a remote rx_intent with a cookie.

CRs-Fixed: 1045916
Change-Id: Id5f204647205b2fde9e5cb422a3ddc8cc4f3a5a0
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
2016-08-03 11:37:13 -06:00
Dhoat Harpal
05360211f8 soc: qcom: glink: Fix parallel migration issue
During parallel migration race conditions are seen in remote open
and local open ack function.

Edge based lock is introduced to avoid any race condition during
simultaneous migration. Edge lock is shared across multiple
transport of same edge and is stored in a global list.

CRs-Fixed: 1010920
Change-Id: I2b988d2a6112add06fa433c4b1deeec0b6e6bb58
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2016-06-08 15:20:06 -07:00
Chris Lew
7d7d65221b soc: qcom: glink: Fix race condition in dummy xprt cleanup
In glink_core_channel_cleaup there is a race condition while
traversing the channels list. This change holds the xprt
channel spinlock during the list manipulation.

CRs-Fixed: 988266
Change-Id: Idcff59ca1483fd98173255d6258e6771d91dec19
Signed-off-by: Chris Lew <clew@codeaurora.org>
2016-05-16 20:10:29 -07:00
Chris Lew
d7e810a2ce soc: qcom: glink: Fix ssr race condition in glink_close
Add else statement in glink_close for a race condition where the
xprt state is set to GLINK_XPRT_DOWN and glink_close runs before
the channel is migrated.

CRs-Fixed: 988266
Change-Id: I4de6530f1fbffd9f3acd1fa539cf756364ea32ac
Signed-off-by: Chris Lew <clew@codeaurora.org>
2016-05-10 13:20:19 -07:00
Dhoat Harpal
9763e34fbc soc: qcom: glink: Fix channel migration on fully open channel
If process_open_event is delayed and glink has migrated to new transport,
process open event will be treated as a new open event and migration will
happen on fully open channel.

If channel is fully, open migration will not be allowed as client might
already be using the channel for communication.

Change-Id: I6c1760bc19f52e7d0c1c9834a72e2304f0ae28c8
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2016-05-06 12:06:26 -07:00
Chris Lew
798f2438dd soc: qcom: glink: Refactor rwref lock mechanism
Add an option to rwref locks that allow the lock functions
to spin when acquiring the lock. Change completion variable
to use waitqueues for sleep functionality.

Change rwref reference function calls to use locking functions
where code reads or writes the context state.

CRs-Fixed: 988266
Change-Id: Ib2908b2495b1b01a6a130033143a7da8e5c0c231
Signed-off-by: Chris Lew <clew@codeaurora.org>
2016-04-27 19:04:49 -07:00
Chris Lew
4ac9a6bc2a soc: qcom: glink: Reorganize glink lock hierarchy
Update the locking hierarchy to reflect the current and
future use-cases. This helps in avoiding deadlock due
to out-of-order locking scenario.

CRs-Fixed: 988266
Change-Id: Ib40da2ecd413e7712cacc9663394e725ebd64a0a
Signed-off-by: Chris Lew <clew@codeaurora.org>
2016-04-27 19:04:49 -07:00
Karthikeyan Ramasubramanian
8266c2d117 soc: qcom: glink: Fix channel migration logic
Channel migration logic assumes that the remote & local channel contexts
are always different and exist in different transports. If the remote
& local channel contexts exist in the same transport, then it leads to
a use-after-free scenario.

Fix the channel migration logic by not freeing the channel context if
the local & remote side opens in the same initial transport.

Change-Id: I319a93c49022b08e5c33b561d982a751d5223a58
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
2016-04-18 17:06:16 -07:00
Dhoat Harpal
8876c65ca7 soc: qcom: glink: Use tasklet/kworker for TX and RX path
Currently, Rx an Tx is based on workqueue and it is taking significant
time to schedule a workqueue which is hampering performance.

Use tasklet if underlying transport supports atomic context, otherwise
kworker is used.

CRs-Fixed: 978296
Change-Id: I736d2b90730ec10f9dff21944c4ad50e4d87da5c
Signed-off-by: Dhoat Harpal <hdhoat@codeaurora.org>
2016-04-12 15:49:53 -07:00
Karthikeyan Ramasubramanian
243a901e21 soc: qcom: glink: Signal the waiter for rx_intent ack under error
During subsystem restart, if a transmit operation is waiting for a remote
receive intent acknowledgment, signal the waiter that the receive intent
request will not be acknowledged. Also check the transport and channel
state before waiting for the acknowledgment. This will prevent the
transmit operation from blocking indefinitely under error scenario.

CRs-Fixed: 952184
Change-Id: I29b8215841f7dcca52137f451665eaf339a6f78e
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
2016-03-23 21:15:35 -07:00
Karthikeyan Ramasubramanian
6abda44581 soc: qcom: glink: Fix race condition between tx and close operation
The channel is closed locally by the client either as part of SSR or normal
working scenario. The transmit operation does not check the transport or
channel states before queuing the packet for transmit operation. This
causes the transmit operation to access stale transport or channel context.

Check the transport and channel state before queuing the packet for
transmission.

CRs-Fixed: 947627
Change-Id: Ic6f8350b6b5e51b641794255f8520ff4616343bb
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
2016-03-23 21:15:04 -07:00
Steven Cahail
ea74beeae9 soc: qcom: glink: Add RX intent request timeout to G-Link channels
During glink_tx(), G-Link can wait for an unlimited amount of time for
the remote side to queue an RX intent. In some cases, e.g. SSR, the wait
must be restricted to a short time, but in the current implementation,
glink_tx() can continue to block indefinitely.

Add a configurable timeout value to the G-Link channel context, which is
set in the channel open configuration. If the value is set to 0, treat
it as an infinite timeout. This allows a timeout to be put in place by
the client for sensitive cases such as SSR where a very limited amount of
time can be spent waiting for an intent.

Change-Id: I1e480fac286d285f871fe3059de7ae761fc4581e
Signed-off-by: Steven Cahail <scahail@codeaurora.org>
2016-03-23 21:13:25 -07:00
Arun Kumar Neelakantam
9188869e03 soc: qcom: glink: Add support for transport based logging
All Transports debug logs are captured in one logging context
which makes the debugging difficult and has a chance to miss
the important logs due to other high traffic transports like RPM.

Create separate logging context for each transports for better
debugging.

Change-Id: If2d00966a186dc48badc8a9a2e017eec6895dcad
Signed-off-by: Arun Kumar Neelakantam <aneela@codeaurora.org>
2016-03-23 21:12:17 -07:00