From nobody Fri Dec 19 09:50:26 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0857EEE020F for ; Wed, 13 Sep 2023 21:27:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232359AbjIMV1g (ORCPT ); Wed, 13 Sep 2023 17:27:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229698AbjIMV1b (ORCPT ); Wed, 13 Sep 2023 17:27:31 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0B661724 for ; Wed, 13 Sep 2023 14:27:27 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-577dad08512so695452a12.1 for ; Wed, 13 Sep 2023 14:27:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694640447; x=1695245247; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oOiFJlPGyJUavNNVJMIMcGzvlYAGe09SF66xWdVaxyU=; b=aP1CrSMPFY/9BpGHOgfmmkbW0TKI9OKa0TkBfI4Q6dG7IY75LrR1u7SseAg0gt5zaY YZhHEEZRwh0ykb9Bcx+/aHeT2UNCT64SnjpbzVzNVD2hopL543cXm4yOjppFRsEKGok5 Z/10+RP7OdA67IIdWydENjNRC6wJ8ap9/JL5s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694640447; x=1695245247; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oOiFJlPGyJUavNNVJMIMcGzvlYAGe09SF66xWdVaxyU=; b=KiOTj4jqq6Iupsf2O53IYhab68xDWNUVaWebBtRAOW54rIryAoJfYiBPGDV0dA8aZ0 1V0HshVrr5yxEjZnSiO8iAqgJwvyKxIaDb2tJaaupNyeAyzQsYDQJY2JMUzTXagAiQ/8 D2zTL2XWNMpenlOlnvWIMIoKKZIenqcCXGy+sZlwDy1tnzRJbwfhdpYgxVnFC2Mfb1DW mA+zUwtenBTEIDG1LnL1zR9cWw5FUiUK7jkl+stlkDh+KpLWg/UGJ7d0Jn+zpMHqI3Ka fySNsws1fCmKDuz54tnF/YN3QiN9iY/rsoDcbuo5/1KB8TqJ0waR+oqUbqZDd951KnQC KTtw== X-Gm-Message-State: AOJu0YyQKAF61QNAN2lY/NtFIegbUjbtOnivrZa26SiuYSDtswOR9e9V xXJdR7Qi5Ba8+VBxd+somsyTpg== X-Google-Smtp-Source: AGHT+IGyULUVZNu+bUP/MqMEKr8RaVU+CWUNozYQ8it166LT6PCoR6pmCH6eo+YA6LRjoue3V82dXQ== X-Received: by 2002:a17:90b:30c2:b0:26f:392f:f901 with SMTP id hi2-20020a17090b30c200b0026f392ff901mr5552309pjb.14.1694640447120; Wed, 13 Sep 2023 14:27:27 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:11a:201:ae97:c6dc:1d98:494f]) by smtp.gmail.com with ESMTPSA id a10-20020a17090ad80a00b0025bdc3454c6sm1923976pjv.8.2023.09.13.14.27.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 14:27:26 -0700 (PDT) From: Stephen Boyd To: Mika Westerberg , Hans de Goede , Mark Gross Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, platform-driver-x86@vger.kernel.org, Andy Shevchenko , Kuppuswamy Sathyanarayanan , Prashant Malani Subject: [PATCH v4 1/4] platform/x86: intel_scu_ipc: Check status after timeout in busy_loop() Date: Wed, 13 Sep 2023 14:27:19 -0700 Message-ID: <20230913212723.3055315-2-swboyd@chromium.org> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog In-Reply-To: <20230913212723.3055315-1-swboyd@chromium.org> References: <20230913212723.3055315-1-swboyd@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It's possible for the polling loop in busy_loop() to get scheduled away for a long time. status =3D ipc_read_status(scu); // status =3D IPC_STATUS_BUSY if (!(status & IPC_STATUS_BUSY)) If this happens, then the status bit could change while the task is scheduled away and this function would never read the status again after timing out. Instead, the function will return -ETIMEDOUT when it's possible that scheduling didn't work out and the status bit was cleared. Bit polling code should always check the bit being polled one more time after the timeout in case this happens. Fix this by reading the status once more after the while loop breaks. The readl_poll_timeout() macro implements all of this, and it is shorter, so use that macro here to consolidate code and fix this. There were some concerns with using readl_poll_timeout() because it uses timekeeping, and timekeeping isn't running early on or during the late stages of system suspend or early stages of system resume, but an audit of the code concluded that this code isn't called during those times so it is safe to use the macro. Cc: Prashant Malani Reviewed-by: Andy Shevchenko Reviewed-by: Mika Westerberg Reviewed-by: Kuppuswamy Sathyanarayanan Fixes: e7b7ab3847c9 ("platform/x86: intel_scu_ipc: Sleeping is fine when po= lling") Signed-off-by: Stephen Boyd Reviewed-by: Ilpo J=C3=A4rvinen --- drivers/platform/x86/intel_scu_ipc.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/in= tel_scu_ipc.c index 6851d10d6582..4c774ee8bb1b 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include =20 @@ -231,19 +232,15 @@ static inline u32 ipc_data_readl(struct intel_scu_ipc= _dev *scu, u32 offset) /* Wait till scu status is busy */ static inline int busy_loop(struct intel_scu_ipc_dev *scu) { - unsigned long end =3D jiffies + IPC_TIMEOUT; + u8 status; + int err; =20 - do { - u32 status; + err =3D readx_poll_timeout(ipc_read_status, scu, status, !(status & IPC_S= TATUS_BUSY), + 100, jiffies_to_usecs(IPC_TIMEOUT)); + if (err) + return err; =20 - status =3D ipc_read_status(scu); - if (!(status & IPC_STATUS_BUSY)) - return (status & IPC_STATUS_ERR) ? -EIO : 0; - - usleep_range(50, 100); - } while (time_before(jiffies, end)); - - return -ETIMEDOUT; + return (status & IPC_STATUS_ERR) ? -EIO : 0; } =20 /* Wait till ipc ioc interrupt is received or timeout in 10 HZ */ --=20 https://chromeos.dev From nobody Fri Dec 19 09:50:26 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24D16EE0212 for ; Wed, 13 Sep 2023 21:27:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232566AbjIMV1h (ORCPT ); Wed, 13 Sep 2023 17:27:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229743AbjIMV1c (ORCPT ); Wed, 13 Sep 2023 17:27:32 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5D041724 for ; Wed, 13 Sep 2023 14:27:28 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-68fb46f38f9so241927b3a.1 for ; Wed, 13 Sep 2023 14:27:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694640448; x=1695245248; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/kiTus1GQ2wpWYv2hiScbkUesx/S4YRwA/TTSZ+SSL4=; b=irWRL3Dhte1i12EFMTqrguyLoUPSaGHc1URlmZ4ILg/6UhpBKDkn1uiORA47RurTRr HbBMckPJCQ5HWE/fi2DItGu3CzIZSEn3F8xSRYyCi8EQiOTULT3US9aI+JgA/0EibUsS irsjZ7ugWpzAT8M00n9Egc6hiYVBG6ygIQe1k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694640448; x=1695245248; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/kiTus1GQ2wpWYv2hiScbkUesx/S4YRwA/TTSZ+SSL4=; b=T0E5D/dtZ2hsvgH6kX/qyRB17Z0DjVz6evDpwh4o5S4VxCFevgyRJYCCMRdIOrDfNU Jqg+I0AabV6oPtsB5yiZfsogBBYZQitiPI43pwS1Kqpk4CW56QsMWqPr3evuxROp9S6H foafImwsWWg+xlN9Wwe13rOj/JpIWdMIth9hAMS1Afxs5goRzn0Ta44C3tMtbixFWs1x pXOhKhnKDzxlhsuZV25JvjOPDFbZpvLNBcAmjwJNdhQjl74USLDA9MCRfUxEXDPyXpJw INDoEqOWoltQtYpcd/sgoYukou9PT7xu/52t3OZqmkMb1wTY99XMVyDG+BynubLE2atB 7qkA== X-Gm-Message-State: AOJu0Yy7AtTG4OZjSFKJrUsdPVgqgZyy9FBrER0UfcljYimSnpDMfXdZ 1AoeKQio3VC8HaC70s0AAJiLWw== X-Google-Smtp-Source: AGHT+IHkCpRGY5eNNzziS4Z0x0tJxKnxzcDaYv5kyCx0kSSKkvJ4n+5d/Sy4MX6b0nbFhT8NwHTsbg== X-Received: by 2002:a05:6a20:561a:b0:147:d861:50e4 with SMTP id ir26-20020a056a20561a00b00147d86150e4mr3072141pzc.33.1694640448396; Wed, 13 Sep 2023 14:27:28 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:11a:201:ae97:c6dc:1d98:494f]) by smtp.gmail.com with ESMTPSA id a10-20020a17090ad80a00b0025bdc3454c6sm1923976pjv.8.2023.09.13.14.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 14:27:27 -0700 (PDT) From: Stephen Boyd To: Mika Westerberg , Hans de Goede , Mark Gross Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, platform-driver-x86@vger.kernel.org, Andy Shevchenko , Kuppuswamy Sathyanarayanan , Prashant Malani Subject: [PATCH v4 2/4] platform/x86: intel_scu_ipc: Check status upon timeout in ipc_wait_for_interrupt() Date: Wed, 13 Sep 2023 14:27:20 -0700 Message-ID: <20230913212723.3055315-3-swboyd@chromium.org> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog In-Reply-To: <20230913212723.3055315-1-swboyd@chromium.org> References: <20230913212723.3055315-1-swboyd@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It's possible for the completion in ipc_wait_for_interrupt() to timeout, simply because the interrupt was delayed in being processed. A timeout in itself is not an error. This driver should check the status register upon a timeout to ensure that scheduling or interrupt processing delays don't affect the outcome of the IPC return value. CPU0 SCU ---- --- ipc_wait_for_interrupt() wait_for_completion_timeout(&scu->cmd_complete) [TIMEOUT] status[IPC_STATUS_B= USY]=3D0 Fix this problem by reading the status bit in all cases, regardless of the timeout. If the completion times out, we'll assume the problem was that the IPC_STATUS_BUSY bit was still set, but if the status bit is cleared in the meantime we know that we hit some scheduling delay and we should just check the error bit. Cc: Prashant Malani Reviewed-by: Kuppuswamy Sathyanarayanan Reviewed-by: Andy Shevchenko Reviewed-by: Mika Westerberg Fixes: ed12f295bfd5 ("ipc: Added support for IPC interrupt mode") Signed-off-by: Stephen Boyd --- drivers/platform/x86/intel_scu_ipc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/in= tel_scu_ipc.c index 4c774ee8bb1b..299c15312acb 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -248,10 +248,12 @@ static inline int ipc_wait_for_interrupt(struct intel= _scu_ipc_dev *scu) { int status; =20 - if (!wait_for_completion_timeout(&scu->cmd_complete, IPC_TIMEOUT)) - return -ETIMEDOUT; + wait_for_completion_timeout(&scu->cmd_complete, IPC_TIMEOUT); =20 status =3D ipc_read_status(scu); + if (status & IPC_STATUS_BUSY) + return -ETIMEDOUT; + if (status & IPC_STATUS_ERR) return -EIO; =20 --=20 https://chromeos.dev From nobody Fri Dec 19 09:50:26 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83503EE0211 for ; Wed, 13 Sep 2023 21:27:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232666AbjIMV1j (ORCPT ); Wed, 13 Sep 2023 17:27:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232173AbjIMV1e (ORCPT ); Wed, 13 Sep 2023 17:27:34 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E2CC1739 for ; Wed, 13 Sep 2023 14:27:30 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-68bed2c786eso247238b3a.0 for ; Wed, 13 Sep 2023 14:27:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694640450; x=1695245250; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0FSXe6bNCBpdZi03aeP0wSp6h1r1vEv3fBGeHHeswAM=; b=MN7B+0/aeKk1to07jMjepdo89gf4ksqoYzQfjr4H7Me4WC90DbPbmC2TTGyRU6cM26 PD+d+hcvJIElgIQV6yLgyJ7fxI2UV8/34U/VXU9CrPDjOPIHd2VhBGmIeI10AzOFcsKu VK7N/AWKRUQzFSI9TgoSpxLXIpkUfXW2wfBY8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694640450; x=1695245250; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0FSXe6bNCBpdZi03aeP0wSp6h1r1vEv3fBGeHHeswAM=; b=VdmhIqytpAaI9m34inT8//XF5oAn2EmLEovMw32G0MQcGLYuRpRKNb1WVXq2sHV/lD iP54b8QZk5FqFUFMIzJ+5kHNsyrkA9j8eXPvCc5/+l07gdt+HCcursD6YqX7Wjit5DW0 JLpXobQJMGhOObEDdTdvyjK7P44i3YF3JTroNHUWvNQqRxPrAmXIlohmqwey8qnAJfux A60HoXlhU98NZD9ganrL6a4S7e1HI1XvT0CgSawnTwZTsVSCM0ZUCLPl7M095G928hnZ Ldern5gPtqvfCp7ukXOr34JVYpplZGpVNJw8sAkln4Un2cfU49P9/Wczm713PdGCEI6r cYTQ== X-Gm-Message-State: AOJu0Yx+gNqb2eok5o4XvCdO8kG9lTKX3JHeP2HevSEdv9wERi4KMjHY do4/aGSB7fKXVP3rXuRGaJlx+Q== X-Google-Smtp-Source: AGHT+IHrBsutj053PgCBAoa/lMn4hSREkeQcGtlYOD1ODQzI8J5LrpGMDWvF5QcJgJC4rleFbOHPXw== X-Received: by 2002:a05:6a20:3d14:b0:152:8774:e1ab with SMTP id y20-20020a056a203d1400b001528774e1abmr4265873pzi.52.1694640449755; Wed, 13 Sep 2023 14:27:29 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:11a:201:ae97:c6dc:1d98:494f]) by smtp.gmail.com with ESMTPSA id a10-20020a17090ad80a00b0025bdc3454c6sm1923976pjv.8.2023.09.13.14.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 14:27:29 -0700 (PDT) From: Stephen Boyd To: Mika Westerberg , Hans de Goede , Mark Gross Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, platform-driver-x86@vger.kernel.org, Andy Shevchenko , Kuppuswamy Sathyanarayanan , Prashant Malani Subject: [PATCH v4 3/4] platform/x86: intel_scu_ipc: Don't override scu in intel_scu_ipc_dev_simple_command() Date: Wed, 13 Sep 2023 14:27:21 -0700 Message-ID: <20230913212723.3055315-4-swboyd@chromium.org> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog In-Reply-To: <20230913212723.3055315-1-swboyd@chromium.org> References: <20230913212723.3055315-1-swboyd@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Andy discovered this bug during patch review. The 'scu' argument to this function shouldn't be overridden by the function itself. It doesn't make any sense. Looking at the commit history, we see that commit f57fa18583f5 ("platform/x86: intel_scu_ipc: Introduce new SCU IPC API") removed the setting of the scu to ipcdev in other functions, but not this one. That was an oversight. Remove this line so that we stop overriding the scu instance that is used by this function. Reported-by: Andy Shevchenko Closes: https://lore.kernel.org/r/ZPjdZ3xNmBEBvNiS@smile.fi.intel.com Cc: Prashant Malani Reviewed-by: Andy Shevchenko Reviewed-by: Mika Westerberg Fixes: f57fa18583f5 ("platform/x86: intel_scu_ipc: Introduce new SCU IPC AP= I") Signed-off-by: Stephen Boyd Reviewed-by: Ilpo J=C3=A4rvinen --- drivers/platform/x86/intel_scu_ipc.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/in= tel_scu_ipc.c index 299c15312acb..3271f81a9c00 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -443,7 +443,6 @@ int intel_scu_ipc_dev_simple_command(struct intel_scu_i= pc_dev *scu, int cmd, mutex_unlock(&ipclock); return -ENODEV; } - scu =3D ipcdev; cmdval =3D sub << 12 | cmd; ipc_command(scu, cmdval); err =3D intel_scu_ipc_check_status(scu); --=20 https://chromeos.dev From nobody Fri Dec 19 09:50:26 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2C82EE020D for ; Wed, 13 Sep 2023 21:27:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232739AbjIMV1m (ORCPT ); Wed, 13 Sep 2023 17:27:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232319AbjIMV1f (ORCPT ); Wed, 13 Sep 2023 17:27:35 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 904A5173A for ; Wed, 13 Sep 2023 14:27:31 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-53fbf2c42bfso183617a12.3 for ; Wed, 13 Sep 2023 14:27:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694640451; x=1695245251; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q/wc8HkItTPJiIGmBh6ydt0pRRoKMzvmGRq2mSNptlY=; b=fF7HMN3KdU2SukU5x66c5UGp8hAb6HIIdQyYqzgs7JSV4wzNW/+ih11xKYI+iC9RLv hmHT/1UIJbkD79TkZSeuIQp9aDCAMI7dUQnik+JPyuw71pXKx0+94pR/FhaISepou0Kk 8BxJo3bTchjg4DLgxixeA9lXn0qOZYXI20R6s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694640451; x=1695245251; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q/wc8HkItTPJiIGmBh6ydt0pRRoKMzvmGRq2mSNptlY=; b=dsp8Io/6K8TOvFNIPjluFmimuYQyR/eA8nviqw0htw1Zg78QpKAc2Wgt+vllfhyB3u kQTKCC1ep55CvHxXpodzahn/52B/EGSwaaE+EwQ9C/DJl4yr6uKQyWz3pAW+/nX6CJri sYSk42Z+SGpWb5BxQh6hBpIFvuCPE7LwEMTaxBm3hm0g40xnX/pSH9St1gelXQpTj6Dy OAOiWhLBrFolJDwEMkg33t/i/5sxOSO60rjhVH+gf1OcW8W3Qk0/bLvXPBwIhdxemJS+ 5jhGggWzmX3YTwq3GJp4RhZS5Jk/NiFMRsjrHm5DjSgK/Qqds9Mw4JKrqyUDNLxsRRJJ YHdw== X-Gm-Message-State: AOJu0Yy+wp3x94zQGOznaJR45iR3LLR9fKzwDXBG75IfgqWzkB3ueXR+ rCoQgOzhqb1wpwue6Fio5dJtzA== X-Google-Smtp-Source: AGHT+IHm0OGkEzrdNohUUUOckuJKxRgfCh2mx2y/pIINxq8HCns3limX90AeFbPOw2bqURkm6q6NcQ== X-Received: by 2002:a17:90b:4a88:b0:262:f449:4497 with SMTP id lp8-20020a17090b4a8800b00262f4494497mr3595415pjb.2.1694640451077; Wed, 13 Sep 2023 14:27:31 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:11a:201:ae97:c6dc:1d98:494f]) by smtp.gmail.com with ESMTPSA id a10-20020a17090ad80a00b0025bdc3454c6sm1923976pjv.8.2023.09.13.14.27.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 14:27:30 -0700 (PDT) From: Stephen Boyd To: Mika Westerberg , Hans de Goede , Mark Gross Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, platform-driver-x86@vger.kernel.org, Andy Shevchenko , Kuppuswamy Sathyanarayanan , Prashant Malani Subject: [PATCH v4 4/4] platform/x86: intel_scu_ipc: Fail IPC send if still busy Date: Wed, 13 Sep 2023 14:27:22 -0700 Message-ID: <20230913212723.3055315-5-swboyd@chromium.org> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog In-Reply-To: <20230913212723.3055315-1-swboyd@chromium.org> References: <20230913212723.3055315-1-swboyd@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It's possible for interrupts to get significantly delayed to the point that callers of intel_scu_ipc_dev_command() and friends can call the function once, hit a timeout, and call it again while the interrupt still hasn't been processed. This driver will get seriously confused if the interrupt is finally processed after the second IPC has been sent with ipc_command(). It won't know which IPC has been completed. This could be quite disastrous if calling code assumes something has happened upon return from intel_scu_ipc_dev_simple_command() when it actually hasn't. Let's avoid this scenario by simply returning -EBUSY in this case. Hopefully higher layers will know to back off or fail gracefully when this happens. It's all highly unlikely anyway, but it's better to be correct here as we have no way to know which IPC the status register is telling us about if we send a second IPC while the previous IPC is still processing. Cc: Prashant Malani Cc: Kuppuswamy Sathyanarayanan Reviewed-by: Andy Shevchenko Reviewed-by: Mika Westerberg Fixes: ed12f295bfd5 ("ipc: Added support for IPC interrupt mode") Signed-off-by: Stephen Boyd Reviewed-by: Ilpo J=C3=A4rvinen --- drivers/platform/x86/intel_scu_ipc.c | 40 +++++++++++++++++++--------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/in= tel_scu_ipc.c index 3271f81a9c00..a68df4133403 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -265,6 +265,24 @@ static int intel_scu_ipc_check_status(struct intel_scu= _ipc_dev *scu) return scu->irq > 0 ? ipc_wait_for_interrupt(scu) : busy_loop(scu); } =20 +static struct intel_scu_ipc_dev *intel_scu_ipc_get(struct intel_scu_ipc_de= v *scu) +{ + u8 status; + + if (!scu) + scu =3D ipcdev; + if (!scu) + return ERR_PTR(-ENODEV); + + status =3D ipc_read_status(scu); + if (status & IPC_STATUS_BUSY) { + dev_dbg(&scu->dev, "device is busy\n"); + return ERR_PTR(-EBUSY); + } + + return scu; +} + /* Read/Write power control(PMIC in Langwell, MSIC in PenWell) registers */ static int pwr_reg_rdwr(struct intel_scu_ipc_dev *scu, u16 *addr, u8 *data, u32 count, u32 op, u32 id) @@ -278,11 +296,10 @@ static int pwr_reg_rdwr(struct intel_scu_ipc_dev *scu= , u16 *addr, u8 *data, memset(cbuf, 0, sizeof(cbuf)); =20 mutex_lock(&ipclock); - if (!scu) - scu =3D ipcdev; - if (!scu) { + scu =3D intel_scu_ipc_get(scu); + if (IS_ERR(scu)) { mutex_unlock(&ipclock); - return -ENODEV; + return PTR_ERR(scu); } =20 for (nc =3D 0; nc < count; nc++, offset +=3D 2) { @@ -437,12 +454,12 @@ int intel_scu_ipc_dev_simple_command(struct intel_scu= _ipc_dev *scu, int cmd, int err; =20 mutex_lock(&ipclock); - if (!scu) - scu =3D ipcdev; - if (!scu) { + scu =3D intel_scu_ipc_get(scu); + if (IS_ERR(scu)) { mutex_unlock(&ipclock); - return -ENODEV; + return PTR_ERR(scu); } + cmdval =3D sub << 12 | cmd; ipc_command(scu, cmdval); err =3D intel_scu_ipc_check_status(scu); @@ -482,11 +499,10 @@ int intel_scu_ipc_dev_command_with_size(struct intel_= scu_ipc_dev *scu, int cmd, return -EINVAL; =20 mutex_lock(&ipclock); - if (!scu) - scu =3D ipcdev; - if (!scu) { + scu =3D intel_scu_ipc_get(scu); + if (IS_ERR(scu)) { mutex_unlock(&ipclock); - return -ENODEV; + return PTR_ERR(scu); } =20 memcpy(inbuf, in, inlen); --=20 https://chromeos.dev