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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 619F4C433EF for ; Fri, 17 Jun 2022 11:20:27 +0000 (UTC) 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=xp+Z27j+oUp3ITe9sWqxvq+g/dxWcR5ycfz7h5nhBvY=; b=ZRfWI5Y7etW8bo FbZa2NoSDr8qv4bUF8cJw0jQ6FE4fIiHvltY9p3Eurbj7aITM/2wK9juD7OlkArtExDQoDnAaBQzD XO7sx4NsbWaEl+AJU1YuBXrkdOR/PDLLQWUg9D9gEqQCYk8TIBKzfMelZdIL933BYxKWW/apLTpBT jGE4+VKlHODR5YDNpFA0o/M96YFSK0cfKs/SnckE1rPFxgJ37NPlBqSyPkT2e6IY+t5via4ufqfDQ wQY3/q/xLe2xo4lzbWEr4PzdHcqJseX+RJDdFeWpNEASMYaiKSWBBn7Oary4M6df0604ObPEtRmdr SNHsIuvn6RqIUuPy6VEw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o2A0Q-007HFO-Di; Fri, 17 Jun 2022 11:19:15 +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 1o29uL-007Epd-Cu for linux-arm-kernel@lists.infradead.org; Fri, 17 Jun 2022 11:13:00 +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 97581113E; Fri, 17 Jun 2022 04:12:52 -0700 (PDT) Received: from e120937-lin (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7371A3F73B; Fri, 17 Jun 2022 04:12:51 -0700 (PDT) Date: Fri, 17 Jun 2022 12:12:45 +0100 From: Cristian Marussi To: Robin Murphy Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, sudeep.holla@arm.com, nicola.mazzucato@arm.com, vincent.guittot@linaro.org, f.fainelli@gmail.com Subject: Re: [PATCH] firmware: arm_scmi: Relax CLOCK_DESCRIBE_RATES out-of-spec checks Message-ID: References: <20220616170347.2800771-1-cristian.marussi@arm.com> <5fa97307-19d7-a834-dbb9-c7001969a011@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5fa97307-19d7-a834-dbb9-c7001969a011@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220617_041257_647674_5A6F29E4 X-CRM114-Status: GOOD ( 30.68 ) 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, Jun 16, 2022 at 07:02:49PM +0100, Robin Murphy wrote: > On 2022-06-16 18:03, Cristian Marussi wrote: > > A reply to CLOCK_DESCRIBE_RATES issued against a non rate-discrete clock > > should be composed of a triplet of rates descriptors (min/max/step) > > returned all in one reply message. > > > > This is not always the case when dealing with some SCMI server deployed in > > the wild: relax such constraint while maintaining memory safety by checking > > carefully the returned payload size. > > > > While at that cleanup a stale debug printout. > > I know we're testing on the same platform so it's of limited value, but for > the record this does indeed make my display work again, so FWIW: > > Tested-by: Robin Murphy > > Thanks for the quick turnaround! > Robin. > Thanks Robin. Testing is never enough :P Thanks, Cristian > > Fixes: 7bc7caafe6b1 ("firmware: arm_scmi: Use common iterators in the clock protocol") > > Signed-off-by: Cristian Marussi > > --- > > drivers/firmware/arm_scmi/clock.c | 26 +++++++++++++++++++++++++- > > drivers/firmware/arm_scmi/driver.c | 1 + > > drivers/firmware/arm_scmi/protocols.h | 3 +++ > > 3 files changed, 29 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/clock.c > > index c7a83f6e38e5..3ed7ae0d6781 100644 > > --- a/drivers/firmware/arm_scmi/clock.c > > +++ b/drivers/firmware/arm_scmi/clock.c > > @@ -194,6 +194,7 @@ static int rate_cmp_func(const void *_r1, const void *_r2) > > } > > struct scmi_clk_ipriv { > > + struct device *dev; > > u32 clk_id; > > struct scmi_clock_info *clk; > > }; > > @@ -223,6 +224,29 @@ iter_clk_describe_update_state(struct scmi_iterator_state *st, > > st->num_returned = NUM_RETURNED(flags); > > p->clk->rate_discrete = RATE_DISCRETE(flags); > > + /* Warn about out of spec replies ... */ > > + if (!p->clk->rate_discrete && > > + (st->num_returned != 3 || st->num_remaining != 0)) { > > + dev_warn(p->dev, > > + "Out-of-spec CLOCK_DESCRIBE_RATES reply for %s - returned:%d remaining:%d rx_len:%zd\n", > > + p->clk->name, st->num_returned, st->num_remaining, > > + st->rx_len); > > + > > + /* > > + * A known quirk: a triplet is returned but num_returned != 3 > > + * Check for a safe payload size and fix. > > + */ > > + if (st->num_returned != 3 && st->num_remaining == 0 && > > + st->rx_len == sizeof(*r) + sizeof(__le32) * 2 * 3) { > > + st->num_returned = 3; > > + st->num_remaining = 0; > > + } else { > > + dev_err(p->dev, > > + "Cannot fix out-of-spec reply !\n"); > > + return -EPROTO; > > + } > > + } > > + > > return 0; > > } > > @@ -255,7 +279,6 @@ iter_clk_describe_process_response(const struct scmi_protocol_handle *ph, > > *rate = RATE_TO_U64(r->rate[st->loop_idx]); > > p->clk->list.num_rates++; > > - //XXX dev_dbg(ph->dev, "Rate %llu Hz\n", *rate); > > } > > return ret; > > @@ -275,6 +298,7 @@ scmi_clock_describe_rates_get(const struct scmi_protocol_handle *ph, u32 clk_id, > > struct scmi_clk_ipriv cpriv = { > > .clk_id = clk_id, > > .clk = clk, > > + .dev = ph->dev, > > }; > > iter = ph->hops->iter_response_init(ph, &ops, SCMI_MAX_NUM_RATES, > > diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c > > index c1922bd650ae..8b7ac6663d57 100644 > > --- a/drivers/firmware/arm_scmi/driver.c > > +++ b/drivers/firmware/arm_scmi/driver.c > > @@ -1223,6 +1223,7 @@ static int scmi_iterator_run(void *iter) > > if (ret) > > break; > > + st->rx_len = i->t->rx.len; > > ret = iops->update_state(st, i->resp, i->priv); > > if (ret) > > break; > > diff --git a/drivers/firmware/arm_scmi/protocols.h b/drivers/firmware/arm_scmi/protocols.h > > index c679f3fb8718..51c31379f9b3 100644 > > --- a/drivers/firmware/arm_scmi/protocols.h > > +++ b/drivers/firmware/arm_scmi/protocols.h > > @@ -179,6 +179,8 @@ struct scmi_protocol_handle { > > * @max_resources: Maximum acceptable number of items, configured by the caller > > * depending on the underlying resources that it is querying. > > * @loop_idx: The iterator loop index in the current multi-part reply. > > + * @rx_len: Size in bytes of the currenly processed message; it can be used by > > + * the user of the iterator to verify a reply size. > > * @priv: Optional pointer to some additional state-related private data setup > > * by the caller during the iterations. > > */ > > @@ -188,6 +190,7 @@ struct scmi_iterator_state { > > unsigned int num_remaining; > > unsigned int max_resources; > > unsigned int loop_idx; > > + size_t rx_len; > > void *priv; > > }; _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel