From patchwork Fri Jul 26 13:45:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 169831 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp83764ilk; Fri, 26 Jul 2019 06:46:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxOUxFTg1kwJnUtyFuJA7XYvNIVmMP7JYVSS2SL4U2Jj+NJLWVGHPO7LWZPIVhcCFHQapwZ X-Received: by 2002:aa7:8218:: with SMTP id k24mr21515079pfi.221.1564148792865; Fri, 26 Jul 2019 06:46:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564148792; cv=none; d=google.com; s=arc-20160816; b=IR+LX4TmvZIEd480clM6TBziZ8vyorGY58yH2JqMFSKP1pwvRTeCGJSNKbCAeIPE2e VGfl0CciUakuIqD7/sPPKrDK1rwzyKGkvdbTRtsdNmecyYloGEcSyv7UVK/Lr4+IUvSw dcs3H7xprH5czIFBPen7/5pTcRINMYlL4xa1mAxpcM8iLqrYQNSpyVaDD637ucmXVEb1 SURWGhwGjfCJTvyqWElmrsQnaWScrV/sygm//yecVS1enY8/T1wfWM+nnObS77Nx0zmY scwZzgaSljiarlLZkwLLv4hojwVU+E8/1K41TYy68uw0G3wnh7t+8qvuHCfBQsUxF0sS 0kTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=X1ffVu6Vb8FU1aen0pD8PW3t8MRrTZq2juCamyoHnXM=; b=TyM9KcoatlnWAokf11gehhu74xeTwdNakOESpWHK/Jjd21SgNBatgPSVFguhSDLqUk puyvZbKoKlVSPFiE8Nf0wTwvCyCgzdsFemKEQXYUNz2r+QR7XVtkdN0Q/9bJ8aNbYyoG PPxNtNCIxk/yJ8D2oqUYv/SZKfSuVAgiOTrmHFphWABOj5+NwFuMQAoY3s83Tsj+mkcH 0wiEftfhGAT1rpPNCGliVb7D4wr0pnXHsuLxmRw6tLqxvgTXVdUxNc8hacFPMl4eUL1Q ri9JyQrOLiOlqsUxSK/SxKtMv8FVcB3TbMfSM1EGGzoDtKP0SrGN44FVRdQyl9MNDdJa ojgQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e62si22998711pfh.254.2019.07.26.06.46.32; Fri, 26 Jul 2019 06:46:32 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388719AbfGZNqb (ORCPT + 29 others); Fri, 26 Jul 2019 09:46:31 -0400 Received: from foss.arm.com ([217.140.110.172]:44088 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388664AbfGZNqN (ORCPT ); Fri, 26 Jul 2019 09:46:13 -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 E3AE8152D; Fri, 26 Jul 2019 06:46:12 -0700 (PDT) Received: from usa.arm.com (e107155-lin.cambridge.arm.com [10.1.196.42]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id ABB1D3F694; Fri, 26 Jul 2019 06:46:11 -0700 (PDT) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org Cc: Sudeep Holla , Peng Fan , linux-kernel@vger.kernel.org, Bo Zhang , Jim Quinlan , Volodymyr Babchuk , Gaku Inami , Etienne Carriere Subject: [PATCH v2 6/6] firmware: arm_scmi: Check if platform has released shmem before using Date: Fri, 26 Jul 2019 14:45:31 +0100 Message-Id: <20190726134531.8928-7-sudeep.holla@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190726134531.8928-1-sudeep.holla@arm.com> References: <20190726134531.8928-1-sudeep.holla@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sometimes platfom may take too long to respond to the command and OS might timeout before platform transfer the ownership of the shared memory region to the OS with the response. Since the mailbox channel associated with the channel is freed and new commands are dispatch on the same channel, OS needs to wait until it gets back the ownership. If not, either OS may end up overwriting the platform response for the last command(which is fine as OS timed out that command) or platform might overwrite the payload for the next command with the response for the old. The latter is problematic as platform may end up interpretting the response as the payload. In order to avoid such race, let's wait until the OS gets back the ownership before we prepare the shared memory with the payload for the next command. Reported-by: Jim Quinlan Signed-off-by: Sudeep Holla --- drivers/firmware/arm_scmi/driver.c | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.17.1 diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 69bf85fea967..765573756987 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -265,6 +265,14 @@ static void scmi_tx_prepare(struct mbox_client *cl, void *m) struct scmi_chan_info *cinfo = client_to_scmi_chan_info(cl); struct scmi_shared_mem __iomem *mem = cinfo->payload; + /* + * Ideally channel must be free by now unless OS timeout last + * request and platform continued to process the same, wait + * until it releases the shared memory, otherwise we may endup + * overwriting it's response with new command payload or vice-versa + */ + spin_until_cond(ioread32(&mem->channel_status) & + SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE); /* Mark channel busy + clear error */ iowrite32(0x0, &mem->channel_status); iowrite32(t->hdr.poll_completion ? 0 : SCMI_SHMEM_FLAG_INTR_ENABLED,