From patchwork Mon Jul 30 08:59:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 10548803 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 28DE7A755 for ; Mon, 30 Jul 2018 08:59:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19AB1297F9 for ; Mon, 30 Jul 2018 08:59:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0DAFD2985C; Mon, 30 Jul 2018 08:59:52 +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,FREEMAIL_FROM,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 55567297F9 for ; Mon, 30 Jul 2018 08:59:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726637AbeG3Kds (ORCPT ); Mon, 30 Jul 2018 06:33:48 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:40049 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726639AbeG3Kds (ORCPT ); Mon, 30 Jul 2018 06:33:48 -0400 Received: by mail-pf1-f194.google.com with SMTP id e13-v6so4239155pff.7 for ; Mon, 30 Jul 2018 01:59:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=sBmKATAAZsijaZvA7AjtkA5tDeYUTBi3rBcD5ESCoTk=; b=hgL501nE++dPjpRsRjOSx9V1BHlpL/T0WJqxpc4MW5Sleh9g5pjhcV29hwXgqsCKii /t9TY0WFNKHnDvgAbqRV0FN3nOp4aHaIFmeIiKxGlYb2/6yBUyEZonijdBEUHWyBmeml tpwwib5sAqH99xf88WHtrE6F0G6WiCaDj/VVb2mWweCTLPAsViTeWS7cP/njQt2Cq5kV NZRCU4PscYBFk7dvja1UpWM1UHXZeKiAn2/7Rvv6An5YcedNYEO4BybwtfCZlhmdQ2Zc Yl45I8n78fl3vTfC8Lvp4Nbu+eCOBtWfqh7amMrrkzRrXJW4WXyxPKJCXthSWcCvYABj C6pA== 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=sBmKATAAZsijaZvA7AjtkA5tDeYUTBi3rBcD5ESCoTk=; b=iy4IVUMP2Xu1P1n89SqrXJ0AklJiqTITLTsNc8RJ4R1Y5Xxp4GEEzkoPXFOuJe/gfe y6lv6OAIu9Gx9hM7PfFUi2DFFFet0RdJmSlIZAOfF5buh1a+NalMgPSK7JFeDF210QDz wyLpebTGzIAecyVfewIyRDZIYYx1dE9NzyydqrqPxgDXrlVw20FJM5hIm4u7B7ulvJNo nJdO3Oyy9dW8JPFgfghjzwBUtoj5aFy30PXRMUbzqseF6x1B9KZUK/eOvRgQXSMBZF9O iMT8u2AyNVJg+xanU79YGtHeiuqx/pjxep8Cp4hx3A06htcXe7UQfAUjU67VRGi5kKLb UOnQ== X-Gm-Message-State: AOUpUlEyOTPLwTJCZORC3ckux+l/7trYKj8cC9GOjL7xYKp2vKQqHDr8 dPeXRYOlwvFpGIq+d+xIn/CONbM= X-Google-Smtp-Source: AAOMgpdKxrBMPRE9zTj6maUhdVl2AOY5zWV0x4kO8PZtEvM4SxqVVOt+wVb/mWDH/+5a4IegQY2phQ== X-Received: by 2002:a62:2119:: with SMTP id h25-v6mr16781702pfh.112.1532941188862; Mon, 30 Jul 2018 01:59:48 -0700 (PDT) Received: from mylaptop.nay.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id d9-v6sm12351544pgp.30.2018.07.30.01.59.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Jul 2018 01:59:48 -0700 (PDT) From: Pingfan Liu To: linux-pm@vger.kernel.org Cc: Pingfan Liu , "Rafael J. Wysocki" , Len Brown , Pavel Machek Subject: [PATCH] pm/reboot: eliminate race between reboot and suspend Date: Mon, 30 Jul 2018 16:59:33 +0800 Message-Id: <1532941173-26969-1-git-send-email-kernelfans@gmail.com> 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 At present, "systemctl suspend" and "shutdown" can run in parrallel. A system can suspend after devices_shutdown(), and resume. Then the shutdown task goes on to power off. This causes many devices are not really shut off. Hence replacing reboot_mutex with pm_mutex to achieve the exclusion. Cc: "Rafael J. Wysocki" Cc: Len Brown Cc: Pavel Machek Signed-off-by: Pingfan Liu Acked-by: Pavel Machek --- kernel/power/main.c | 3 +-- kernel/reboot.c | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/kernel/power/main.c b/kernel/power/main.c index d9706da..b5b3ac6 100644 --- a/kernel/power/main.c +++ b/kernel/power/main.c @@ -15,11 +15,10 @@ #include #include #include +#include #include "power.h" -DEFINE_MUTEX(pm_mutex); - #ifdef CONFIG_PM_SLEEP void lock_system_sleep(void) diff --git a/kernel/reboot.c b/kernel/reboot.c index e4ced88..45e9db7 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -294,7 +294,7 @@ void kernel_power_off(void) } EXPORT_SYMBOL_GPL(kernel_power_off); -static DEFINE_MUTEX(reboot_mutex); +DEFINE_MUTEX(pm_mutex); /* * Reboot system call: for obvious reasons only root may call it, @@ -338,7 +338,7 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd, if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off) cmd = LINUX_REBOOT_CMD_HALT; - mutex_lock(&reboot_mutex); + mutex_lock(&pm_mutex); switch (cmd) { case LINUX_REBOOT_CMD_RESTART: kernel_restart(NULL); @@ -389,7 +389,7 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd, ret = -EINVAL; break; } - mutex_unlock(&reboot_mutex); + mutex_unlock(&pm_mutex); return ret; }