[5/6] rpmsg: glink: Fail qcom_glink_tx() once remove has been initiated
Commit Message
Upon removing the glink edge communication is at best one-way. This
means that the very common scenario of glink requesting intents will not
be possible to serve.
Typically a successful transmission results in the client waiting for a
response, with some timeout and a mechanism for aborting that timeout.
Because of this, once the glink edge is defunct once removal is
commenced it's better to fail transmissions fast.
Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>
---
drivers/rpmsg/qcom_glink_native.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
Comments
On 1/9/2023 2:40 PM, Bjorn Andersson wrote:
> Upon removing the glink edge communication is at best one-way. This
glink edge, communication
> means that the very common scenario of glink requesting intents will not
> be possible to serve.
>
> Typically a successful transmission results in the client waiting for a
> response, with some timeout and a mechanism for aborting that timeout.
>
> Because of this, once the glink edge is defunct once removal is
> commenced it's better to fail transmissions fast.
>
> Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>
> ---
Reviewed-by: Chris Lew <quic_clew@quicinc.com>
> drivers/rpmsg/qcom_glink_native.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c
> index db5d946d5901..d81d0729493e 100644
> --- a/drivers/rpmsg/qcom_glink_native.c
> +++ b/drivers/rpmsg/qcom_glink_native.c
> @@ -90,6 +90,7 @@ struct glink_core_rx_intent {
> * @intentless: flag to indicate that there is no intent
> * @tx_avail_notify: Waitqueue for pending tx tasks
> * @sent_read_notify: flag to check cmd sent or not
> + * @abort_tx: flag indicating that all tx attempts should fail
> */
> struct qcom_glink {
> struct device *dev;
> @@ -111,6 +112,8 @@ struct qcom_glink {
> bool intentless;
> wait_queue_head_t tx_avail_notify;
> bool sent_read_notify;
> +
> + bool abort_tx;
> };
>
> enum {
> @@ -326,12 +329,22 @@ static int qcom_glink_tx(struct qcom_glink *glink,
>
> spin_lock_irqsave(&glink->tx_lock, flags);
>
> + if (glink->abort_tx) {
> + ret = -EIO;
> + goto out;
> + }
> +
> while (qcom_glink_tx_avail(glink) < tlen) {
> if (!wait) {
> ret = -EAGAIN;
> goto out;
> }
>
> + if (glink->abort_tx) {
> + ret = -EIO;
> + goto out;
> + }
> +
> if (!glink->sent_read_notify) {
> glink->sent_read_notify = true;
> qcom_glink_send_read_notify(glink);
> @@ -1763,11 +1776,18 @@ static int qcom_glink_remove_device(struct device *dev, void *data)
> void qcom_glink_native_remove(struct qcom_glink *glink)
> {
> struct glink_channel *channel;
> + unsigned long flags;
> int cid;
> int ret;
>
> qcom_glink_cancel_rx_work(glink);
>
> + /* Fail all attempts at sending messages */
> + spin_lock_irqsave(&glink->tx_lock, flags);
> + glink->abort_tx = true;
> + wake_up_all(&glink->tx_avail_notify);
> + spin_unlock_irqrestore(&glink->tx_lock, flags);
> +
> ret = device_for_each_child(glink->dev, NULL, qcom_glink_remove_device);
> if (ret)
> dev_warn(glink->dev, "Can't remove GLINK devices: %d\n", ret);
@@ -90,6 +90,7 @@ struct glink_core_rx_intent {
* @intentless: flag to indicate that there is no intent
* @tx_avail_notify: Waitqueue for pending tx tasks
* @sent_read_notify: flag to check cmd sent or not
+ * @abort_tx: flag indicating that all tx attempts should fail
*/
struct qcom_glink {
struct device *dev;
@@ -111,6 +112,8 @@ struct qcom_glink {
bool intentless;
wait_queue_head_t tx_avail_notify;
bool sent_read_notify;
+
+ bool abort_tx;
};
enum {
@@ -326,12 +329,22 @@ static int qcom_glink_tx(struct qcom_glink *glink,
spin_lock_irqsave(&glink->tx_lock, flags);
+ if (glink->abort_tx) {
+ ret = -EIO;
+ goto out;
+ }
+
while (qcom_glink_tx_avail(glink) < tlen) {
if (!wait) {
ret = -EAGAIN;
goto out;
}
+ if (glink->abort_tx) {
+ ret = -EIO;
+ goto out;
+ }
+
if (!glink->sent_read_notify) {
glink->sent_read_notify = true;
qcom_glink_send_read_notify(glink);
@@ -1763,11 +1776,18 @@ static int qcom_glink_remove_device(struct device *dev, void *data)
void qcom_glink_native_remove(struct qcom_glink *glink)
{
struct glink_channel *channel;
+ unsigned long flags;
int cid;
int ret;
qcom_glink_cancel_rx_work(glink);
+ /* Fail all attempts at sending messages */
+ spin_lock_irqsave(&glink->tx_lock, flags);
+ glink->abort_tx = true;
+ wake_up_all(&glink->tx_avail_notify);
+ spin_unlock_irqrestore(&glink->tx_lock, flags);
+
ret = device_for_each_child(glink->dev, NULL, qcom_glink_remove_device);
if (ret)
dev_warn(glink->dev, "Can't remove GLINK devices: %d\n", ret);