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 1CE4FC43334 for ; Thu, 16 Jun 2022 18:04:16 +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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kCn1ygYUH3kbLjVCQI8Kw6UxXAEt2plF4mMzP48In/c=; b=HplSRgyx8ZClbz PSgotdF6iRGampAkcy6kWTQk4fXhOnvx7S31UQSBkJe75fZNOicv/8grrjKjvgQsRlF4j1q+qG7g3 pGrZqIr0myT0DLikT5FqQtHuFx891Irq+46miyFGzynG4ain0ez2zNsnYtoaUaKSqw08d0XXOPb2S uFWvSmwXlaZuLP1aE1z1uvYC5MHjHHRL3APKsGSxrN5QRKaaBYbXYokXH3GlARoH7ISs7IS8aCa8z CB3dRQZuGyyK5jmVTOvhRF9ZUrCvi3Dvmecb/UEx2nLlyRlmXphRystxxFy43F1KIkBdCBBj0eGiY tZPI8EyQKAnvlJvymyDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o1tpg-003nYc-QQ; Thu, 16 Jun 2022 18:03:04 +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 1o1tpd-003nXR-Po for linux-arm-kernel@lists.infradead.org; Thu, 16 Jun 2022 18:03:03 +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 0B50111FB; Thu, 16 Jun 2022 11:02:57 -0700 (PDT) Received: from [10.57.82.209] (unknown [10.57.82.209]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C70CA3F73B; Thu, 16 Jun 2022 11:02:55 -0700 (PDT) Message-ID: <5fa97307-19d7-a834-dbb9-c7001969a011@arm.com> Date: Thu, 16 Jun 2022 19:02:49 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH] firmware: arm_scmi: Relax CLOCK_DESCRIBE_RATES out-of-spec checks Content-Language: en-GB To: Cristian Marussi , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, nicola.mazzucato@arm.com, vincent.guittot@linaro.org, f.fainelli@gmail.com References: <20220616170347.2800771-1-cristian.marussi@arm.com> From: Robin Murphy In-Reply-To: <20220616170347.2800771-1-cristian.marussi@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220616_110301_984347_BFA605C0 X-CRM114-Status: GOOD ( 26.24 ) 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. > 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