Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp1942985rdb; Tue, 5 Sep 2023 09:24:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZz50UwjuRC79CUu6p0Pwq67BuWRQ/GO+APP3/ZKULqC6Go56x2KVjFfmQCdg/HUkfrCI0 X-Received: by 2002:a05:6512:348b:b0:500:98ff:4162 with SMTP id v11-20020a056512348b00b0050098ff4162mr249814lfr.40.1693931083476; Tue, 05 Sep 2023 09:24:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693931083; cv=none; d=google.com; s=arc-20160816; b=H+pjRhudO0/1/8g4wOXWVgzb5JsN2dSkK0XX+QgJV1bVOdXkCPq4rhkkAWzwzCfbDz P2y5wrD9X6tLdxudXtQMXzlqGRDJLGRai111Y8pWLvthmFt4Iv7Pz38+7RZux4Zbw6jr 8mvPYOLzJU8NHfclAV85QJaVLDnEj5u9akF34o1rdK3VRoRfPN1YcIv54vqgFMdGgysa T7wxGyVUSmSX5cmXPubDs6tdgQE5Heb4yCeQhSwOCDeRQZMymz4xxdclG70oTPF0/yIm Y27wc8EzulRq0UsLeFqJyEp3VZ9tSglAnLHbDCJCwa0ES46mB2tXr0cMwKWQGKNzTFmE 2eZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=1KO3cGtZNb6YBOJqVkOYtkUYBgStxNO2aXl8NS3rMXw=; fh=9AEOr0li2JaGGZ8GrLy4PDxyCdJTgwX+YE1VTs0mVmY=; b=jiJXQehg+0Fvla4o8GU7gcblojLi1YF9pHE47zPihTqcpOBn4b8gpjc9i+nPrCUay8 AHY+eskIaVex2yziBf/rkcQhZ4AHnDQvPdQWVlff3/SQ4IUd+4oVHeYUpRfSkm5TnETG sgUxvJJwGzBDDkApOqILnqK40X4LItHe0CBTXuBUZAGd1NAMxn3vG990TWjp+nmtkiUS pvaDxfUYe9TxqTXYGRBUXiQ/hWY3haWXLHJJ/lg4Wfa/uQk9mS8lZ0kEAZjnypB3NBwT E+E+f6/NNsmm907U5B7a8L2+VEpNugnupAZK/9UDe9QJYxbWKFH77xj+ETWGdfcbt3K7 pbGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hrvarstX; 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 oq8-20020a170906cc8800b009a5e55d5825si7717742ejb.382.2023.09.05.09.24.38; Tue, 05 Sep 2023 09:24:43 -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=hrvarstX; 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 S1345566AbjIAFuV (ORCPT + 9 others); Fri, 1 Sep 2023 01:50:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229829AbjIAFuT (ORCPT ); Fri, 1 Sep 2023 01:50:19 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B579B10C4; Thu, 31 Aug 2023 22:50:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1693547415; x=1725083415; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=VCwDKR0+XuajmyREC4vrMp5tg6MbHHMUwY4gC4BjQC8=; b=hrvarstXzYZh4VUqGqfjfRFxpQYSmSkt5R3ozJ1EnsktPyENgudj4lID XdPCYIpqx+1qzqTCRO6u77x/WdetswcNWS7EegYcKTMx9WhJn4BRoSU/8 uzOyh1/QZ2EYQYWBnawb7gUzgR3/wrRpnzG3UleSf2p5xtuhKQlBCOhSC LFzvWn8TQtz0Z1TO40y7in3eFMguFsrUvvwTQt8O7D2i5eFMUEaljrh4Y 1EeLDItDJXJaRN7wPFhIPPY+FU7zyGIrAzssc3GX8X1j/sPKQe2TAdpth VWoyQrgzTuK8je9/H8pVlf1MAs/9AWeSj7RK6pnvOupa50Pk9VUfdiIgR Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10819"; a="440123006" X-IronPort-AV: E=Sophos;i="6.02,218,1688454000"; d="scan'208";a="440123006" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Aug 2023 22:50:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10819"; a="1070608229" X-IronPort-AV: E=Sophos;i="6.02,218,1688454000"; d="scan'208";a="1070608229" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga005.fm.intel.com with ESMTP; 31 Aug 2023 22:50:12 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 1DA06DE; Fri, 1 Sep 2023 08:50:11 +0300 (EEST) Date: Fri, 1 Sep 2023 08:50:11 +0300 From: Mika Westerberg To: Stephen Boyd Cc: Hans de Goede , Mark Gross , linux-kernel@vger.kernel.org, patches@lists.linux.dev, platform-driver-x86@vger.kernel.org, Andy Shevchenko , Kuppuswamy Sathyanarayanan , Prashant Malani Subject: Re: [PATCH 1/3] platform/x86: intel_scu_ipc: Check status after timeouts in busy_loop() Message-ID: <20230901055011.GT3465@black.fi.intel.com> References: <20230831011405.3246849-1-swboyd@chromium.org> <20230831011405.3246849-2-swboyd@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230831011405.3246849-2-swboyd@chromium.org> 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 Wed, Aug 30, 2023 at 06:14:01PM -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); > > if (!(status & IPC_STATUS_BUSY)) How can the status bit change here as we are the only user and the SCU access is serialized by ipclock? > 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. > > The read_poll_timeout() helper implements this logic, and is shorter, so > simply use that helper here. Yes, I agree it makes the code simpler. > Cc: Prashant Malani > Cc: Andy Shevchenko > Fixes: e7b7ab3847c9 ("platform/x86: intel_scu_ipc: Sleeping is fine when polling") > Signed-off-by: Stephen Boyd > --- > 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 */ > -- > https://chromeos.dev