From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DCDFC4338F for ; Wed, 28 Jul 2021 08:31:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0691360FD8 for ; Wed, 28 Jul 2021 08:31:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234574AbhG1Ibd (ORCPT ); Wed, 28 Jul 2021 04:31:33 -0400 Received: from foss.arm.com ([217.140.110.172]:52658 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234311AbhG1Ibb (ORCPT ); Wed, 28 Jul 2021 04:31:31 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8B2FD1FB; Wed, 28 Jul 2021 01:31:30 -0700 (PDT) Received: from e120937-lin (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BD8AC3F73D; Wed, 28 Jul 2021 01:31:27 -0700 (PDT) Date: Wed, 28 Jul 2021 09:31:25 +0100 From: Cristian Marussi To: Peter Hilber Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, virtualization@lists.linux-foundation.org, virtio-dev@lists.oasis-open.org, sudeep.holla@arm.com, james.quinlan@broadcom.com, Jonathan.Cameron@Huawei.com, f.fainelli@gmail.com, etienne.carriere@linaro.org, vincent.guittot@linaro.org, souvik.chakravarty@arm.com, igor.skalkin@opensynergy.com, alex.bennee@linaro.org, jean-philippe@linaro.org, mikhail.golubev@opensynergy.com, anton.yakovlev@opensynergy.com, Vasyl.Vavrychuk@opensynergy.com, Andriy.Tryshnivskyy@opensynergy.com Subject: Re: [PATCH v6 07/17] firmware: arm_scmi: Handle concurrent and out-of-order messages Message-ID: <20210728083125.GJ49078@e120937-lin> References: <20210712141833.6628-1-cristian.marussi@arm.com> <20210712141833.6628-8-cristian.marussi@arm.com> <20210719091451.GF49078@e120937-lin> <85868de4-54bf-cca8-3786-61a404b80117@opensynergy.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <85868de4-54bf-cca8-3786-61a404b80117@opensynergy.com> User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 22, 2021 at 10:32:58AM +0200, Peter Hilber wrote: > On 19.07.21 11:14, Cristian Marussi wrote: > > On Thu, Jul 15, 2021 at 06:36:03PM +0200, Peter Hilber wrote: > > > On 12.07.21 16:18, Cristian Marussi wrote: > > [snip] > > > > > @@ -608,6 +755,7 @@ static int do_xfer(const struct scmi_protocol_handle *ph, > > > > xfer->hdr.protocol_id, xfer->hdr.seq, > > > > xfer->hdr.poll_completion); > > > > + xfer->state = SCMI_XFER_SENT_OK; > > > > > > To be completely safe, this assignment could also be protected by the > > > xfer->lock. > > > > > > > In fact this would be true being xfer->lock meant to protect the state but it > > seemed to me unnecessary here given that this is a brand new xfer with a > > brand new (monotonic) seq number so that any possibly late-received msg will > > carry an old stale seq number certainly different from this such that cannot be > > possibly mapped to this same xfer. (but just discarded on xfer lookup in > > xfer_command_acquire) > > > > The issue indeed could still exist only for do_xfer loops (as you pointed out > > already early on) where the seq_num is used, but in that case on a timeout we > > would have already bailed out of the loop and reported an error so any timed-out > > late received response would have been anyway discarded; so at the end I thought > > I could avoid spinlocking here. > > > > Thanks, > > Cristian > > Hi Peter, sorry for the late answer. > > I mostly meant to refer to the possibility of a very fast response not > seeing this assignment, since the next line is > > > ret = info->desc->ops->send_message(cinfo, xfer); > > and during that a regular scmi_rx_callback(), reading xfer->state, can > already arrive. But maybe this is too theoretical. > Right, that's a possibility indeed to account for even if remote: given that, though, no race is possible here on state as said, I'd still avoid the spinlock and related irq-off and opt instead for a barrier to avoid re-ordering and to be sure that the scmi_rx_callback() on the RX processor can see the latest value (a dmb(ish) + cache coherence magic should be enough) Thanks, Cristian From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CA2EC4338F for ; Wed, 28 Jul 2021 08:33:47 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4DDEB60FD8 for ; Wed, 28 Jul 2021 08:33:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4DDEB60FD8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=06HU+G2bhZJT4JtjfM3l1s5DRFzTl9m9gbabcn0Tp6I=; b=Op0xwfQHcWbSRj lDFcKm5lEyI3Weo8Sr6zmHqMk309BrwtIvyawIrXJf48dFOWoSJGks+EntLakvtpmZcuw4hn/u64R AZffIuORFfBb83QTOj0YSfnYJrel1G+fKEux3Q6yIASrxFjObZiS34qWFUa40TAuxZMgChvVzOxqi rg2SWkgFvgCjjrcpdSC0xyFzvpcz8SlBHgug+84x8LPN2oDHR8jotvPkiES4/DouKBM/MsnMIREqC BllirVqzFHaJXBgdb3AayKoC2jtFjt9N8F27BeYYCmMU7y4AfVePEcw0EtDChp3DkqXDpJeIkCvMD ichZgF2aNfCGodMhGItg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8eyY-00HZ49-Uf; Wed, 28 Jul 2021 08:31:39 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8eyW-00HZ2w-0p for linux-arm-kernel@lists.infradead.org; Wed, 28 Jul 2021 08:31:37 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8B2FD1FB; Wed, 28 Jul 2021 01:31:30 -0700 (PDT) Received: from e120937-lin (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BD8AC3F73D; Wed, 28 Jul 2021 01:31:27 -0700 (PDT) Date: Wed, 28 Jul 2021 09:31:25 +0100 From: Cristian Marussi To: Peter Hilber Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, virtualization@lists.linux-foundation.org, virtio-dev@lists.oasis-open.org, sudeep.holla@arm.com, james.quinlan@broadcom.com, Jonathan.Cameron@Huawei.com, f.fainelli@gmail.com, etienne.carriere@linaro.org, vincent.guittot@linaro.org, souvik.chakravarty@arm.com, igor.skalkin@opensynergy.com, alex.bennee@linaro.org, jean-philippe@linaro.org, mikhail.golubev@opensynergy.com, anton.yakovlev@opensynergy.com, Vasyl.Vavrychuk@opensynergy.com, Andriy.Tryshnivskyy@opensynergy.com Subject: Re: [PATCH v6 07/17] firmware: arm_scmi: Handle concurrent and out-of-order messages Message-ID: <20210728083125.GJ49078@e120937-lin> References: <20210712141833.6628-1-cristian.marussi@arm.com> <20210712141833.6628-8-cristian.marussi@arm.com> <20210719091451.GF49078@e120937-lin> <85868de4-54bf-cca8-3786-61a404b80117@opensynergy.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <85868de4-54bf-cca8-3786-61a404b80117@opensynergy.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210728_013136_133646_C5CC9F93 X-CRM114-Status: GOOD ( 22.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Jul 22, 2021 at 10:32:58AM +0200, Peter Hilber wrote: > On 19.07.21 11:14, Cristian Marussi wrote: > > On Thu, Jul 15, 2021 at 06:36:03PM +0200, Peter Hilber wrote: > > > On 12.07.21 16:18, Cristian Marussi wrote: > > [snip] > > > > > @@ -608,6 +755,7 @@ static int do_xfer(const struct scmi_protocol_handle *ph, > > > > xfer->hdr.protocol_id, xfer->hdr.seq, > > > > xfer->hdr.poll_completion); > > > > + xfer->state = SCMI_XFER_SENT_OK; > > > > > > To be completely safe, this assignment could also be protected by the > > > xfer->lock. > > > > > > > In fact this would be true being xfer->lock meant to protect the state but it > > seemed to me unnecessary here given that this is a brand new xfer with a > > brand new (monotonic) seq number so that any possibly late-received msg will > > carry an old stale seq number certainly different from this such that cannot be > > possibly mapped to this same xfer. (but just discarded on xfer lookup in > > xfer_command_acquire) > > > > The issue indeed could still exist only for do_xfer loops (as you pointed out > > already early on) where the seq_num is used, but in that case on a timeout we > > would have already bailed out of the loop and reported an error so any timed-out > > late received response would have been anyway discarded; so at the end I thought > > I could avoid spinlocking here. > > > > Thanks, > > Cristian > > Hi Peter, sorry for the late answer. > > I mostly meant to refer to the possibility of a very fast response not > seeing this assignment, since the next line is > > > ret = info->desc->ops->send_message(cinfo, xfer); > > and during that a regular scmi_rx_callback(), reading xfer->state, can > already arrive. But maybe this is too theoretical. > Right, that's a possibility indeed to account for even if remote: given that, though, no race is possible here on state as said, I'd still avoid the spinlock and related irq-off and opt instead for a barrier to avoid re-ordering and to be sure that the scmi_rx_callback() on the RX processor can see the latest value (a dmb(ish) + cache coherence magic should be enough) Thanks, Cristian _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel