From patchwork Thu Feb 21 07:59:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 10823263 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B399013B5 for ; Thu, 21 Feb 2019 07:59:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6D7F2F19F for ; Thu, 21 Feb 2019 07:59:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9AD772F32C; Thu, 21 Feb 2019 07:59:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE0632F311 for ; Thu, 21 Feb 2019 07:59:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727046AbfBUH7Z (ORCPT ); Thu, 21 Feb 2019 02:59:25 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:52616 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727260AbfBUH7K (ORCPT ); Thu, 21 Feb 2019 02:59:10 -0500 Received: by mail-wm1-f66.google.com with SMTP id m1so9236150wml.2 for ; Wed, 20 Feb 2019 23:59:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=wd5LWqxi3KTL1mk2vfXcGPq8iJCNRzZJVnK0M/1Bo3U=; b=bVIn4WnrPcR4HTYDzRKojaZ50k3GEfJW7Sksmhzc/679sbwDlgI2DA5Gs1UvmPeQwZ ZQJBAQ29bKaDtL4yT6B7KkLO4O4HkVub2imU1j6cLxBviJ3PQ3ZR/vrw7s9aRT727icr l7v7ITADpl/TXytVuSDehgcFhc0OrM7ytHMs6o7GABVjrvSJDZOLo787S58bB5+W87B3 6nCLqR5RdiGg/9Ks+pHvv86fQ6goEN25lPRO8CLii2y+IvG2ogkV5kZFtAQ+HT3e2Qtv kPIDSVsIgnLnBFrFD8hUEMrABLNL41O+qXcM3Ocab8fE5K9WMo0ODNNF2UQRBjS2iiO7 ELGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=wd5LWqxi3KTL1mk2vfXcGPq8iJCNRzZJVnK0M/1Bo3U=; b=AfFrTD81bN19o7Ho3Mh4tXey+GTAY9YRxM1/7RmE9BEkX0rucxDfeVSt0+O3gbyanc 4p8KCT9LOIPZbGG1+NbLukYL1BLCwyqIrIGLzihvmuaF6A9+8fFJqk+mN0t15SzHuZw6 2lZFVMS2OjKihAki8FnwGqpfs9Jq564jdS1crE2sE1cuB4QbmL4+Uhf4ozcs5EU5fUwQ i9TFsAbAqUGwBC39aszlfp/YRqWGIAk34cLu9ZXPhzskHh3kn76DC/WjEAOv3R3id6/L pzBESD9Z3EmXJ3CNti9TrEtUVRQcXqkmNJtmL7wA3+4ZkigIGJ5ipRiuOJTRHo59o1Um JYZw== X-Gm-Message-State: AHQUAuaiiT4s+U1VdX8YIiPX69K2f4ohrFCl5opSJqZdP5RJJb1AIfV0 W6BuwrMQQ7luOCAARHr0fSE4mvoW5Zc= X-Google-Smtp-Source: AHgI3IZbHPzMylUlX8znklRpZt8Js/R70hjxQ5T3DuZ42/aaRjBoP2ALBXGBtxVjwwPJ9do6lNHT3w== X-Received: by 2002:a1c:dc8a:: with SMTP id t132mr10206801wmg.48.1550735948722; Wed, 20 Feb 2019 23:59:08 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:f:6020:a9b1:5119:7e50:9df]) by smtp.gmail.com with ESMTPSA id o12sm73384517wre.0.2019.02.20.23.59.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 Feb 2019 23:59:07 -0800 (PST) From: Vincent Guittot To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, rjw@rjwysocki.net, ulf.hansson@linaro.org Cc: sunzhaosheng@hisilicon.com, Vincent Guittot Subject: [PATCH] PM-runtime: fix deadlock when canceling hrtimer Date: Thu, 21 Feb 2019 08:59:02 +0100 Message-Id: <1550735942-3569-1-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When rpm_resume() desactivates the autosuspend timer, it should only try to cancel hrtimer but not wait for the handler to finish because both rpm_resume() and pm_suspend_timer_fn() are taking the power.lock. We can have the deadlock sequence: CPU0 CPU1 rpm_resume() spin_lock_irqsave pm_suspend_timer_fn() spin_lock_irqsave pm_runtime_deactivate_timer() hrtimer_cancel() hrtimer_try_to_cancel() is enough because dev->power.timer_expires is also set to 0. Fixes: 8234f6734c5d ("PM-runtime: Switch autosuspend over to using hrtimers") Reported-by: Sunzhaosheng Sun(Zhaosheng) Signed-off-by: Vincent Guittot --- drivers/base/power/runtime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 04407d9..78937c4 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -121,7 +121,7 @@ EXPORT_SYMBOL_GPL(pm_runtime_suspended_time); static void pm_runtime_deactivate_timer(struct device *dev) { if (dev->power.timer_expires > 0) { - hrtimer_cancel(&dev->power.suspend_timer); + hrtimer_try_to_cancel(&dev->power.suspend_timer); dev->power.timer_expires = 0; } }