From patchwork Thu Oct 3 15:52:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 175112 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp540244ill; Thu, 3 Oct 2019 09:17:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqylQa/P0GRfxo35j3kcUPMVxUvRf52Qbkb6vURQJS+soyxaq6IjZtJnW7m20anYFLu67LZL X-Received: by 2002:a17:906:828c:: with SMTP id h12mr8466188ejx.155.1570119441096; Thu, 03 Oct 2019 09:17:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570119441; cv=none; d=google.com; s=arc-20160816; b=lyub1V/MgtJmEnGYtV/2tyTMrCZZuHeejsBiydqmU84A03V49u3wYEO3jhCjkGvGJr KOFAfHyzINYqHT1I3vFN7BLD4ogPxAdMZbSw3wu5ip+2tCF5N4xng56jOAGN+eHtD/oS gCcBT5wMcEurEnlQ9vNupeDlMSrp+A46JBGPOscyMAe3rSHgCFYNnYwJJQFwGZS9W8cL cZU40SscWhFaCJMpxKPc0FPdo1RoJ5UgdQGaUMxUjZ7rz0ZFwcOAUpFeFyl+FTeTE0mW pQiDXV9l2gb713BbEXVCW/OMI8eNVbl0J6fjkjbOLZAosE97BbEOm2e8lNlzaXnDoIYv QZ0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Qrq66J2UiLjPgoxZGtd/ihjJBmHxOxsotE9335B0LJs=; b=k1+G/C1xQzphc2uwNzJgIkiNeoOXropDCu45HJ8nb6QiBKDxF0srnZRbICzrxZejLS sajaodHPTlT6beTZyCpGz3iiHWw9OlNDd3LXQ6HZGEYsMA/cTeinSPS2joLMYXgklTeC ysYlgs7hDA8JVN3WTyC65845uTxXHfvPny/rVh2N5JUYf2wcA6VYhUdtQiodIezWcVn8 bviao8EF+Hz4MlusTVefDTyhzNvpWtsIHTONV0ols6JKDGPnLTIe5dTThstFev67ZjvK MxDqW1M8pB80E7qv/9jN/29iIm/WQg7gg0Mkhv9LomQFq1A2ajCus0mIh/zAG8Nj0Fgq dlwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XjOPlZcT; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 d26si1686202edq.91.2019.10.03.09.17.20; Thu, 03 Oct 2019 09:17:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@kernel.org header.s=default header.b=XjOPlZcT; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732422AbfJCQRR (ORCPT + 14 others); Thu, 3 Oct 2019 12:17:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:42910 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389205AbfJCQRR (ORCPT ); Thu, 3 Oct 2019 12:17:17 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0F7B320700; Thu, 3 Oct 2019 16:17:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570119436; bh=Oh+7ZXgLTx07OWwHyaxKMRlgpijwLPFXyLLpXRu+Qls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XjOPlZcT6E21D6T99/2ymp2LaxC+TMlDCi1q4itAHYnMCnBNmybFNuTbgkoe4JlYO etznXaQXurRKBKTLnAZaFGw8B/k/o7Oqt9MnWU309uGpE1Fc4bms9NSUxFC3BNCdft bba0ZSSqaQGIqn4eBM6kXpmM9TbkEPAx8M9w9fa4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jim Quinlan , Sudeep Holla , Sasha Levin Subject: [PATCH 4.19 063/211] firmware: arm_scmi: Check if platform has released shmem before using Date: Thu, 3 Oct 2019 17:52:09 +0200 Message-Id: <20191003154502.983205965@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154447.010950442@linuxfoundation.org> References: <20191003154447.010950442@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Sudeep Holla [ Upstream commit 9dc34d635c67e57051853855c43249408641a5ab ] 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 Signed-off-by: Sasha Levin --- drivers/firmware/arm_scmi/driver.c | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.20.1 diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 8f952f2f1a292..09119e3f5c018 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -271,6 +271,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 its response with new message 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,