From nobody Wed Feb 11 18:27:20 2026 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 7E927CA0EC3 for ; Mon, 11 Sep 2023 21:39:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349794AbjIKVex (ORCPT ); Mon, 11 Sep 2023 17:34:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244217AbjIKTjr (ORCPT ); Mon, 11 Sep 2023 15:39:47 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FCE51B8 for ; Mon, 11 Sep 2023 12:39:42 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-26d50a832a9so3339579a91.3 for ; Mon, 11 Sep 2023 12:39:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694461182; x=1695065982; 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=gdCNmE4TQzaUVGYBpjExxVlAWo5NcVTWN45t1mLK2Kw=; b=ogpttftmeuGXskkeyI7t4md+uLYnvUs0J/Pn3eJnYCUi/XytZcLFKUOVj3ijBzWBnO lJlDS1XHOVyvuJSBwO2U8D49Cx1zJ3IJSWBDxs2I/hGrWFvW1G+Q7AhJEaqoDt5mG7Fs QoHCsnruJJxVE7zckenLWst++1VoWlgJV8HGs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694461182; x=1695065982; 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=gdCNmE4TQzaUVGYBpjExxVlAWo5NcVTWN45t1mLK2Kw=; b=mdiuWQd2Gx2fGkCLJWgejcILGgqE/f+T9lU5iFm/VPhfCq2hYoaf8oubywFkzyrF16 2dP784ZoQRAbYPbkfBh2eBkMvQ+WzNh5Ra/csoQUIEqlHDSbKKSpxh7lFHF/eOyIKE6v T+6o7g7pMUW4sJVLlW2KCrUtT0ugd4GPhv34F4V38b+EMhVlMm1HH+zqI1Z0Pt502lZp o1VPDrXW+bHPYVH74PpX2D35E2AB0HAANIIEBt0NCp5eeemTtp8Dos3/VKuMLsZeu1I4 lfC0AnKvDHWzKIZzA3gaGo0BsGoVziy0eRcxsYWEXNhhQTOdldK+IQ8NJ42Td93TU3S1 ZTPg== X-Gm-Message-State: AOJu0YyWWjhI3s2oqjoSb4cy4Ty9RkQCFo6MbIKAIirWHMx5eYFysd8x V3aeY9dAXI5PHN/Gw5yxh/VU6g== X-Google-Smtp-Source: AGHT+IGGvlqWnCd6FgKie+c4RBzySbl2Wtfy49TuNcsKhZkbb20DCZlYeRe7ju+YlMJNU0euA/ADjA== X-Received: by 2002:a17:90a:c246:b0:263:ebab:a152 with SMTP id d6-20020a17090ac24600b00263ebaba152mr8240717pjx.19.1694461181946; Mon, 11 Sep 2023 12:39:41 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:11a:201:d487:5e33:6656:3711]) by smtp.gmail.com with ESMTPSA id fu8-20020a17090ad18800b00262e485156esm7736543pjb.57.2023.09.11.12.39.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 12:39:41 -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 v3 1/4] platform/x86: intel_scu_ipc: Check status after timeout in busy_loop() Date: Mon, 11 Sep 2023 12:39:33 -0700 Message-ID: <20230911193937.302552-2-swboyd@chromium.org> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog In-Reply-To: <20230911193937.302552-1-swboyd@chromium.org> References: <20230911193937.302552-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 read_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 read_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 Cc: Andy Shevchenko Fixes: e7b7ab3847c9 ("platform/x86: intel_scu_ipc: Sleeping is fine when po= lling") Signed-off-by: Stephen Boyd Reviewed-by: Andy Shevchenko Reviewed-by: Kuppuswamy Sathyanarayanan Reviewed-by: Mika Westerberg --- 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..5a37becc65aa 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 read_poll_timeout(ipc_read_status, status, !(status & IPC_STATUS_= BUSY), + 100, jiffies_to_usecs(IPC_TIMEOUT), false, scu); + 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 Wed Feb 11 18:27:20 2026 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 111ECCA0EC3 for ; Mon, 11 Sep 2023 23:02:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349767AbjIKVer (ORCPT ); Mon, 11 Sep 2023 17:34:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244219AbjIKTjs (ORCPT ); Mon, 11 Sep 2023 15:39:48 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 055CC18D for ; Mon, 11 Sep 2023 12:39:44 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-273e1aec35aso2141848a91.1 for ; Mon, 11 Sep 2023 12:39:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694461183; x=1695065983; 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=kZYrHnobXTh0OSmcxOutmTVdFw75ZwDUd6CgfQDQ3MU=; b=jkpQtQkf9CmjnLo2qkfbo+ma1IvYZZrIkQVDU8FeE0rGYwCLnaZ2QYzS8PTcjwpEkk 1pVi5tfGDk1WtalnGLnTbYe/2N+3rHKrQd4u/ghEXLcE1/AyKTwPwD/R3JOjTOc77lcQ YWZPU8SZpMWz3iF+GZsj9IikXLe19fEeZYRiI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694461183; x=1695065983; 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=kZYrHnobXTh0OSmcxOutmTVdFw75ZwDUd6CgfQDQ3MU=; b=mRQBFfvHlOV6ln8I1RLR4qF8cM0Ub0sGMZUvzfz1AwkuigM7pNoDZBytXg+ncIbHkb r/X8n8/dJwvu8tdC2tpEdrU/kCwXbufEBvLJKJV6/sgiewpVMVjkkZ59fPnHD1mANxtA 2Z1c92Aw+j1QnVn8Cs5Znsg/TFpvUUS+xzPMwXAXkaK1TToeONmFvy5JIpEXSeFQwiw1 l4RyiorISez3h25Nq/r22xOLsCRqZ+pipmmwAJvcmuXpPU28s/nS/JRqzo7I66+BHTYm maaYdEPaX8HkfqlMDx31Vdb/rS5SAOpUIak7cER8pUXlbmUOink9e4brqo4x1OVh3axf 0PXQ== X-Gm-Message-State: AOJu0Yx8mZ/+SRIRtN3WnR73DKccGblT1IMxSgHbP4LlTFdnEU9tq9FL NUupDyzSf/JMSdRb6DIUKU5PmQ== X-Google-Smtp-Source: AGHT+IGOfdGvbw1wwt4Gf9ldbs/gHOpAtrlGyNreNjdfdz8lCBCPYU+3AOX6Bw9QrL5rSH9U2KMdvA== X-Received: by 2002:a17:90a:3481:b0:268:557e:1848 with SMTP id p1-20020a17090a348100b00268557e1848mr8154453pjb.2.1694461183460; Mon, 11 Sep 2023 12:39:43 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:11a:201:d487:5e33:6656:3711]) by smtp.gmail.com with ESMTPSA id fu8-20020a17090ad18800b00262e485156esm7736543pjb.57.2023.09.11.12.39.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 12:39:42 -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 v3 2/4] platform/x86: intel_scu_ipc: Check status upon timeout in ipc_wait_for_interrupt() Date: Mon, 11 Sep 2023 12:39:34 -0700 Message-ID: <20230911193937.302552-3-swboyd@chromium.org> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog In-Reply-To: <20230911193937.302552-1-swboyd@chromium.org> References: <20230911193937.302552-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 Fixes: ed12f295bfd5 ("ipc: Added support for IPC interrupt mode") Signed-off-by: Stephen Boyd Reviewed-by: Mika Westerberg --- 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 5a37becc65aa..8be1686e22e9 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 Wed Feb 11 18:27:20 2026 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 55B79CA0EC0 for ; Mon, 11 Sep 2023 21:39:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349691AbjIKVeb (ORCPT ); Mon, 11 Sep 2023 17:34:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244224AbjIKTjt (ORCPT ); Mon, 11 Sep 2023 15:39:49 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7634612A for ; Mon, 11 Sep 2023 12:39:45 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1c397ed8681so17377495ad.2 for ; Mon, 11 Sep 2023 12:39:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694461185; x=1695065985; 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=iZS9exdhsXGWlwAB3PPHAHPTpMkYjkQ66zHV37ZNnIo=; b=VJFdmIKkhv/Q+m+JOoiFKhTBZ+rrK10LCUqGXdzbKbRxyxO8VMsfe8fPD8KOMRWZcf vU251VLuJpCuLwTAwx+e6hWYNi3DA5QOlKgv1LHZqM+kzklQD7DMAFRt5+hB4T2AYork SLJZF2nasOAcgpLboG144l4aqhJkoSBMSfExM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694461185; x=1695065985; 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=iZS9exdhsXGWlwAB3PPHAHPTpMkYjkQ66zHV37ZNnIo=; b=Ozky3k4H23xe2Zevm91Lg1GKs+HAg49XgQ4iI141/Ebk5zwN+D6cH+EYRncjQlKNxS VrhopCpfMtu1qQ0g0mbKgaeKfqwUrk+agSoQ8izucnpBmEeALDM6F3ugCTEV36Ws1Vk/ ArclOb6CoElWyYZ+QgXlr74hIg5TADu3CBO/pgEtUjZWZJdRFhf1goLrnrfSbln2L0/U 2yTVp13Lyi4y7c/hseXDTAEnGRc/84h9LU4jGoQIRnnU4S2FQPqs7CKzOVdCnfMkS3hi WJX5L7zJMWWQYK3RuI2eKj8PCI7kQ1Oyf0PvTQWe177bxRXQwdId/ZCEXAOPu07xet+M g/zg== X-Gm-Message-State: AOJu0Yz3S8uFB4xSomSk5w+h34fBVQwhLDp9T6dA0gdQPWtOECdmz45F GvDbPxN64DHZNAPFXnOzFl7I5f6WKmv9o8jLdPI= X-Google-Smtp-Source: AGHT+IE7TogpeCC/K5uuUl78NkURxmB6xAcGOF09QSqED+BJ2qE4ZV0Dxs2vBHRHl4QM+fNIhII6jQ== X-Received: by 2002:a17:90b:164e:b0:268:10a3:cea8 with SMTP id il14-20020a17090b164e00b0026810a3cea8mr8146677pjb.9.1694461184937; Mon, 11 Sep 2023 12:39:44 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:11a:201:d487:5e33:6656:3711]) by smtp.gmail.com with ESMTPSA id fu8-20020a17090ad18800b00262e485156esm7736543pjb.57.2023.09.11.12.39.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 12:39:44 -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 v3 3/4] platform/x86: intel_scu_ipc: Don't override scu in intel_scu_ipc_dev_simple_command() Date: Mon, 11 Sep 2023 12:39:35 -0700 Message-ID: <20230911193937.302552-4-swboyd@chromium.org> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog In-Reply-To: <20230911193937.302552-1-swboyd@chromium.org> References: <20230911193937.302552-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 Fixes: f57fa18583f5 ("platform/x86: intel_scu_ipc: Introduce new SCU IPC AP= I") Signed-off-by: Stephen Boyd Reviewed-by: Andy Shevchenko Reviewed-by: Mika Westerberg --- 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 8be1686e22e9..6958265db29d 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 Wed Feb 11 18:27:20 2026 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 F008BCA0EC5 for ; Mon, 11 Sep 2023 21:10:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240009AbjIKVE3 (ORCPT ); Mon, 11 Sep 2023 17:04:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244227AbjIKTjv (ORCPT ); Mon, 11 Sep 2023 15:39:51 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA42518D for ; Mon, 11 Sep 2023 12:39:46 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-26f57f02442so3366304a91.0 for ; Mon, 11 Sep 2023 12:39:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694461186; x=1695065986; 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=CIfVld1coOvYARfYOzv2HqS0W6bVI+gXrtF9tymreUw=; b=N5KkZQsYv+I/nM/ltGRxMeZbJkCLnA7UWVMxaas4RQxp2G/2juc+8Njt2f1+Jw+L1y 8WTCeD4Ga2Pz8lb8bbhAq5tQwg/F8hJ0xpHKvPL3QlVOGra+BnghOJUXXRjE2pcjPsVv VCFyjuee00x/Fl7GHHsPA1KpGD90T7EH7hlVE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694461186; x=1695065986; 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=CIfVld1coOvYARfYOzv2HqS0W6bVI+gXrtF9tymreUw=; b=vss70+3SommfQvz8QE889UQuQw2nDzY9SJsWs92Tl/IZ/aQ1C1DwxciFHPiJ6F0Dci lPlXsv2mXuCBdIz9+9kElsCjJ6ct6XdPLU0/KpaaXQSnWTxrDfel8hk0ji5kTvwo0ldO p8k3XgcHzI3FiqfaU6J3+bD89LW3CTG4uMwUi4EK4eGn5mrUq7mRPvuZkmisKh8FGDtc REO6KaN5YfVJTUFpGKAuV9OVL5K9iJTa4lXkU4VCIz83vhoBvlCT4+0cRKoaJKSrDCv9 NaVNDxLwnbCY52tP2/sQRNifIdpYWQFMaJ/27dHVQ/GsvpusoEAYL5HW1JNmHdJsdinV 74lQ== X-Gm-Message-State: AOJu0YxqTpMljPy440nOMaa7JwN+WLGN0hEYdFhOd6Iq8Mch502DyykU FmNj3uNZWNRMsZj6Q7TR49dBOw== X-Google-Smtp-Source: AGHT+IEJD9aaS/paLlM3NnqHlPKypKmKoRzToVoKSA/lBjh/RRD+ka+skD5NVC21QofiO/2bL20UVQ== X-Received: by 2002:a17:90b:1c0f:b0:273:ee6c:ee5c with SMTP id oc15-20020a17090b1c0f00b00273ee6cee5cmr5142476pjb.7.1694461186242; Mon, 11 Sep 2023 12:39:46 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:11a:201:d487:5e33:6656:3711]) by smtp.gmail.com with ESMTPSA id fu8-20020a17090ad18800b00262e485156esm7736543pjb.57.2023.09.11.12.39.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 12:39:45 -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 v3 4/4] platform/x86: intel_scu_ipc: Fail IPC send if still busy Date: Mon, 11 Sep 2023 12:39:36 -0700 Message-ID: <20230911193937.302552-5-swboyd@chromium.org> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog In-Reply-To: <20230911193937.302552-1-swboyd@chromium.org> References: <20230911193937.302552-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 Fixes: ed12f295bfd5 ("ipc: Added support for IPC interrupt mode") Signed-off-by: Stephen Boyd Reviewed-by: Andy Shevchenko Reviewed-by: Mika Westerberg --- 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 6958265db29d..c5b15450598e 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