Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp313051iog; Fri, 17 Jun 2022 04:13:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sv6mRg7HFU5CFZzr81sIQ24vgf5EN13bMRVIg176MUCu9c8YQ7Td7ZMTDaA5BIH3Cwa3wp X-Received: by 2002:a63:8c5e:0:b0:40c:67ae:6529 with SMTP id q30-20020a638c5e000000b0040c67ae6529mr55445pgn.509.1655464433795; Fri, 17 Jun 2022 04:13:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655464433; cv=none; d=google.com; s=arc-20160816; b=jrlOWveXefwDBadUBZeFbgWO/fDZdYY/DskT5GsbIyy7aaVqt97MWN4TLk4oAgovgg HnZnt2pyzVNS01U8IVQmloAquXtCS9VxN+bsKErBBVa9eh5LJZ76Wl7i/EJPmWTxD/kF Copw/NHZVQMbs7W+DnMoiBpDoiDSk2bJ/niwi9WBBQZvVkcRkuOk5EFQq44Zpr1T+inr qJZpqK5xtMF6siUGiP4ncVQ+vkINZLUctyjhS09MQ5lv+wTcOVGXpSsDbih6ouxIGhG+ ulHN7h57T7ERaiPehB68tnMB4MotO6QtpdJ+rYndh3VcqC/uMkIa5O2SFiTzQ9zzBCpr LnSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=QXET1I254icUoz8BBQiASYQscgxsnoXqg9sPp0r4wkI=; b=vLiu48MOIydHhqbWqPWfR21AsifuJfzc23eJ0g3j+PWPewZhNH9zFNXZlUuS30MA9W 7soTcKjHmbAN/cdcyYhEPAOOyY//k8BjGgejVWA8PlamCHqKLM9Cxn3vDRZT1106zde6 sEqJPujWGWNBSQp0bs5GyicnUndqi82IwCbBKMtcvFOcqvA8HfQqMZ0Rjk7LjepCTVGV wE0Vt1IZT75KR+GleFPfYb5SsrCWa86Kr2iTtQNW6Tv0oZkEpqdpwPjYVX8RoC44IgBf XA3xVivXVJuOF1aHvvukAyq1BtpGzIT+9JO0D4M6H+XzeKAm58XBNj0AqAoSwa1fe44Z iggQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u18-20020a170903125200b00153b2d164fbsi6644866plh.259.2022.06.17.04.13.37; Fri, 17 Jun 2022 04:13:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381289AbiFQLMz (ORCPT + 99 others); Fri, 17 Jun 2022 07:12:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381154AbiFQLMy (ORCPT ); Fri, 17 Jun 2022 07:12:54 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 308941A04A for ; Fri, 17 Jun 2022 04:12:52 -0700 (PDT) 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5fa97307-19d7-a834-dbb9-c7001969a011@arm.com> X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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; > > };