Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3354251ybt; Mon, 22 Jun 2020 23:33:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnvvu6IKMoN4zdAOw4EF0cjNmS/Qu0Dq0yekPds42wqf27hODWJTtrDMYS2qjsbkpLj5Jo X-Received: by 2002:a17:907:a92:: with SMTP id by18mr2054877ejc.116.1592893989943; Mon, 22 Jun 2020 23:33:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592893989; cv=none; d=google.com; s=arc-20160816; b=nIxeSNQoLsUvWH5QKgU+n8J8MBcSEqNDGAvrM86IAQB5TViMdlZxZOFVTo19uhHKgE xI0jD7aWiqlQ9TBFrLQ0QWkQCD+xTppl/5ASjXqkdyphWzblBmlTQaGCM+oqHIAAzASU CX/vxinhUiGVqDbTeBIHnYkeFWMSuXAmxgHmp6IgMmE2ywpHyuWoHrRjKC1HNQjNs6vL wjO37tdqBja8SQOVBcevtSv55jx8ywPKXB1xnZxCs000RW45N66uu2a2+FbMoZl9JvPH OGXDiD+2UKC9vJWhEDwUmoEdotq8wzhOmJe7ddpEoznux5Vc7wwCj91CrylDo7Ls/6U9 MmZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:ironport-sdr:ironport-sdr; bh=5IFsue4hQagax6w7hgJO0QGjkPO/aX13I+cO22Kup7Q=; b=PiTQTkslFIs9wWC3T0Nz3czzOqTkPEpL7cyId8D2t22Bl8q2agh9noQDHtBGtoMGvH 8ntFQwHl3Edwqp3owSR1kXt3ZbndAZq+Q7IxAx5Ux9nbWq6txr9yzvzTIQTU4hAzHwBK 4sX0sqdGH9gNIhviMWZ8VBLWU3aoCJ7Hfp+vnF9/Uq4F3g6QJWHnfoh14ZdTk2Sk6Tcz 6fMo/7w1JG0TqFJ9XWBsL419+Fyk8VDgK2c502+xN/cHxGfm8nn/W1vStXDzJtWgwKyw c8GfB7ehaidjnQFY3fQ6vMJD3FKz9Sk+Mkcy2LCXIJqpho6kNeunYdpS/U3KhT7f6xeY YS3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e8si43874edy.494.2020.06.22.23.32.47; Mon, 22 Jun 2020 23:33:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730957AbgFWGan (ORCPT + 99 others); Tue, 23 Jun 2020 02:30:43 -0400 Received: from mga12.intel.com ([192.55.52.136]:21452 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730708AbgFWGan (ORCPT ); Tue, 23 Jun 2020 02:30:43 -0400 IronPort-SDR: dLiEMUWawMGH8i41DCab/iLjZidrLC8G6LBfXvgN3xD8e9wcSh0TpaR20p+wmgM14is9JHNldn ABQhsmtaMu3Q== X-IronPort-AV: E=McAfee;i="6000,8403,9660"; a="123650428" X-IronPort-AV: E=Sophos;i="5.75,270,1589266800"; d="scan'208";a="123650428" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2020 23:30:43 -0700 IronPort-SDR: W8NKYYcgp++Sp08vRstab/P6xSPfzuvhS4KS78Lq1LK6adkFBxCId0atgy/7XzBvBdXvlynAX/ UMx0VJu89Vwg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,270,1589266800"; d="scan'208";a="279007642" Received: from chenyu-office.sh.intel.com ([10.239.158.173]) by orsmga006.jf.intel.com with ESMTP; 22 Jun 2020 23:30:40 -0700 From: Chen Yu To: "Rafael J. Wysocki" , Peter Zijlstra Cc: Daniel Lezcano , Len Brown , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Chen Yu , Len Brown Subject: [PATCH 1/2][v3] PM / s2idle: Clear _TIF_POLLING_NRFLAG before suspend to idle Date: Tue, 23 Jun 2020 14:31:31 +0800 Message-Id: <55caab9c03a0d6c3c0a1f45294d6c274b73c954b.1592892767.git.yu.c.chen@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Suspend to idle was found to not work on Goldmont CPU recently. And the issue was triggered due to: 1. On Goldmont the CPU in idle can only be woken up via IPIs, not POLLING mode: Commit 08e237fa56a1 ("x86/cpu: Add workaround for MONITOR instruction erratum on Goldmont based CPUs") 2. When the CPU is entering suspend to idle process, the _TIF_POLLING_NRFLAG is kept on, due to cpuidle_enter_s2idle() doesn't properly match call_cpuidle(). 3. Commit b2a02fc43a1f ("smp: Optimize send_call_function_single_ipi()") makes use of _TIF_POLLING_NRFLAG to avoid sending IPIs to idle CPUs. 4. As a result, some IPIs related functions might not work well during suspend to idle on Goldmont. For example, one suspected victim: tick_unfreeze() -> timekeeping_resume() -> hrtimers_resume() -> clock_was_set() -> on_each_cpu() might wait forever, because the IPIs will not be sent to the CPUs which are sleeping with _TIF_POLLING_NRFLAG set, and Goldmont CPU could not be woken up by only setting _TIF_NEED_RESCHED on the monitor address. Clear the _TIF_POLLING_NRFLAG flag before entering suspend to idle, and let the driver's enter_s2idle() to decide whether to set _TIF_POLLING_NRFLAG or not. So that to avoid the scenario described above and keep the context consistent with before. Fixes: b2a02fc43a1f ("smp: Optimize send_call_function_single_ipi()") Reported-by: kbuild test robot Cc: "Rafael J. Wysocki" Cc: Peter Zijlstra (Intel) Cc: Len Brown Signed-off-by: Chen Yu --- v2: According to Peter's review, v1 is racy, if someone already set TIF_NEED_RESCHED this patch just clear POLLING and go to sleep. Check TIF_NEED_RESCHED before entering suspend to idle and adjust the naming to be consistent with call_cpuidle(). v3: According to Rafael, it would be better to do the simplest fix first and then do the cleanup on top of it. --- drivers/cpuidle/cpuidle.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index c149d9e20dfd..e092789187c6 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -186,7 +187,7 @@ int cpuidle_enter_s2idle(struct cpuidle_driver *drv, struct cpuidle_device *dev) * be frozen safely. */ index = find_deepest_state(drv, dev, U64_MAX, 0, true); - if (index > 0) + if (index > 0 && !current_clr_polling_and_test()) enter_s2idle_proper(drv, dev, index); return index; -- 2.17.1