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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7A5ECA0ED0 for ; Mon, 11 Sep 2023 22:47:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379279AbjIKWmJ (ORCPT ); Mon, 11 Sep 2023 18:42:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352967AbjIKVqO (ORCPT ); Mon, 11 Sep 2023 17:46:14 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 083A81DC9E; Mon, 11 Sep 2023 14:18:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694467111; x=1726003111; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=OvOywvaVgqf7GXCTK6i+HE3r8bZumInwL/UZ2w6I2+s=; b=Ffr1y9IawzNxbrNNPNUC+BxWY2IAJOk7jVjRR9FBh5H/SMM8Cqfu2qjP r2zTL0iM2+ZtzUjZnIeuZSEOpwGumE+WVGgUOQozSss2ijNJZB+638QfF hWbVFjC+agmu6C4A2iKudbLxmtY0fGnC300/Ipr1CXGDjzCcup6aeUsEP G8vMmPmJKwCTX3TRS9hDnamt5mYHW2pFL0ny0qgkpCqGkI+o0loMvFpZX 91YgjU9U2/mWKnOl9iTZNZBhKjV2u/aEWro8zEmmpLx9uAeAVEUb6Q2VP gu0aXtVvjX3/kEd2NBw5eZ3PdITxoCUw7uXGbDBgD9j0dfN8S9LNoK8l8 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10830"; a="409166246" X-IronPort-AV: E=Sophos;i="6.02,244,1688454000"; d="scan'208";a="409166246" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Sep 2023 14:17:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10830"; a="720129941" X-IronPort-AV: E=Sophos;i="6.02,244,1688454000"; d="scan'208";a="720129941" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga006.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Sep 2023 14:17:25 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1qfoHa-008QTA-1i; Tue, 12 Sep 2023 00:17:22 +0300 Date: Tue, 12 Sep 2023 00:17:22 +0300 From: Andy Shevchenko To: Stephen Boyd Cc: Mika Westerberg , Hans de Goede , Mark Gross , linux-kernel@vger.kernel.org, patches@lists.linux.dev, platform-driver-x86@vger.kernel.org, Kuppuswamy Sathyanarayanan , Prashant Malani Subject: Re: [PATCH v3 1/4] platform/x86: intel_scu_ipc: Check status after timeout in busy_loop() Message-ID: References: <20230911193937.302552-1-swboyd@chromium.org> <20230911193937.302552-2-swboyd@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230911193937.302552-2-swboyd@chromium.org> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 11, 2023 at 12:39:33PM -0700, 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); // status = 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. ... > + err = read_poll_timeout(ipc_read_status, status, !(status & IPC_STATUS_BUSY), > + 100, jiffies_to_usecs(IPC_TIMEOUT), false, scu); Since "false" you probably can utilize readx_poll_timeout(). > + if (err) > + return err; > -- With Best Regards, Andy Shevchenko