Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8985280ybi; Tue, 23 Jul 2019 19:29:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqzoLA7MBGrtehXmU9dS/yoFqhwCFIqSqbrs9FPU8/wKRl/WM/7WqK6Ec6hypFBySwtfPwt5 X-Received: by 2002:a17:90a:eb08:: with SMTP id j8mr49210178pjz.72.1563935379310; Tue, 23 Jul 2019 19:29:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563935379; cv=none; d=google.com; s=arc-20160816; b=TFhzW92vg0cGaPkZBqYaJd5vGzontmBHf/aONbIgJyJNswD3rWlNFAaadt3RFocYay HdxlJ3NBBcVf1QLaORrLfLoXnbfcErySIfquoxzCOdVOnMI0MqaJEsAu0bt1aruFgLG7 7+OQ9kiptVuiHeZVvOBdY/KhQ2h89vaYTqRsKLqH6/gS0XnyTi0aRUXPY1J/WNXqIa8q B8oC0zp8PEk6BV0SrD1wAIW2mmybSJ1dy5732xcMEQb/zIDoKjjgpkwtfHizzr+2o12X L8PYeo2TeOccXMZ6IE3kkWLx0ucEPGTETOxoZdjG03/BiKXH2+JrvIkHQ5ok52qAqRgl G7BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:user-agent:from:cc:to:subject :references:in-reply-to:content-transfer-encoding:mime-version :message-id:dkim-signature; bh=QbT9jGu1lmx3/9h3LW15ROrOwQXxSF86nPLyM5BLkII=; b=NS665Jaau4/Du8VUHDE5VE1mfjvpdfCT5TcxRAtUtR80om8tbWYofjne+SIUe0WPTw XijZuhdze2cwnOsI9lC/0CsunKQjSsmNFMFA1Uj+pakngJVR0Tlaje7KABCPM8GmJtj7 kMmVBzTCreHiEzLWdWnbqvbPGYPCBkX+3ltAuEEuO4lHJz7Vbkn6zpHz0AiedUGmEaDV gXGOU3tUYKcODKjV3SC8VHPfKdkn59W+t1RR1F/AKYqfMK/EnKpl+KxUO0x4PdEXR/Fy lqVJxstGNFi38MoTCspyye8w6q6JFqMAwmyl5MDlvNFb4cERzeQNLhmVhEni4aOS3XLq t5QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iTCMzgyF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d22si11132662pls.112.2019.07.23.19.29.23; Tue, 23 Jul 2019 19:29:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iTCMzgyF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730569AbfGWULN (ORCPT + 99 others); Tue, 23 Jul 2019 16:11:13 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:46489 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728447AbfGWULN (ORCPT ); Tue, 23 Jul 2019 16:11:13 -0400 Received: by mail-pl1-f196.google.com with SMTP id c2so21000105plz.13 for ; Tue, 23 Jul 2019 13:11:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=message-id:mime-version:content-transfer-encoding:in-reply-to :references:subject:to:cc:from:user-agent:date; bh=QbT9jGu1lmx3/9h3LW15ROrOwQXxSF86nPLyM5BLkII=; b=iTCMzgyFfG0OP9uRHM4PgqYmeTY0g0hC424bokI7JNfKuRDiJzS2wLzjLh0EP8I2L2 +HYLetQYiXmSxCGmJMqTzMS30qc2pCkBxCE/upXFcENcoBdrMBIIBK89qB1STSVOC3C/ MglHaKb+TPOMn6k5Rd/kcCj11LmsZAUzfaMm8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:mime-version :content-transfer-encoding:in-reply-to:references:subject:to:cc:from :user-agent:date; bh=QbT9jGu1lmx3/9h3LW15ROrOwQXxSF86nPLyM5BLkII=; b=PgQOtVyiH5ELOwd2o3ZOsOxD1BobefVgSlBoumRCLbmfb6Dw8aCYEngnoA4+6gGpBi iqvPQJ5EbpYWrpybWZdBfUacncoz3SlUK3uK/ucxvc1kXTD/h7Uhs9pM8Lu2ePfB8DGc 3UvQ/K9UBHk9pp+3/Iuh1Ae7NHmgCYQRmwd2en32Kdniym/ZkdO2XDtU1spG04qzyhVt cmKYVtBdPiB3N276xDh215gvrJB42WoR42k5HT9LtVmuZmAWjPqQ0HcT78fRfQtCZdz+ 9CnHhutDSSLF7cgI5lqC1LSJMNGASvOjuhFwrEMGj9gwab8rxF4SQHyKk9VdWVzgxOlQ vNiw== X-Gm-Message-State: APjAAAVhbNwpEKJAIOhODk4bVKR4ZQOJ/qzmMX+LziX3F3z7ZV5jfXI/ vygmMmI+QbnZCXCuDCYNb4+osA== X-Received: by 2002:a17:902:e282:: with SMTP id cf2mr83244845plb.301.1563912672555; Tue, 23 Jul 2019 13:11:12 -0700 (PDT) Received: from chromium.org ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id b136sm51971272pfb.73.2019.07.23.13.11.11 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 23 Jul 2019 13:11:11 -0700 (PDT) Message-ID: <5d3769df.1c69fb81.55d03.aa33@mx.google.com> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20190722215340.3071-2-ilina@codeaurora.org> References: <20190722215340.3071-1-ilina@codeaurora.org> <20190722215340.3071-2-ilina@codeaurora.org> Subject: Re: [PATCH V2 2/4] drivers: qcom: rpmh-rsc: avoid locking in the interrupt handler To: Lina Iyer , agross@kernel.org, bjorn.andersson@linaro.org Cc: linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, rnayak@codeaurora.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, dianders@chromium.org, mkshah@codeaurora.org, Lina Iyer From: Stephen Boyd User-Agent: alot/0.8.1 Date: Tue, 23 Jul 2019 13:11:10 -0700 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Lina Iyer (2019-07-22 14:53:38) > Avoid locking in the interrupt context to improve latency. Since we > don't lock in the interrupt context, it is possible that we now could > race with the DRV_CONTROL register that writes the enable register and > cleared by the interrupt handler. For fire-n-forget requests, the > interrupt may be raised as soon as the TCS is triggered and the IRQ > handler may clear the enable bit before the DRV_CONTROL is read back. >=20 > Use the non-sync variant when enabling the TCS register to avoid reading > back a value that may been cleared because the interrupt handler ran > immediately after triggering the TCS. >=20 > Signed-off-by: Lina Iyer > --- I have to read this patch carefully. The commit text isn't convincing me that it is actually safe to make this change. It mostly talks about the performance improvements and how we need to fix __tcs_trigger(), which is good, but I was hoping to be convinced that not grabbing the lock here is safe.=20 How do we ensure that drv->tcs_in_use is cleared before we call tcs_write() and try to look for a free bit? Isn't it possible that we'll get into a situation where the bitmap is all used up but the hardware has just received an interrupt and is going to clear out a bit and then an rpmh write fails with -EBUSY? > drivers/soc/qcom/rpmh-rsc.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) >=20 > diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c > index 5ede8d6de3ad..694ba881624e 100644 > --- a/drivers/soc/qcom/rpmh-rsc.c > +++ b/drivers/soc/qcom/rpmh-rsc.c > @@ -242,9 +242,7 @@ static irqreturn_t tcs_tx_done(int irq, void *p) > write_tcs_reg(drv, RSC_DRV_CMD_ENABLE, i, 0); > write_tcs_reg(drv, RSC_DRV_CMD_WAIT_FOR_CMPL, i, 0); > write_tcs_reg(drv, RSC_DRV_IRQ_CLEAR, 0, BIT(i)); > - spin_lock(&drv->lock); > clear_bit(i, drv->tcs_in_use); > - spin_unlock(&drv->lock); > if (req) > rpmh_tx_done(req, err); > } > @@ -304,7 +302,7 @@ static void __tcs_trigger(struct rsc_drv *drv, int tc= s_id) > enable =3D TCS_AMC_MODE_ENABLE; > write_tcs_reg_sync(drv, RSC_DRV_CONTROL, tcs_id, enable); > enable |=3D TCS_AMC_MODE_TRIGGER; > - write_tcs_reg_sync(drv, RSC_DRV_CONTROL, tcs_id, enable); > + write_tcs_reg(drv, RSC_DRV_CONTROL, tcs_id, enable); > } > =20 > static int check_for_req_inflight(struct rsc_drv *drv, struct tcs_group = *tcs,