From patchwork Tue Feb 13 19:04:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 128289 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp4569780ljc; Tue, 13 Feb 2018 11:09:31 -0800 (PST) X-Google-Smtp-Source: AH8x2247CBK9ekxGKfHF5LMd8c2+SR6qjBMFR0iDTp2MdZ4anfyC0Rb9Poo2eivPSTYWn9chwVKZ X-Received: by 2002:a17:902:28c4:: with SMTP id f62-v6mr2011716plb.31.1518548971788; Tue, 13 Feb 2018 11:09:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518548971; cv=none; d=google.com; s=arc-20160816; b=g4fhu8l3Sj2/hCo2/X9RAKwDV4VRUs9osglYtkIltPa3i1ff1C/baOkqP51XuKXTTN uEOnrf4LZNflKWVsifG1dZB9BEY+WD6AYi8VEX24EMY/mgTusT7FLeKVUyREc7f5RpJm qEmL3KEyhLfg12cq3nkKZD2TV6TwVkh3zCH/FAoQrZEh41BOcj3YQJ9kPyW/MUMt7kjT bwuz9UT7CC+7oGlaM5Oo3O2gYPtSs2JhgrCDDd+ewyBOlz+FZwCOm8DqklzMFYuGE2Z5 42N72O19+R8eKLb4TgiCJ0/bL80sTuNS50WB0/dqRw+A0x8sgyEt3j7hiQVU6Gj2vDav bLog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=q15zDVZDEcq8jGKfrcIHGCnCxhC4SGVl71b0ktaemIc=; b=0ZKK0MGtcR0q5tDtfCNNXsJHXE8IV57rIPUOL1hUDH6bSDA4d7Ri7kt4rLnIrOHk9+ sLsV/gslnpwrNrXja6mNRVwcsms9HILfu01LHd3E9LLN97TmSXdqhmw6jaEaJ4m5O52w NYclgCVFzmghwV1H0abnA5sGl2O4UZEVpZoR7rNhYwZzB+e0J/uaC42iEZn/916YU5q5 JzP6S8HHC6kI1KN7AAQ8mmF2wSEC+p3nV9AXuHlJdaugj2xHIldlFaLKj/uQxP3bIrtj MCDN3l7Mx8jhHHa87L3N4Uv9lEIpPGuSbkXZ0HSXYaHRGRRfOt5KKnKZBvgSGbsgWkom nbmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=UwaL9qis; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s21si939877pfm.325.2018.02.13.11.09.31; Tue, 13 Feb 2018 11:09:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=UwaL9qis; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752344AbeBMTJ3 (ORCPT + 10 others); Tue, 13 Feb 2018 14:09:29 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:36622 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751819AbeBMTJ3 (ORCPT ); Tue, 13 Feb 2018 14:09:29 -0500 Received: by mail-pl0-f68.google.com with SMTP id v3so7097167plg.3 for ; Tue, 13 Feb 2018 11:09:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=7QK4hR5NBH5x4HUNgAw95Eh+3ZnkkXkhTr46j0e2tnk=; b=UwaL9qisxSClsCMrpXETp7IP7IhHGPzHHZnGxRsXy7pIcrSeQAt8AWNGJEFu4HAJ5I qzEo5IaDrqiIepxBQs7OLTWsHTic3EcEHuLfDFnrXBiwD1aEaXAyO+79T4Rq4oIUL3Hi drxTw4AbjfMeyIMVoN0VVYOCgdCE59GdPsEeM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=7QK4hR5NBH5x4HUNgAw95Eh+3ZnkkXkhTr46j0e2tnk=; b=aEQ4BrpaqL8u88tOgQrWWfarFQhMrFLCb0viDq11gHr63qeHFITlL3b5mG1YSkF1O5 IZV22v9emq5qMg/n+Ok2pMkt7aTGOdkTwgbgf7jBgU03+JkvE+OLUYFK6OuG4DqS2pCn LWwq4aSS7NLY+7XCD6NyU/2WEMEdcuS7kht3/8ddspMriW1G7QeLCdoARANxcNazwo+E /a2PbEJWdmI8Iyg33dzmswFEcfZV1i8CdDCBN7jtC7U2SUXwHgxjXSL7ExFrCIvEPEZK P8hNOefwswzG+/XGJ2msLqEe3CizGBwI6JV4YkEJSmUgPLp/kqH4TsbpHdRa/5xuYTVV kaqw== X-Gm-Message-State: APf1xPDbs+Pozixh9Co/LntdtQSvnDMwwE6XHRqH8YWMjLQpT5hbaMfO 2wTg78eXpvZEHvk+mrMDY0Lz1w== X-Received: by 2002:a17:902:22e:: with SMTP id 43-v6mr2073576plc.384.1518548654299; Tue, 13 Feb 2018 11:04:14 -0800 (PST) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id n25sm31708509pfk.152.2018.02.13.11.04.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Feb 2018 11:04:13 -0800 (PST) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson , Chris Lew , Arun Kumar Neelakantam , Srini Kandagatla Cc: linux-remoteproc@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] rpmsg: smd: Use spinlock in tx path Date: Tue, 13 Feb 2018 11:04:11 -0800 Message-Id: <20180213190411.25076-1-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.15.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org By switching the tx_lock to a spinlock we allow clients to use rpmsg_trysend() from atomic context. The mutex was interruptable as it was previously held for the duration of some client waiting for available space in the FIFO, but this was recently changed to only be held temporarily - allowing us to replace it with a spinlock. Signed-off-by: Bjorn Andersson --- drivers/rpmsg/qcom_smd.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) -- 2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/rpmsg/qcom_smd.c b/drivers/rpmsg/qcom_smd.c index 92d0c6a7a837..1066ee48420f 100644 --- a/drivers/rpmsg/qcom_smd.c +++ b/drivers/rpmsg/qcom_smd.c @@ -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; @@ -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 */ @@ -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) { @@ -753,7 +756,7 @@ 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 || @@ -761,9 +764,7 @@ static int __qcom_smd_send(struct qcom_smd_channel *channel, const void *data, 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); } @@ -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; } @@ -1090,7 +1091,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);