From patchwork Thu Oct 3 15:51:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 175129 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp554297ill; Thu, 3 Oct 2019 09:27:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqy6Tmmp6Su6IpjYnFay89KR1kukbgpBdn/YqroG5fPSTzFXlxcIp+xfw3aG9qP9wF1wS4qC X-Received: by 2002:a50:a57d:: with SMTP id z58mr10482843edb.115.1570120073517; Thu, 03 Oct 2019 09:27:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570120073; cv=none; d=google.com; s=arc-20160816; b=fEkiHlue8LUja7bG+Eg/P6FC22UUF9vBECS02ql8SHxCXoXiKI5breltTjX24Yz8VL oEh6Uwd1kN3ZBh4X5eiR1pqfdFG5b96huxfcvMCS7VYdxAJNDaMBrhzXTQTQNAIwP4S/ t1Bpce6IHPiF0d+MtoID4ahTDhrs5hh8zZ3BhmBLaI0zq9tyvvj2oQLRLDXjd3I//T0S v3r6JnwKiLnJU2sjxR50cot1+5JeI3/YgnyyZdf1+G2AHnr/eoJy4wh8G00hlY7Rdptl m7iXx1FHhuyEpzOnJdck0KVftQ7uc7BQbIBt6Ntcn8CzK+o7xb9OCtW7iGLhxpFoyUdD K4ag== 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=QysHqyJiNaBe1m1gUMpqTANmqSNRouVizu+qOvBPryA=; b=uopiaV/h4QdjCQ6UgPNTt9udXTSzQGHPhYyH3u0T8mhQhLQ35mZrU/DGIqFYDJYzb+ 2iykq0BDR4UNKcimGj3plJ7svOdv6M54ObrJJOQ+LHk4Udkc/9yUddoa9y3TWPFDQhZX +HEQhzsbPZoGs2Wzi7I6Y99bQ13F5K2P95MYe+QWFEtpv9WHXpG5If04Gvs6IYI+o6o6 wehTsuCIntsXlQLeTqM+MYUAhcl+hYqSIqLRKYeGyE32MT37W1UXDTDmvx8Ldy7TjRm8 aHKjN4RFNeQe7jFpfEvJjSHPrcB2RJh+TqI7jeGRy8jkIq2cVsy+qbNTIu5GD+3CjMzw wLRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hfCilLsZ; 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 z10si1796653edx.168.2019.10.03.09.27.53; Thu, 03 Oct 2019 09:27:53 -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=hfCilLsZ; 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 S2391336AbfJCQ1u (ORCPT + 14 others); Thu, 3 Oct 2019 12:27:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:59992 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391330AbfJCQ1t (ORCPT ); Thu, 3 Oct 2019 12:27:49 -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 4EABB2133F; Thu, 3 Oct 2019 16:27:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570120068; bh=iupxWFpcY6/cgaLlrAWuYCcnrImMYlOV5CQiGwgF2WE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hfCilLsZ3e9kIJWIdt7dSii85vVbXL0JqMPIwg4Hdano3+lxQ3hslhIz/dE1SBeQZ Z1k3elXOM6Z4F+1SRKIaTbMcFE8dL+IUMHqkLF9Lj6B6Id1CQ8f0Ug/MVLXX1CxSWt IHSm3YjuMN7LdxQtzPmuNKFXpUnsYZmeWa9u5Pqg= 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 5.2 086/313] firmware: arm_scmi: Check if platform has released shmem before using Date: Thu, 3 Oct 2019 17:51:04 +0200 Message-Id: <20191003154541.351570368@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154533.590915454@linuxfoundation.org> References: <20191003154533.590915454@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 b5bc4c7a8fab2..b49c9e6f4bf10 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,