From patchwork Mon Dec 20 17:41:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 12696867 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 828D6C433EF for ; Mon, 20 Dec 2021 17:43:47 +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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+EsB/YNTQncA30FNte5br+oj9soCT+2Ay3MjN4ufYgY=; b=bxvKU+0XMqfuyC bLm3clwG3qo1ZvI2zKXLCUq4cqrVk/Cxrp3Nj5r2/FjQlaAxGRLrGVQP+FDYcUx4zggH+hJJMyoWX xZGWjUKoVb4dBkzblsFWQ27uzA9/RJqu1WTYcIN41eDR5ZWYZWGAew9jCZdO7/GEzZxtx2OzenRCt j9H4ReqzRv4rcrGAc3ZT+l/5Xx/c1Vm5gXjC/j9rP055NtTzGq83TknAHxR7PyFrHY+GCZqVDOUrl zOGFj4Rdrj1H7dya3zTuTbt+zAKf+kzwVcqZlLk3Wv3/Z85RIg2MgaFCNjq5i4JRuV8zsX5j2xzuH AN4AW5evBZSR8kk7AQXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mzMgF-003cQG-Bj; Mon, 20 Dec 2021 17:42:35 +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 1mzMg0-003cJj-8O for linux-arm-kernel@lists.infradead.org; Mon, 20 Dec 2021 17:42:21 +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 D5676D6E; Mon, 20 Dec 2021 09:42:17 -0800 (PST) Received: from e120937-lin.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7DB363F774; Mon, 20 Dec 2021 09:42:16 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, f.fainelli@gmail.com, souvik.chakravarty@arm.com, nicola.mazzucato@arm.com, Cristian Marussi Subject: [RFC PATCH 1/2] firmware: arm_scmi: Filter out negative results on scmi_reading_get Date: Mon, 20 Dec 2021 17:41:54 +0000 Message-Id: <20211220174155.40239-2-cristian.marussi@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211220174155.40239-1-cristian.marussi@arm.com> References: <20211220174155.40239-1-cristian.marussi@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211220_094220_375504_8210A738 X-CRM114-Status: GOOD ( 10.85 ) 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: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When the backing SCMI Platform supports a Sensor protocol whose version is greater than SCMI v2.0 (0x10000), the underlying SCMI SENSOR_READING_GET command will report sensors readings no more as unsigned but as signed values. A new scmi_reading_get_timestamped operation was added to properly handle this and other changes like timestamps and multi-axis sensors; on the other side the Sensor scmi_reading_get protocol operation was kepts as it was for backward compatibility and so it stil reports values as unsigned, but no check was added to detect the situation in which a newer FW could try to report negative values over an unsigned quantity. Filter out negative values in scmi_reading_get, reporting an error, when the SCMI FW version is greater than V2.0 and a negative value has been received. Reported-by: Nicola Mazzucato Signed-off-by: Cristian Marussi --- Note that, till now, HWMON SCMI driver was silently interpreting u64 as s64, so after this change whenever a FW >2.0 is used it won't be possible anymore to report negative values in HWMON. --- drivers/firmware/arm_scmi/sensors.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/firmware/arm_scmi/sensors.c b/drivers/firmware/arm_scmi/sensors.c index cdbb287bd8bc..f3952f1d9f61 100644 --- a/drivers/firmware/arm_scmi/sensors.c +++ b/drivers/firmware/arm_scmi/sensors.c @@ -730,6 +730,14 @@ static int scmi_sensor_reading_get(const struct scmi_protocol_handle *ph, *value = get_unaligned_le64(t->rx.buf); } + if (!ret && si->version > SCMIv2_SENSOR_PROTOCOL && *value & BIT(63)) { + dev_warn_once(ph->dev, + "SCMI FW Sensor version:0x%X reported negative value %ld\n", + si->version, (long)*value); + *value = 0; + ret = -EIO; + } + ph->xops->xfer_put(ph, t); return ret; } From patchwork Mon Dec 20 17:41:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 12696868 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 884DAC433F5 for ; Mon, 20 Dec 2021 17:43:54 +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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Vzn5A3e/91inea3XBadsZwkEQw2TG5PSCw4hIdx7G/s=; b=0paWBygjI5UF7u 6u3J0xux434Ssa2lR9/ONVtV2Um6qDl8y8CoMC8JYTMNpn+ay56mCRY/0wlCAHWAGeE+qt7/LIEH+ Yq2A0Ctz6x9DfyAtar7zxAyytt0//TPmfxcd7I88GDQEEbeViJxrn6VxT89ODpWkyXTnps0oEyVUo +F8YLIaB479LCDAQXaFbwiTpWiF4pf5GvGw3TPUEZzn3h3aiRh+auy0KPn3UDwxE9AGGeTK7AIbfK uoUcTRlHi2vi7xgNcFG8nuINHe21gQS4e1jVQKadjnYqvA9HO+vmT531O1H0MD9ob/01HURWhrXLS Ilc5NixCFdFOwz4DLvjw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mzMgS-003cUc-DP; Mon, 20 Dec 2021 17:42:48 +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 1mzMg0-003cKg-EK for linux-arm-kernel@lists.infradead.org; Mon, 20 Dec 2021 17:42:22 +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 53184ED1; Mon, 20 Dec 2021 09:42:19 -0800 (PST) Received: from e120937-lin.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 164563F774; Mon, 20 Dec 2021 09:42:17 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, f.fainelli@gmail.com, souvik.chakravarty@arm.com, nicola.mazzucato@arm.com, Cristian Marussi Subject: [RFC PATCH 2/2] hwmon: (scmi) Filter out results wrongly interpreted as negatives Date: Mon, 20 Dec 2021 17:41:55 +0000 Message-Id: <20211220174155.40239-3-cristian.marussi@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211220174155.40239-1-cristian.marussi@arm.com> References: <20211220174155.40239-1-cristian.marussi@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211220_094220_552225_79386663 X-CRM114-Status: UNSURE ( 9.62 ) X-CRM114-Notice: Please train this message. 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: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org SCMI Sensor scmi_reading_get interface can report only unsigned values while hwmon_ops.read allows for signed negative values to be passed on: this has the undesired side effect of silently interpreting as negative any big-enough positive reading reported by the SCMI interface. Filter out such big positives reporting an error. Signed-off-by: Cristian Marussi --- drivers/hwmon/scmi-hwmon.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c index b1329a58ce40..0924d1b8a9ce 100644 --- a/drivers/hwmon/scmi-hwmon.c +++ b/drivers/hwmon/scmi-hwmon.c @@ -73,10 +73,24 @@ static int scmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type, struct scmi_sensors *scmi_sensors = dev_get_drvdata(dev); sensor = *(scmi_sensors->info[type] + channel); + /* + * Can fail with EIO if the backing SCMI Sensor FW version tried to + * report a negative value. + */ ret = sensor_ops->reading_get(scmi_sensors->ph, sensor->id, &value); if (ret) return ret; + /* + * Cannot accept either valid positive values so big that would be + * interpreted as negative by HWMON signed long *val return value. + */ + if (value & BIT(63)) { + dev_warn_once(dev, + "Reported unsigned value too big.\n"); + return -EIO; + } + ret = scmi_hwmon_scale(sensor, &value); if (!ret) *val = value;