From patchwork Thu Dec 22 18:38:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 35899 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp107890wrn; Thu, 22 Dec 2022 10:43:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXtc6pqM6hLoFtr18+LMuB4OBfAv0qyta5uV/NIdugvMwx55FJvrX1ndek2WIp5//7yU6yLD X-Received: by 2002:a17:907:d407:b0:7ad:f962:dba1 with SMTP id vi7-20020a170907d40700b007adf962dba1mr6453226ejc.53.1671734632657; Thu, 22 Dec 2022 10:43:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671734632; cv=none; d=google.com; s=arc-20160816; b=EgCv5uY9ItFTLgd11r3h4kqgZJNcQ3/oxfBv/Dh0ihJJxmFFQwquh1BeD5VpZ+G5QY ZTjEIUpFIAHczgdMgMByhibXUJx3bQhGTcoS/hRJlRKLmFf8JsbiUh5V3g+FjRKC2XFK +7bzRdF+T+5l8tebj/5ritjI3fDaYNWnq7zA4kgowx8Un9sPbgp3hDebWF1ygiFsst58 g5x9pH6+78oU/WhoZup5IHS8Xam6KyrYYZfBy7zbMRTAnL8q9H+kIvMhXz+MDdtOVuLT a8Ryg6/sfgXKWLV93A4sZXHLWDVPIYko8+M3U0XM71sBDUKBZ15r7hmwOtmLOiP9btb/ lxDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=eDXbYHKzesT3dofWcEIAvKjStKiP/tAUVLhsd//Azv4=; b=gqa+p3XCzUrl9/CwgEQ4bA3zLen9NJSMcvpvNYS96fsltYO03QfifbVTPLtIkTfrXp OwvZGaHFKlN/c9EcNri58+vLaLSs0YEg/MInhxi5WBanIWyWtZVyZJ/2N+4urLp6jh55 fK7lnKp8UcMD2v5cvodfAWgCCAS/PpVrK8eZf5Gz3bmbjqF/JT5z5Uii539+Rw1lF9DY ZSqd2M2oV8pgKxLwFbFeGgft/a8LzC39XIY7cDhkAUxL8HCXWf81lP/yPtuEYbamSJzg 9Hgpa04u0PDpojF+Arw871F8aS5A2Fyh9BRlUCYDrVf6m/KZzcdtqKN0aqMJnvAQSMgt MQ0A== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f24-20020a50fe18000000b0047f1a8093ebsi1176003edt.178.2022.12.22.10.43.28; Thu, 22 Dec 2022 10:43:52 -0800 (PST) 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 S235288AbiLVSiu (ORCPT + 99 others); Thu, 22 Dec 2022 13:38:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230070AbiLVSio (ORCPT ); Thu, 22 Dec 2022 13:38:44 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B33211C932 for ; Thu, 22 Dec 2022 10:38:43 -0800 (PST) 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 8E0551576; Thu, 22 Dec 2022 10:39:24 -0800 (PST) Received: from e120937-lin.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C80FC3FAFB; Thu, 22 Dec 2022 10:38:42 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, cristian.marussi@arm.com Subject: [PATCH 1/5] firmware: arm_scmi: Clear stale xfer->hdr.status Date: Thu, 22 Dec 2022 18:38:19 +0000 Message-Id: <20221222183823.518856-2-cristian.marussi@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221222183823.518856-1-cristian.marussi@arm.com> References: <20221222183823.518856-1-cristian.marussi@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752940814338311329?= X-GMAIL-MSGID: =?utf-8?q?1752940814338311329?= Stale error status reported from a previous message transaction must be cleared before starting a new transaction to avoid being confusingly reported in the following SCMI message dump traces. Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/driver.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index f818d00bb2c6..ffdad59ec81f 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -910,6 +910,8 @@ static int do_xfer(const struct scmi_protocol_handle *ph, xfer->hdr.protocol_id, xfer->hdr.seq, xfer->hdr.poll_completion); + /* Clear any stale status */ + xfer->hdr.status = SCMI_SUCCESS; xfer->state = SCMI_XFER_SENT_OK; /* * Even though spinlocking is not needed here since no race is possible From patchwork Thu Dec 22 18:38:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 35900 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp107906wrn; Thu, 22 Dec 2022 10:43:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXvcZxjl16LC7leSAXxvpJx7pZ7O4kKV0d52KnJ0PfSZ8Eix8iQogtyZNuybEi8bZr+4nIh8 X-Received: by 2002:a17:906:184a:b0:78d:f456:1ed0 with SMTP id w10-20020a170906184a00b0078df4561ed0mr9505001eje.33.1671734636265; Thu, 22 Dec 2022 10:43:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671734636; cv=none; d=google.com; s=arc-20160816; b=c5vdz/c9KgLeSpQjyWje9FO31QWOPMDd9tns7uw+atJpMYD152uokuPoKE6HXGilDE vmFYouMuBqh6rGsQPgSdPn7LWzlxJNogEuE/yELFvfH6hGXN30zpZDga0jVVEYavl6Ib 88gPXWFtB5erxgh1+LMM3oAttetVECmIRA4cJc+C808MmT5ep36Rv6UtQfwWmqxc5QHJ zUsBWKW7nyeRCVYKCV0EfI6YSnilEyLZbe+hOiMiXhYONSRBUjPpeTE2m1DYBvwaQibV 3+NpTA1Uo20+QEEoW8jXbOkMROu82QTHJMATg0z6w7gT8q/gsgqCkpXRUWQKHxYJmV+9 cmvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=pv42xKTVa5o2uys5A6+FEL+H6ruAC7lPymVwRwmvOK4=; b=0tRHpIx7ynGkKBzTO/i7SOJxdNMm42Mch+9DFQVC5QxH3jCz6fRtJHKY3A+/eAt4Zb xb+B/rbWAY7uyqFpJdgr4Bo9WCxd9bcyQIX5q+GC3dVLOmtUp7Jc993Egwqg5hPi8eRz L53Am+/oMoGpSmJuxfo9t9CRrBl9xLlyTQt8o0GPBoODJIT7quAWI1TwUtlJsO1zBH0B qWYW5r1KXYFYB2JPAxld0Q4K3lJ7WsVk4VwR+429lS1d1sIWIVaupLvgkXRC57BgXbTJ pjyW5n3iRkYRrxBu7F0DMI0xgWs946m09ZrFqryTdlUsrT+/guzxIWzwsFxIigLmmvNk 5rBw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he30-20020a1709073d9e00b007c1247d65a8si1091923ejc.687.2022.12.22.10.43.32; Thu, 22 Dec 2022 10:43:56 -0800 (PST) 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 S235285AbiLVSiy (ORCPT + 99 others); Thu, 22 Dec 2022 13:38:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230357AbiLVSip (ORCPT ); Thu, 22 Dec 2022 13:38:45 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BA0FF1D320 for ; Thu, 22 Dec 2022 10:38:44 -0800 (PST) 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 963391595; Thu, 22 Dec 2022 10:39:25 -0800 (PST) Received: from e120937-lin.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CD7323FAFB; Thu, 22 Dec 2022 10:38:43 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, cristian.marussi@arm.com Subject: [PATCH 2/5] firmware: arm_scmi: Harden shared memory access in fetch_response Date: Thu, 22 Dec 2022 18:38:20 +0000 Message-Id: <20221222183823.518856-3-cristian.marussi@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221222183823.518856-1-cristian.marussi@arm.com> References: <20221222183823.518856-1-cristian.marussi@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752940817870121918?= X-GMAIL-MSGID: =?utf-8?q?1752940817870121918?= A misbheaving SCMI platform firmware could reply with out-of-spec messages, shorter than the mimimum size comprising a header and a status field. Harden shmem_fetch_response to properly truncate such a bad messages. Fixes: 5c8a47a5a91d ("firmware: arm_scmi: Make scmi core independent of the transport type") Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/shmem.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/arm_scmi/shmem.c b/drivers/firmware/arm_scmi/shmem.c index 1dfe534b8518..135f8718000f 100644 --- a/drivers/firmware/arm_scmi/shmem.c +++ b/drivers/firmware/arm_scmi/shmem.c @@ -81,10 +81,11 @@ u32 shmem_read_header(struct scmi_shared_mem __iomem *shmem) void shmem_fetch_response(struct scmi_shared_mem __iomem *shmem, struct scmi_xfer *xfer) { + size_t len = ioread32(&shmem->length); + xfer->hdr.status = ioread32(shmem->msg_payload); /* Skip the length of header and status in shmem area i.e 8 bytes */ - xfer->rx.len = min_t(size_t, xfer->rx.len, - ioread32(&shmem->length) - 8); + xfer->rx.len = min_t(size_t, xfer->rx.len, len > 8 ? len - 8 : 0); /* Take a copy to the rx buffer.. */ memcpy_fromio(xfer->rx.buf, shmem->msg_payload + 4, xfer->rx.len); From patchwork Thu Dec 22 18:38:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 35902 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp108775wrn; Thu, 22 Dec 2022 10:46:20 -0800 (PST) X-Google-Smtp-Source: AMrXdXsY90G13UmtpFY91jjex4CFvpDetvZleJjGHoYDdHrNzqxMGhX3+F8Vm/2sItPiKN0xKOeI X-Received: by 2002:aa7:d589:0:b0:46c:d2f2:123d with SMTP id r9-20020aa7d589000000b0046cd2f2123dmr5812951edq.40.1671734780038; Thu, 22 Dec 2022 10:46:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671734780; cv=none; d=google.com; s=arc-20160816; b=jh7HD0ajCmGaBg1JlRadR5ksF2EdGSxrtOS8QO58V3UBOgJY+RAUog2X+rWDKliFly fg4y2MAtRxDb0rg1NeOa1UxbiKdETWdKwsIlIzFtnv8WN/F5ZigotxBjBExJJzza24Qh Pctnj88x2OwVIXYdT8astYKq32Pa8n08ELJxzyZjAOFiMrDVGtesUwyAcix7dcunnyQF Ggcdg5YW8XCJMXPI39l5UP3JQaq4AKBWcTM51yN4kLgMyzGRAMRJIxYpbgfmmybcLmKh eQ7XogPWeMjbjrDFy2TIrAKe/NbDR1ovUUp+QlL1qXRbCLcultD/7A1NsZU8PEE7oSSp 93sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=JXQ/UQPT656CR5yHneNcSt52JhvnXm8ShuRkkoDcLto=; b=T7RG2M7ubUswXJiTn86Ag2BNAQPzENSNixESGRutSpIxsEpxc95HCFcw+vcfXNHEFc 47jcqIvX5pNMISAXo9BKxjm2hrVzDyxqJAUAo7GOhLePpppJyKT6Uexx5r1NWhRlGBii idiE5ANzT8ueLkns5mruHbwtX9RdkX8vd0uuYyio42jbd/i8LUJsXSZIc+cjfzOBX49t fdfliWPvRC041DbdBodmj7pKuBXJsz2i33eyy6j43pDIMXJpG+kXK3DBpPX39Iun4z0s qPMH7YIJHHgUPxxAiAMBuK/lB7BxDgRDosoAR+2jD0wHFigqC7Mo8oSwtp1cssMmbq+H D1Qg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw9-20020a170906478900b007aeaacd5592si1022955ejc.124.2022.12.22.10.45.55; Thu, 22 Dec 2022 10:46:20 -0800 (PST) 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 S235379AbiLVSi5 (ORCPT + 99 others); Thu, 22 Dec 2022 13:38:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230444AbiLVSiq (ORCPT ); Thu, 22 Dec 2022 13:38:46 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A9BA81D661 for ; Thu, 22 Dec 2022 10:38:45 -0800 (PST) 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 869A2169E; Thu, 22 Dec 2022 10:39:26 -0800 (PST) Received: from e120937-lin.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BF6703FAFB; Thu, 22 Dec 2022 10:38:44 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, cristian.marussi@arm.com Subject: [PATCH 3/5] firmware: arm_scmi: Harden shared memory access in fetch_notification Date: Thu, 22 Dec 2022 18:38:21 +0000 Message-Id: <20221222183823.518856-4-cristian.marussi@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221222183823.518856-1-cristian.marussi@arm.com> References: <20221222183823.518856-1-cristian.marussi@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752940968736157683?= X-GMAIL-MSGID: =?utf-8?q?1752940968736157683?= A misbheaving SCMI platform firmware could reply with out-of-spec notifications, shorter than the mimimum size comprising a header. Fixes: d5141f37c42e ("firmware: arm_scmi: Add notifications support in transport layer") Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/shmem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/arm_scmi/shmem.c b/drivers/firmware/arm_scmi/shmem.c index 135f8718000f..87b4f4d35f06 100644 --- a/drivers/firmware/arm_scmi/shmem.c +++ b/drivers/firmware/arm_scmi/shmem.c @@ -94,8 +94,10 @@ void shmem_fetch_response(struct scmi_shared_mem __iomem *shmem, void shmem_fetch_notification(struct scmi_shared_mem __iomem *shmem, size_t max_len, struct scmi_xfer *xfer) { + size_t len = ioread32(&shmem->length); + /* Skip only the length of header in shmem area i.e 4 bytes */ - xfer->rx.len = min_t(size_t, max_len, ioread32(&shmem->length) - 4); + xfer->rx.len = min_t(size_t, max_len, len > 4 ? len - 4 : 0); /* Take a copy to the rx buffer.. */ memcpy_fromio(xfer->rx.buf, shmem->msg_payload, xfer->rx.len); From patchwork Thu Dec 22 18:38:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 35901 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp108690wrn; Thu, 22 Dec 2022 10:46:06 -0800 (PST) X-Google-Smtp-Source: AMrXdXvF4q8mBAK3O3Gss1nsJo7XUbtI2Iv7uAsmR1vCJkRhL5E0Hmofy9rxtmBGoOGGnDpq7Rww X-Received: by 2002:aa7:dd13:0:b0:45c:937d:25c8 with SMTP id i19-20020aa7dd13000000b0045c937d25c8mr5885695edv.1.1671734765968; Thu, 22 Dec 2022 10:46:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671734765; cv=none; d=google.com; s=arc-20160816; b=hGyZTbEY14iR4UeCqmAwAbp8Go60SFRRRh8m07DerklKmQWjTevhK3ol65lwcg5MR8 jcWxv1qv2tTqXwMphYmSMGj0tEKXqQSYAUR/PH4vgPeuEg05IRwa3BqUoEaetmD6PEGI bXf05gY0Emq2nCvgTX68HQXThNZcKWtEi6UHIPVkeapLWZOo/nKYzJclFQfpaCt/XjgA 52Uyz5dUAyrfXmGQ2gZccqSBFnh8a1GPxD6pAhRJ+kcX8vYQliTLbffGh2xEQiBWFtDi AXyy9UaMafmelkyIt4ImEkGDyxdMmijefLcfalhRiHSp6mpNosp900uV0Y3SwljTVzzd y95g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=vSRHk3tF4RzYxXaHI8hgErzcouS2nfh1gm07p3d87aA=; b=dY3aELgHkAddHQSCiuTmnPo2rgnZCkgiBxgDxXTeDLhUigmZECZC0SJ18M2b/RKgX3 ALhXMgWNeSxIzGI9xqI6a0sSfvIzXD+pX+CcH2l7PN6EylLugfJU+7HhPnffnU2blM40 NNl8lzSxQhVWqnjwiFE5zidf8aLi6/UP0Itjxi1v82EIwqsV7fbHvDLWR3HqhlkfVvqJ Bb0vi32c0DjN65bGcj0AjUaqihc7w1gNkA1VE1w07oPa8DtvrWdh6bYzhpb6WrwcUrQN T9yCpIGoB43B/eVaoUoC+fgyNXWSnhPAQSQISmEFBq3G40rf4OrZ1a0W0UknlTw0BwXk FGxA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a21-20020a05640213d500b00472982b0adbsi1088287edx.55.2022.12.22.10.45.41; Thu, 22 Dec 2022 10:46:05 -0800 (PST) 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 S235427AbiLVSjB (ORCPT + 99 others); Thu, 22 Dec 2022 13:39:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235230AbiLVSir (ORCPT ); Thu, 22 Dec 2022 13:38:47 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D8D9C1D329; Thu, 22 Dec 2022 10:38:46 -0800 (PST) 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 B253F16A3; Thu, 22 Dec 2022 10:39:27 -0800 (PST) Received: from e120937-lin.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B075F3FAFB; Thu, 22 Dec 2022 10:38:45 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, cristian.marussi@arm.com, Rob Herring , devicetree@vger.kernel.org Subject: [PATCH 4/5] dt-bindings: firmware: arm,scmi: Add support for syspower protocol Date: Thu, 22 Dec 2022 18:38:22 +0000 Message-Id: <20221222183823.518856-5-cristian.marussi@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221222183823.518856-1-cristian.marussi@arm.com> References: <20221222183823.518856-1-cristian.marussi@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752940953687901516?= X-GMAIL-MSGID: =?utf-8?q?1752940953687901516?= Add new SCMI Syspower protocol bindings definitions and example. Cc: Rob Herring Cc: devicetree@vger.kernel.org Signed-off-by: Cristian Marussi --- Got lost in translation probably...from txt to yaml --- .../devicetree/bindings/firmware/arm,scmi.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml index 1c0388da6721..f3dd77a470dd 100644 --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml @@ -111,6 +111,12 @@ properties: required: - '#power-domain-cells' + protocol@12: + type: object + properties: + reg: + const: 0x12 + protocol@13: type: object properties: @@ -285,6 +291,10 @@ examples: #power-domain-cells = <1>; }; + scmi_syspower: protocol@12 { + reg = <0x12>; + }; + scmi_dvfs: protocol@13 { reg = <0x13>; #clock-cells = <1>; From patchwork Thu Dec 22 18:38:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 35903 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp109014wrn; Thu, 22 Dec 2022 10:46:54 -0800 (PST) X-Google-Smtp-Source: AMrXdXtuVh5HLuH6aedVDRDZgrpWsRuGsXYO4DrSt+UOa8ssKKPUED2JVEY0tyDtVnSd1FOZW7r9 X-Received: by 2002:a05:6402:4009:b0:467:dc59:cec6 with SMTP id d9-20020a056402400900b00467dc59cec6mr12020519eda.0.1671734814812; Thu, 22 Dec 2022 10:46:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671734814; cv=none; d=google.com; s=arc-20160816; b=IUyU2KCjy/A0D9vdCuW1bIWI/amhO/vAwZ8TQUMyKuO57tqNiTfe5vmw6pokidVS9c rJLOhRcDbRCNjyZ1wj84CUWhH8rfPRi5YCFuCwOlSwSuKNU62XsJfPZoFzdoF/Yh8sA2 sZ3aCgxqHG6RSkzIIn84PI7S65m4wG6P0Z+YGGtN11MbnCUbhODxUBDZzFTdJ5vRjAR4 7bIZE/eNyKeJ01gfzwBspIH6mvfb0GDsV6Zx0GiYLJfCamIgeE/zeAY+aLaIMTBzjUO0 QdLBDf5VGoi5srL0o9vD3bjs48nLxeGAwpaT88UnKNEH+snnYpKPDP+Swxlla8xgJ5GG fAEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=q4tCi7tStcUowLDltlSeMcJt8ohL5CBfgI2VYOiT1xs=; b=m88jIKEDJRVx0L1ORoqE2ofHq9XjMfiImZjy1ikS3+FJ2Jucf3FsRCekT4153mrReQ O8iZrg7p1PN5WOY4lyi0jWGjG9xIF/EIGPQq2YCSDnlimbMYVzmTNXEaG65S5bjIAjTB 7YYKcQsw6lILSbOLJZaGuLtM549nBP84diqZVCNNKvkVn2YUmdwNi4dLfae+DzEUGe1j 2uSPuoOIBFgVbVnhZyQdz4Kskjc0g04exULyD2Ix3+RrFVxEM5BJ40c1kf99bovXz4Rk zERA+LIaSGgTG7x6+tfI/8omXqqZBmOXSz4ncvdbiWtPohCejEcdPUho63lTo1ezF7k8 QQkA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m19-20020a056402511300b0045d15f39bf4si1341454edd.479.2022.12.22.10.46.30; Thu, 22 Dec 2022 10:46:54 -0800 (PST) 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 S235438AbiLVSjE (ORCPT + 99 others); Thu, 22 Dec 2022 13:39:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235217AbiLVSit (ORCPT ); Thu, 22 Dec 2022 13:38:49 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CFCDE1D320 for ; Thu, 22 Dec 2022 10:38:47 -0800 (PST) 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 A32AA16F2; Thu, 22 Dec 2022 10:39:28 -0800 (PST) Received: from e120937-lin.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DA57D3FAFB; Thu, 22 Dec 2022 10:38:46 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, cristian.marussi@arm.com Subject: [PATCH 5/5] firmware: arm_scmi: Fix virtio channels cleanup on shutdown Date: Thu, 22 Dec 2022 18:38:23 +0000 Message-Id: <20221222183823.518856-6-cristian.marussi@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221222183823.518856-1-cristian.marussi@arm.com> References: <20221222183823.518856-1-cristian.marussi@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752941005204556613?= X-GMAIL-MSGID: =?utf-8?q?1752941005204556613?= When unloading the SCMI core stack module, configured to use the virtio SCMI transport, LOCKDEP reports the splat down below about unsafe locks dependencies. In order to avoid this possible unsafe locking scenario call upfront virtio_break_device() before getting hold of vioch->lock. ===================================================== WARNING: HARDIRQ-safe -> HARDIRQ-unsafe lock order detected 6.1.0-00067-g6b934395ba07-dirty #4 Not tainted ----------------------------------------------------- rmmod/307 [HC0[0]:SC0[0]:HE0:SE1] is trying to acquire: ffff000080c510e0 (&dev->vqs_list_lock){+.+.}-{3:3}, at: virtio_break_device+0x28/0x68 and this task is already holding: ffff00008288ada0 (&channels[i].lock){-.-.}-{3:3}, at: virtio_chan_free+0x60/0x168 [scmi_module] which would create a new lock dependency: (&channels[i].lock){-.-.}-{3:3} -> (&dev->vqs_list_lock){+.+.}-{3:3} but this new dependency connects a HARDIRQ-irq-safe lock: (&channels[i].lock){-.-.}-{3:3} ... which became HARDIRQ-irq-safe at: lock_acquire+0x128/0x398 _raw_spin_lock_irqsave+0x78/0x140 scmi_vio_complete_cb+0xb4/0x3b8 [scmi_module] vring_interrupt+0x84/0x120 vm_interrupt+0x94/0xe8 __handle_irq_event_percpu+0xb4/0x3d8 handle_irq_event_percpu+0x20/0x68 handle_irq_event+0x50/0xb0 handle_fasteoi_irq+0xac/0x138 generic_handle_domain_irq+0x34/0x50 gic_handle_irq+0xa0/0xd8 call_on_irq_stack+0x2c/0x54 do_interrupt_handler+0x8c/0x90 el1_interrupt+0x40/0x78 el1h_64_irq_handler+0x18/0x28 el1h_64_irq+0x64/0x68 _raw_write_unlock_irq+0x48/0x80 ep_start_scan+0xf0/0x128 do_epoll_wait+0x390/0x858 do_compat_epoll_pwait.part.34+0x1c/0xb8 __arm64_sys_epoll_pwait+0x80/0xd0 invoke_syscall+0x4c/0x110 el0_svc_common.constprop.3+0x98/0x120 do_el0_svc+0x34/0xd0 el0_svc+0x40/0x98 el0t_64_sync_handler+0x98/0xc0 el0t_64_sync+0x170/0x174 to a HARDIRQ-irq-unsafe lock: (&dev->vqs_list_lock){+.+.}-{3:3} ... which became HARDIRQ-irq-unsafe at: ... lock_acquire+0x128/0x398 _raw_spin_lock+0x58/0x70 __vring_new_virtqueue+0x130/0x1c0 vring_create_virtqueue+0xc4/0x2b8 vm_find_vqs+0x20c/0x430 init_vq+0x308/0x390 virtblk_probe+0x114/0x9b0 virtio_dev_probe+0x1a4/0x248 really_probe+0xc8/0x3a8 __driver_probe_device+0x84/0x190 driver_probe_device+0x44/0x110 __driver_attach+0x104/0x1e8 bus_for_each_dev+0x7c/0xd0 driver_attach+0x2c/0x38 bus_add_driver+0x1e4/0x258 driver_register+0x6c/0x128 register_virtio_driver+0x2c/0x48 virtio_blk_init+0x70/0xac do_one_initcall+0x84/0x420 kernel_init_freeable+0x2d0/0x340 kernel_init+0x2c/0x138 ret_from_fork+0x10/0x20 other info that might help us debug this: Possible interrupt unsafe locking scenario: CPU0 CPU1 ---- ---- lock(&dev->vqs_list_lock); local_irq_disable(); lock(&channels[i].lock); lock(&dev->vqs_list_lock); lock(&channels[i].lock); *** DEADLOCK *** ================ Fixes: 42e90eb53bf3f ("firmware: arm_scmi: Add a virtio channel refcount") Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/virtio.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/arm_scmi/virtio.c b/drivers/firmware/arm_scmi/virtio.c index 33c9b81a55cd..1db975c08896 100644 --- a/drivers/firmware/arm_scmi/virtio.c +++ b/drivers/firmware/arm_scmi/virtio.c @@ -160,7 +160,6 @@ static void scmi_vio_channel_cleanup_sync(struct scmi_vio_channel *vioch) } vioch->shutdown_done = &vioch_shutdown_done; - virtio_break_device(vioch->vqueue->vdev); if (!vioch->is_rx && vioch->deferred_tx_wq) /* Cannot be kicked anymore after this...*/ vioch->deferred_tx_wq = NULL; @@ -482,6 +481,12 @@ static int virtio_chan_free(int id, void *p, void *data) struct scmi_chan_info *cinfo = p; struct scmi_vio_channel *vioch = cinfo->transport_info; + /* + * Break device to inhibit further traffic flowing while shutting down + * the channels: doing it later holding vioch->lock creates unsafe + * locking dependency chains as reported by LOCKDEP. + */ + virtio_break_device(vioch->vqueue->vdev); scmi_vio_channel_cleanup_sync(vioch); scmi_free_channel(cinfo, data, id);