Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp1941034rdb; Tue, 5 Sep 2023 09:21:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGnGhZNmd6afbqZTK/auS3ZkjKeiN5yrWqA0oicfyF8CDDeTqrlqnGytS1oSYOsHNe36mow X-Received: by 2002:aa7:da81:0:b0:522:30cc:a1eb with SMTP id q1-20020aa7da81000000b0052230cca1ebmr311127eds.0.1693930912615; Tue, 05 Sep 2023 09:21:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693930912; cv=none; d=google.com; s=arc-20160816; b=xIacR+0cdMSvqYhCAsVPQlLktDDkQf43ZBOyWRs+K4ZwDcowTeuR84oy1nz1pR3UO/ sDZzS02svCoVOhQn3oB0TkNtnqAR7hnUDIu1KnxCQa3eFvrpgQIOrWWvgPWBatqQqKoG VxjLqn8vq0WJIgsHMKFAjoo3ma8+gEfhnttqfUL+7RTeAUkJlyAW5jjJBs7YpIr5ImR2 QozFN1/sU67gYuzdwktCrEFxE+2bZOcRMqs3q320vn1EE+SMLIFQAQjWXXSumleryGlP oJo8RS0sPCzy8V2U/mEJkkhWYP3SjFEjVAgZMePrmhd2w21H1+TmKprOyhl5Rih2c0oC YYiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=Yqn2dTEwYPPcSuNrXjaXU1lzK+/3oBC1sgaTEPb2lbw=; fh=rkCGCyaUanfIBh/kPmD7Og9983sD4XZZAz7CtzWNOFg=; b=x6VkJnUDAmglzPqU6+pvR38n680cmzga0xUPxj0UUo6O8BLAmZsRVDrpuO0CUil6p6 xt4oTYaEZ0jZJiDjGq0f4D9XQVBmznox+9qS/5cym6MdCB2GPgLwCTEYqK1GhFCxcnQT 5un3Az7cEcTEuNFQuZ2TG4zp37qcDEVpo7LfytKVfiq9j3zgu0wNcv7/4jdk3P1fcfTP tEKSVlT9Axwjtc4dJsP9FemOFi+WwLilS018PanIu7ihJG94mCaqLfaoA8JTkEMSyuaQ ldZNPZhPA3VKG4bNYeyylT6hDSHT5sh6x017wIS7oHiLrucHmXuhYYcbPsQCW5ZrN4L9 PgMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BSxltfCq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r11-20020aa7d14b000000b00527231b121fsi8134629edo.31.2023.09.05.09.21.49; Tue, 05 Sep 2023 09:21:52 -0700 (PDT) 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; dkim=pass header.i=@intel.com header.s=Intel header.b=BSxltfCq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346428AbjHaOVo (ORCPT + 8 others); Thu, 31 Aug 2023 10:21:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346431AbjHaOVl (ORCPT ); Thu, 31 Aug 2023 10:21:41 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47634FB; Thu, 31 Aug 2023 07:21:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1693491693; x=1725027693; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=7WT3EG9zGp7Fa0vDneWL1fnehQfIMEL/lXJrnlpi7YU=; b=BSxltfCqhlzvq1ULT1CgFUpYV03x7LYzzWfi5Oia4jVRF1JdPZr5f06r FfSJceRoUPlyFx5ozUtUnhJut/HqYeQ+e2rVDoNgtYr5vwAPeZWEAQ0Hl eYEfAkRSeDCUPGWzRadqTHwFBc1dM/TsnQBUCz8MQ8Ukjq5jaXp0Eb7s0 q3Ee9uOnSTmbDsVrl/VOztPymQPt0e83SivAjAzGMfDLyF66+aa6haR8K f1w1Z7V35zttRvJS7pGsYLLOpLV0xIgWFgLTKdXicPFbkPiaJ2W8mSajF Syg8TrRtJa34a4uWgzbsCaKWkK9LVNwEEmoqEMNt6mh25L8w7N9fZPTCu A==; X-IronPort-AV: E=McAfee;i="6600,9927,10819"; a="355456355" X-IronPort-AV: E=Sophos;i="6.02,217,1688454000"; d="scan'208";a="355456355" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Aug 2023 07:15:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10819"; a="805013471" X-IronPort-AV: E=Sophos;i="6.02,217,1688454000"; d="scan'208";a="805013471" Received: from bcnelson-mobl2.amr.corp.intel.com (HELO [10.209.16.42]) ([10.209.16.42]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Aug 2023 07:15:11 -0700 Message-ID: Date: Thu, 31 Aug 2023 07:15:11 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/3] platform/x86: intel_scu_ipc: Check status after timeouts in busy_loop() Content-Language: en-US To: Stephen Boyd , 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 , Prashant Malani References: <20230831011405.3246849-1-swboyd@chromium.org> <20230831011405.3246849-2-swboyd@chromium.org> From: Kuppuswamy Sathyanarayanan In-Reply-To: <20230831011405.3246849-2-swboyd@chromium.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,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 On 8/30/2023 6:14 PM, Stephen Boyd wrote: > It's possible for the polling loop in busy_loop() to get scheduled away > for a long time. > > status = ipc_read_status(scu); > > if (!(status & IPC_STATUS_BUSY)) > > If this happens, then the status bit could change and this function > would never test it again after checking the jiffies against the timeout > limit. Polling code should check the condition one more time after the > timeout in case this happens. I think it is not checking the condition, but reading the status one more time to reflect the latest status. > > The read_poll_timeout() helper implements this logic, and is shorter, so > simply use that helper here. > > Cc: Prashant Malani > Cc: Andy Shevchenko > Fixes: e7b7ab3847c9 ("platform/x86: intel_scu_ipc: Sleeping is fine when polling") > Signed-off-by: Stephen Boyd > --- Otherwise code looks fine to me. Reviewed-by: Kuppuswamy Sathyanarayanan > 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/intel_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 > > @@ -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 = jiffies + IPC_TIMEOUT; > - > - do { > - u32 status; > - > - status = ipc_read_status(scu); > - if (!(status & IPC_STATUS_BUSY)) > - return (status & IPC_STATUS_ERR) ? -EIO : 0; > + u8 status; > + int err; > > - usleep_range(50, 100); > - } while (time_before(jiffies, end)); > + err = read_poll_timeout(ipc_read_status, status, !(status & IPC_STATUS_BUSY), > + 100, jiffies_to_usecs(IPC_TIMEOUT), false, scu); > + if (err) > + return err; > > - return -ETIMEDOUT; > + return (status & IPC_STATUS_ERR) ? -EIO : 0; > } > > /* Wait till ipc ioc interrupt is received or timeout in 10 HZ */ -- Sathyanarayanan Kuppuswamy Linux Kernel Developer