Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1687415iog; Thu, 16 Jun 2022 11:31:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uSwGkKgVU4dFCSnW4y5tXk8JiejRLB7bCwX9FsDyVZbSaafUFm5a6gTFeT0cKWKsiwCFZA X-Received: by 2002:a17:90b:1210:b0:1ea:ee10:c823 with SMTP id gl16-20020a17090b121000b001eaee10c823mr4719552pjb.109.1655404260504; Thu, 16 Jun 2022 11:31:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655404260; cv=none; d=google.com; s=arc-20160816; b=vlaK50KUkxg6zle1MKKDr4At8JhzxaOnenzgFT3ZIX8CCb9bfUNUHR+qZpGxDItd0D R09xTe+jmJsULoTK7w1X4wWR5v8ZVbvC6hgSQ3Z0PIgtw+V4bt/0FSD2SOmvYAoaN8Sd uqQ2n6y19Ty1u5VOGxdD8BjJV+ApPpS5+aY2XfGirv89rXtcMg3/8KQ4InqbqvJhnFM1 LAiVjfjwnMPz5dZFyzPa1Ks3DJ1SixVX3JxlLExOU2S41bUJ3NKl9tLGKgzGWzPHWzpC BF8FQYbv3Ifw0yGkSxtUA1aFTZ1egmAHD9bDjZK3nt0yK1DRKvMKzRNgUlFfdpxPhRxH KUHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=KbOPYZPQjvC714xI4vxmX8VnS/XfqBoR7Pp0XyAhjfM=; b=LZlqNlqSv0fiTK+zSMlpHrb7vB70r0PonImsgLym6a+zcuNHNlmW17znGYTlnuQmBg lTwEQbm0KpMYV7JSD9Nmh+QOPSceW8PhnuLTcDjwTGrQCE4zQ7LBB6W8Xm7JPxGM/7kf Polkt1EM8Mq/B0iz8QHqaKnQ8bzMVLZuGZOhLBAXLJ5oVY9NJtEF4C576zQ3fKFECbmB Z7YpAQqXaWQgwXPZDZ2JHZw/A7ihE24nss1dwXuaS4E4g2Y4Tdr/1Lp3myNRM6DmaITP AwR7RVwQ4dbUlnukQTMXrv/IsAJWu97rJ+KXTEJEYQ0IwiwlPeG3z0sN3ZapawOVmeKk 1LFA== 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 e9-20020a170902ef4900b00168b8ef0734si3205072plx.508.2022.06.16.11.30.47; Thu, 16 Jun 2022 11:31:00 -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 S242736AbiFPSC7 (ORCPT + 99 others); Thu, 16 Jun 2022 14:02:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229561AbiFPSC6 (ORCPT ); Thu, 16 Jun 2022 14:02:58 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 284ECE0DF for ; Thu, 16 Jun 2022 11:02:57 -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 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> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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 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; > }; >