Skip to content

Commit

Permalink
Merge tag 'rpmsg-v4.17' of git://github.com/andersson/remoteproc
Browse files Browse the repository at this point in the history
Pull rpmsg updates from Bjorn Andersson:

 - transition the rpmsg_trysend() code paths of SMD and GLINK to use
   non-sleeping locks

 - revert the overly optimistic handling of discovered SMD channels

 - fix an issue in SMD where incoming messages race with the probing of
   a client driver

* tag 'rpmsg-v4.17' of git://github.com/andersson/remoteproc:
  rpmsg: smd: Use announce_create to process any receive work
  rpmsg: Only invoke announce_create for rpdev with endpoints
  rpmsg: smd: Fix container_of macros
  Revert "rpmsg: smd: Create device for all channels"
  rpmsg: glink: Use spinlock in tx path
  rpmsg: smd: Use spinlock in tx path
  rpmsg: smd: use put_device() if device_register fail
  rpmsg: glink: use put_device() if device_register fail
  • Loading branch information
Linus Torvalds committed Apr 10, 2018
2 parents f77cfbe + 0d72038 commit 9ab89c4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 22 deletions.
18 changes: 11 additions & 7 deletions drivers/rpmsg/qcom_glink_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ struct qcom_glink {
spinlock_t rx_lock;
struct list_head rx_queue;

struct mutex tx_lock;
spinlock_t tx_lock;

spinlock_t idr_lock;
struct idr lcids;
Expand Down Expand Up @@ -288,23 +288,27 @@ static int qcom_glink_tx(struct qcom_glink *glink,
const void *data, size_t dlen, bool wait)
{
unsigned int tlen = hlen + dlen;
int ret;
unsigned long flags;
int ret = 0;

/* Reject packets that are too big */
if (tlen >= glink->tx_pipe->length)
return -EINVAL;

ret = mutex_lock_interruptible(&glink->tx_lock);
if (ret)
return ret;
spin_lock_irqsave(&glink->tx_lock, flags);

while (qcom_glink_tx_avail(glink) < tlen) {
if (!wait) {
ret = -EAGAIN;
goto out;
}

/* Wait without holding the tx_lock */
spin_unlock_irqrestore(&glink->tx_lock, flags);

usleep_range(10000, 15000);

spin_lock_irqsave(&glink->tx_lock, flags);
}

qcom_glink_tx_write(glink, hdr, hlen, data, dlen);
Expand All @@ -313,7 +317,7 @@ static int qcom_glink_tx(struct qcom_glink *glink,
mbox_client_txdone(glink->mbox_chan, 0);

out:
mutex_unlock(&glink->tx_lock);
spin_unlock_irqrestore(&glink->tx_lock, flags);

return ret;
}
Expand Down Expand Up @@ -1567,7 +1571,7 @@ struct qcom_glink *qcom_glink_native_probe(struct device *dev,
glink->features = features;
glink->intentless = intentless;

mutex_init(&glink->tx_lock);
spin_lock_init(&glink->tx_lock);
spin_lock_init(&glink->rx_lock);
INIT_LIST_HEAD(&glink->rx_queue);
INIT_WORK(&glink->rx_work, qcom_glink_work);
Expand Down
3 changes: 2 additions & 1 deletion drivers/rpmsg/qcom_glink_smem.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ struct qcom_glink *qcom_glink_smem_register(struct device *parent,
ret = device_register(dev);
if (ret) {
pr_err("failed to register glink edge\n");
put_device(dev);
return ERR_PTR(ret);
}

Expand Down Expand Up @@ -299,7 +300,7 @@ struct qcom_glink *qcom_glink_smem_register(struct device *parent,
return glink;

err_put_dev:
put_device(dev);
device_unregister(dev);

return ERR_PTR(ret);
}
Expand Down
51 changes: 38 additions & 13 deletions drivers/rpmsg/qcom_smd.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ struct qcom_smd_endpoint {
struct qcom_smd_channel *qsch;
};

#define to_smd_device(_rpdev) container_of(_rpdev, struct qcom_smd_device, rpdev)
#define to_smd_device(r) container_of(r, struct qcom_smd_device, rpdev)
#define to_smd_edge(d) container_of(d, struct qcom_smd_edge, dev)
#define to_smd_endpoint(ept) container_of(ept, struct qcom_smd_endpoint, ept)
#define to_smd_endpoint(e) container_of(e, struct qcom_smd_endpoint, ept)

/**
* struct qcom_smd_channel - smd channel struct
Expand Down Expand Up @@ -205,7 +205,7 @@ struct qcom_smd_channel {
struct smd_channel_info_pair *info;
struct smd_channel_info_word_pair *info_word;

struct mutex tx_lock;
spinlock_t tx_lock;
wait_queue_head_t fblockread_event;

void *tx_fifo;
Expand Down Expand Up @@ -729,6 +729,7 @@ static int __qcom_smd_send(struct qcom_smd_channel *channel, const void *data,
{
__le32 hdr[5] = { cpu_to_le32(len), };
int tlen = sizeof(hdr) + len;
unsigned long flags;
int ret;

/* Word aligned channels only accept word size aligned data */
Expand All @@ -739,9 +740,11 @@ static int __qcom_smd_send(struct qcom_smd_channel *channel, const void *data,
if (tlen >= channel->fifo_size)
return -EINVAL;

ret = mutex_lock_interruptible(&channel->tx_lock);
if (ret)
return ret;
/* Highlight the fact that if we enter the loop below we might sleep */
if (wait)
might_sleep();

spin_lock_irqsave(&channel->tx_lock, flags);

while (qcom_smd_get_tx_avail(channel) < tlen &&
channel->state == SMD_CHANNEL_OPENED) {
Expand All @@ -753,17 +756,15 @@ static int __qcom_smd_send(struct qcom_smd_channel *channel, const void *data,
SET_TX_CHANNEL_FLAG(channel, fBLOCKREADINTR, 0);

/* Wait without holding the tx_lock */
mutex_unlock(&channel->tx_lock);
spin_unlock_irqrestore(&channel->tx_lock, flags);

ret = wait_event_interruptible(channel->fblockread_event,
qcom_smd_get_tx_avail(channel) >= tlen ||
channel->state != SMD_CHANNEL_OPENED);
if (ret)
return ret;

ret = mutex_lock_interruptible(&channel->tx_lock);
if (ret)
return ret;
spin_lock_irqsave(&channel->tx_lock, flags);

SET_TX_CHANNEL_FLAG(channel, fBLOCKREADINTR, 1);
}
Expand All @@ -787,7 +788,7 @@ static int __qcom_smd_send(struct qcom_smd_channel *channel, const void *data,
qcom_smd_signal_channel(channel);

out_unlock:
mutex_unlock(&channel->tx_lock);
spin_unlock_irqrestore(&channel->tx_lock, flags);

return ret;
}
Expand Down Expand Up @@ -996,8 +997,26 @@ static struct device_node *qcom_smd_match_channel(struct device_node *edge_node,
return NULL;
}

static int qcom_smd_announce_create(struct rpmsg_device *rpdev)
{
struct qcom_smd_endpoint *qept = to_smd_endpoint(rpdev->ept);
struct qcom_smd_channel *channel = qept->qsch;
unsigned long flags;
bool kick_state;

spin_lock_irqsave(&channel->recv_lock, flags);
kick_state = qcom_smd_channel_intr(channel);
spin_unlock_irqrestore(&channel->recv_lock, flags);

if (kick_state)
schedule_work(&channel->edge->state_work);

return 0;
}

static const struct rpmsg_device_ops qcom_smd_device_ops = {
.create_ept = qcom_smd_create_ept,
.announce_create = qcom_smd_announce_create,
};

static const struct rpmsg_endpoint_ops qcom_smd_endpoint_ops = {
Expand Down Expand Up @@ -1090,7 +1109,7 @@ static struct qcom_smd_channel *qcom_smd_create_channel(struct qcom_smd_edge *ed
if (!channel->name)
return ERR_PTR(-ENOMEM);

mutex_init(&channel->tx_lock);
spin_lock_init(&channel->tx_lock);
spin_lock_init(&channel->recv_lock);
init_waitqueue_head(&channel->fblockread_event);
init_waitqueue_head(&channel->state_change_event);
Expand Down Expand Up @@ -1234,6 +1253,11 @@ static void qcom_channel_state_worker(struct work_struct *work)
if (channel->state != SMD_CHANNEL_CLOSED)
continue;

remote_state = GET_RX_CHANNEL_INFO(channel, state);
if (remote_state != SMD_CHANNEL_OPENING &&
remote_state != SMD_CHANNEL_OPENED)
continue;

if (channel->registered)
continue;

Expand Down Expand Up @@ -1408,6 +1432,7 @@ struct qcom_smd_edge *qcom_smd_register_edge(struct device *parent,
ret = device_register(&edge->dev);
if (ret) {
pr_err("failed to register smd edge\n");
put_device(&edge->dev);
return ERR_PTR(ret);
}

Expand All @@ -1428,7 +1453,7 @@ struct qcom_smd_edge *qcom_smd_register_edge(struct device *parent,
return edge;

unregister_dev:
put_device(&edge->dev);
device_unregister(&edge->dev);
return ERR_PTR(ret);
}
EXPORT_SYMBOL(qcom_smd_register_edge);
Expand Down
2 changes: 1 addition & 1 deletion drivers/rpmsg/rpmsg_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ static int rpmsg_dev_probe(struct device *dev)
goto out;
}

if (rpdev->ops->announce_create)
if (ept && rpdev->ops->announce_create)
err = rpdev->ops->announce_create(rpdev);
out:
return err;
Expand Down

0 comments on commit 9ab89c4

Please sign in to comment.