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 1A2DBC982CC for ; Sun, 20 Sep 2026 09:20:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=H5BTcoA9+94KRYddRu4mHSSUMUgwqghE4QR9AVtOE3w=; b=UsyjqKjJ2YrHsjpTLP0pUbSSkP XtyVNKk7ESDith8ocS7pJV+cBMUh/ThK/iW8AEIQ39vRs4EIegz3mP277+FylVuUUrg1ajDDq9O0t kSpNGCZY4uXcVHiUMDJMmC3biAurINvdWyqZudCh8fH6vVfM1vmW40K/Q8Ez5SUpQBiTtKqfA1Suz G9165PhkGHC/O5mC+D+BHYaBuuXR7cBX8/hBd9MtAN779n/S7Lkolj7kRXfYjWQ7VsUwRR8bp1MsQ dydga0VGUDWn98fY+KmD7SMRE1TVN+wQclyiEVt0Lx8jxsFosb/xD7Bl/AvW+ybPd8p3Ha0eL90Ni ye4yUA3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x8Dim-0000000H9Ca-1zh2; Sun, 20 Sep 2026 09:20:28 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x8Did-0000000H99p-0RQ7 for linux-arm-kernel@lists.infradead.org; Sun, 20 Sep 2026 09:20:20 +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 26889175A; Sun, 20 Sep 2026 02:20:14 -0700 (PDT) Received: from pluto.fritz.box (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D368E3F59E; Sun, 20 Sep 2026 02:20:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789896017; bh=Z1zT/+qmdnYlo6v6PyvGTRruroGKs4FxS/7jYNNL1h8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OtL7pd7tSdRuMX6Uj2n/EhNv5zenFA7EzbQCZ3/kabtNnyUF5Uq70SU18u5GP4Rnq IKYknV04kQcHjKTNIAiFzyVpK//cWJgW0iyumlsBETslgEB8O+trrlYvEzcHfz+a30 MJsBNRQGS16Ij5fKz6Fh/8RBFEam7TNWi54skhcM= From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org, linux-doc@vger.kernel.org Cc: sudeep.holla@kernel.org, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, etienne.carriere@st.com, peng.fan@oss.nxp.com, michal.simek@amd.com, d-gole@ti.com, jic23@kernel.org, elif.topuz@arm.com, lukasz.luba@arm.com, philip.radford@arm.com, david@kernel.org, souvik.chakravarty@arm.com, leitao@kernel.org, kas@kernel.org, puranjay@kernel.org, usama.arif@linux.dev, kernel-team@meta.com, Cristian Marussi , Jonathan Cameron Subject: [PATCH v12 02/25] firmware: arm_scmi: Allow registration of unknown-size events/reports Date: Sun, 20 Sep 2026 10:19:05 +0100 Message-ID: <20260920091928.2014972-3-cristian.marussi@arm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260920091928.2014972-1-cristian.marussi@arm.com> References: <20260920091928.2014972-1-cristian.marussi@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260920_022019_239218_6F53E3E7 X-CRM114-Status: GOOD ( 17.88 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Allow protocols to register events with build-time unknown sizes: such events can be declared zero-sized and let the core SCMI stack perform the needed safe-net boundary checks based on the configured transport size. Reviewed-by: Jonathan Cameron Signed-off-by: Cristian Marussi --- v10 --> v11 - account for ktime_t field when checking boundary v2 --> v3 - split out of previous patch on protocol notifier - use max() instead of max_t() --- drivers/firmware/arm_scmi/notify.c | 25 ++++++++++++++++++++----- drivers/firmware/arm_scmi/notify.h | 8 ++++++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/drivers/firmware/arm_scmi/notify.c b/drivers/firmware/arm_scmi/notify.c index fb60fb07c0ed..3264e1062700 100644 --- a/drivers/firmware/arm_scmi/notify.c +++ b/drivers/firmware/arm_scmi/notify.c @@ -595,7 +595,13 @@ int scmi_notify(const struct scmi_handle *handle, u8 proto_id, u8 evt_id, if (!r_evt) return -EINVAL; - if (len > r_evt->evt->max_payld_sz) { + /* + * Events with a zero max_payld_sz are sized to be of the maximum + * size allowed by the transport: no need to be size-checked here + * since the transport layer would have already dropped such + * over-sized messages. + */ + if (r_evt->evt->max_payld_sz && len > r_evt->evt->max_payld_sz) { dev_err(handle->dev, "discard badly sized message\n"); return -EINVAL; } @@ -752,7 +758,7 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id, const struct scmi_protocol_handle *ph, const struct scmi_protocol_events *ee) { - int i; + int i, max_msg_sz, max_report_sz; unsigned int num_sources; size_t payld_sz = 0; struct scmi_registered_events_desc *pd; @@ -767,6 +773,9 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id, if (!ni) return -ENOMEM; + max_msg_sz = ph->hops->get_max_msg_size(ph); + max_report_sz = max_msg_sz + sizeof(ktime_t); + /* num_sources cannot be <= 0 */ if (ee->num_sources) { num_sources = ee->num_sources; @@ -779,8 +788,13 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id, } evt = ee->evts; - for (i = 0; i < ee->num_events; i++) - payld_sz = max_t(size_t, payld_sz, evt[i].max_payld_sz); + for (i = 0; i < ee->num_events; i++) { + if (evt[i].max_payld_sz == 0) { + payld_sz = max_msg_sz; + break; + } + payld_sz = max(payld_sz, evt[i].max_payld_sz); + } payld_sz += sizeof(struct scmi_event_header); pd = scmi_allocate_registered_events_desc(ni, proto_id, ee->queue_sz, @@ -807,7 +821,8 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id, mutex_init(&r_evt->sources_mtx); r_evt->report = devm_kzalloc(ni->handle->dev, - evt->max_report_sz, GFP_KERNEL); + evt->max_report_sz ?: max_report_sz, + GFP_KERNEL); if (!r_evt->report) return -ENOMEM; diff --git a/drivers/firmware/arm_scmi/notify.h b/drivers/firmware/arm_scmi/notify.h index f18f98c5ab3b..c2eb4844c7db 100644 --- a/drivers/firmware/arm_scmi/notify.h +++ b/drivers/firmware/arm_scmi/notify.h @@ -18,8 +18,12 @@ /** * struct scmi_event - Describes an event to be supported * @id: Event ID - * @max_payld_sz: Max possible size for the payload of a notification message - * @max_report_sz: Max possible size for the report of a notification message + * @max_payld_sz: Max possible size for the payload of a notification message. + * Set to zero to use the maximum payload size allowed by the + * transport. + * @max_report_sz: Max possible size for the report of a notification message. + * Set to zero to use the maximum payload size allowed by the + * transport plus the additional ktime_t timestamp. * * Each SCMI protocol, during its initialization phase, can describe the events * it wishes to support in a few struct scmi_event and pass them to the core -- 2.54.0