2019-05-27 09:55:05 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2010-07-07 16:31:02 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Brian King IBM Corporation
|
|
|
|
*/
|
|
|
|
|
2013-05-07 08:34:11 +04:00
|
|
|
#include <linux/cpu.h>
|
2010-07-07 16:31:02 +04:00
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/suspend.h>
|
2011-05-27 21:27:45 +04:00
|
|
|
#include <linux/stat.h>
|
2010-07-07 16:31:02 +04:00
|
|
|
#include <asm/firmware.h>
|
|
|
|
#include <asm/hvcall.h>
|
|
|
|
#include <asm/machdep.h>
|
|
|
|
#include <asm/mmu.h>
|
|
|
|
#include <asm/rtas.h>
|
2012-01-11 10:56:04 +04:00
|
|
|
#include <asm/topology.h>
|
2014-02-26 08:02:18 +04:00
|
|
|
#include "../../kernel/cacheinfo.h"
|
2010-07-07 16:31:02 +04:00
|
|
|
|
|
|
|
static u64 stream_id;
|
2011-12-22 03:09:52 +04:00
|
|
|
static struct device suspend_dev;
|
2010-07-07 16:31:02 +04:00
|
|
|
static DECLARE_COMPLETION(suspend_work);
|
|
|
|
static struct rtas_suspend_me_data suspend_data;
|
|
|
|
static atomic_t suspending;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pseries_suspend_begin - First phase of hibernation
|
|
|
|
*
|
|
|
|
* Check to ensure we are in a valid state to hibernate
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* 0 on success / other on failure
|
|
|
|
**/
|
|
|
|
static int pseries_suspend_begin(suspend_state_t state)
|
|
|
|
{
|
|
|
|
long vasi_state, rc;
|
|
|
|
unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
|
|
|
|
|
|
|
|
/* Make sure the state is valid */
|
|
|
|
rc = plpar_hcall(H_VASI_STATE, retbuf, stream_id);
|
|
|
|
|
|
|
|
vasi_state = retbuf[0];
|
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
pr_err("pseries_suspend_begin: vasi_state returned %ld\n",rc);
|
|
|
|
return rc;
|
|
|
|
} else if (vasi_state == H_VASI_ENABLED) {
|
|
|
|
return -EAGAIN;
|
|
|
|
} else if (vasi_state != H_VASI_SUSPENDING) {
|
|
|
|
pr_err("pseries_suspend_begin: vasi_state returned state %ld\n",
|
|
|
|
vasi_state);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pseries_suspend_cpu - Suspend a single CPU
|
|
|
|
*
|
|
|
|
* Makes the H_JOIN call to suspend the CPU
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
static int pseries_suspend_cpu(void)
|
|
|
|
{
|
|
|
|
if (atomic_read(&suspending))
|
|
|
|
return rtas_suspend_cpu(&suspend_data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-26 08:02:18 +04:00
|
|
|
/**
|
|
|
|
* pseries_suspend_enable_irqs
|
|
|
|
*
|
|
|
|
* Post suspend configuration updates
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
static void pseries_suspend_enable_irqs(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Update configuration which can be modified based on device tree
|
|
|
|
* changes during resume.
|
|
|
|
*/
|
|
|
|
cacheinfo_cpu_offline(smp_processor_id());
|
|
|
|
post_mobility_fixup();
|
|
|
|
cacheinfo_cpu_online(smp_processor_id());
|
|
|
|
}
|
|
|
|
|
2010-07-07 16:31:02 +04:00
|
|
|
/**
|
|
|
|
* pseries_suspend_enter - Final phase of hibernation
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* 0 on success / other on failure
|
|
|
|
**/
|
|
|
|
static int pseries_suspend_enter(suspend_state_t state)
|
|
|
|
{
|
|
|
|
int rc = rtas_suspend_last_cpu(&suspend_data);
|
|
|
|
|
|
|
|
atomic_set(&suspending, 0);
|
|
|
|
atomic_set(&suspend_data.done, 1);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pseries_prepare_late - Prepare to suspend all other CPUs
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* 0 on success / other on failure
|
|
|
|
**/
|
|
|
|
static int pseries_prepare_late(void)
|
|
|
|
{
|
|
|
|
atomic_set(&suspending, 1);
|
|
|
|
atomic_set(&suspend_data.working, 0);
|
|
|
|
atomic_set(&suspend_data.done, 0);
|
|
|
|
atomic_set(&suspend_data.error, 0);
|
|
|
|
suspend_data.complete = &suspend_work;
|
2013-11-15 02:32:02 +04:00
|
|
|
reinit_completion(&suspend_work);
|
2010-07-07 16:31:02 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* store_hibernate - Initiate partition hibernation
|
2011-12-22 03:09:52 +04:00
|
|
|
* @dev: subsys root device
|
|
|
|
* @attr: device attribute struct
|
2010-07-07 16:31:02 +04:00
|
|
|
* @buf: buffer
|
|
|
|
* @count: buffer size
|
|
|
|
*
|
|
|
|
* Write the stream ID received from the HMC to this file
|
|
|
|
* to trigger hibernating the partition
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* number of bytes printed to buffer / other on failure
|
|
|
|
**/
|
2011-12-22 03:09:52 +04:00
|
|
|
static ssize_t store_hibernate(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2010-07-07 16:31:02 +04:00
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
stream_id = simple_strtoul(buf, NULL, 16);
|
|
|
|
|
|
|
|
do {
|
|
|
|
rc = pseries_suspend_begin(PM_SUSPEND_MEM);
|
|
|
|
if (rc == -EAGAIN)
|
|
|
|
ssleep(1);
|
|
|
|
} while (rc == -EAGAIN);
|
|
|
|
|
2020-06-12 08:12:31 +03:00
|
|
|
if (!rc)
|
2010-07-07 16:31:02 +04:00
|
|
|
rc = pm_suspend(PM_SUSPEND_MEM);
|
|
|
|
|
|
|
|
stream_id = 0;
|
|
|
|
|
|
|
|
if (!rc)
|
|
|
|
rc = count;
|
powerpc/rtas: don't online CPUs for partition suspend
Partition suspension, used for hibernation and migration, requires
that the OS place all but one of the LPAR's processor threads into one
of two states prior to calling the ibm,suspend-me RTAS function:
* the architected offline state (via RTAS stop-self); or
* the H_JOIN hcall, which does not return until the partition
resumes execution
Using H_CEDE as the offline mode, introduced by
commit 3aa565f53c39 ("powerpc/pseries: Add hooks to put the CPU into
an appropriate offline state"), means that any threads which are
offline from Linux's point of view must be moved to one of those two
states before a partition suspension can proceed.
This was eventually addressed in commit 120496ac2d2d ("powerpc: Bring
all threads online prior to migration/hibernation"), which added code
to temporarily bring up any offline processor threads so they can call
H_JOIN. Conceptually this is fine, but the implementation has had
multiple races with cpu hotplug operations initiated from user
space[1][2][3], the error handling is fragile, and it generates
user-visible cpu hotplug events which is a lot of noise for a platform
feature that's supposed to minimize disruption to workloads.
With commit 3aa565f53c39 ("powerpc/pseries: Add hooks to put the CPU
into an appropriate offline state") reverted, this code becomes
unnecessary, so remove it. Since any offline CPUs now are truly
offline from the platform's point of view, it is no longer necessary
to bring up CPUs only to have them call H_JOIN and then go offline
again upon resuming. Only active threads are required to call H_JOIN;
stopped threads can be left alone.
[1] commit a6717c01ddc2 ("powerpc/rtas: use device model APIs and
serialization during LPM")
[2] commit 9fb603050ffd ("powerpc/rtas: retry when cpu offline races
with suspend/migration")
[3] commit dfd718a2ed1f ("powerpc/rtas: Fix a potential race between
CPU-Offline & Migration")
Fixes: 120496ac2d2d ("powerpc: Bring all threads online prior to migration/hibernation")
Signed-off-by: Nathan Lynch <nathanl@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200612051238.1007764-3-nathanl@linux.ibm.com
2020-06-12 08:12:22 +03:00
|
|
|
|
2010-07-07 16:31:02 +04:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2014-02-20 00:56:54 +04:00
|
|
|
#define USER_DT_UPDATE 0
|
|
|
|
#define KERN_DT_UPDATE 1
|
|
|
|
|
|
|
|
/**
|
|
|
|
* show_hibernate - Report device tree update responsibilty
|
|
|
|
* @dev: subsys root device
|
|
|
|
* @attr: device attribute struct
|
|
|
|
* @buf: buffer
|
|
|
|
*
|
|
|
|
* Report whether a device tree update is performed by the kernel after a
|
|
|
|
* resume, or if drmgr must coordinate the update from user space.
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* 0 if drmgr is to initiate update, and 1 otherwise
|
|
|
|
**/
|
|
|
|
static ssize_t show_hibernate(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
return sprintf(buf, "%d\n", KERN_DT_UPDATE);
|
|
|
|
}
|
|
|
|
|
2017-01-12 06:54:13 +03:00
|
|
|
static DEVICE_ATTR(hibernate, 0644, show_hibernate, store_hibernate);
|
2010-07-07 16:31:02 +04:00
|
|
|
|
2011-12-22 03:09:52 +04:00
|
|
|
static struct bus_type suspend_subsys = {
|
2010-07-07 16:31:02 +04:00
|
|
|
.name = "power",
|
2011-12-22 03:09:52 +04:00
|
|
|
.dev_name = "power",
|
2010-07-07 16:31:02 +04:00
|
|
|
};
|
|
|
|
|
2010-11-16 16:14:02 +03:00
|
|
|
static const struct platform_suspend_ops pseries_suspend_ops = {
|
2010-07-07 16:31:02 +04:00
|
|
|
.valid = suspend_valid_only_mem,
|
|
|
|
.begin = pseries_suspend_begin,
|
|
|
|
.prepare_late = pseries_prepare_late,
|
|
|
|
.enter = pseries_suspend_enter,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pseries_suspend_sysfs_register - Register with sysfs
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* 0 on success / other on failure
|
|
|
|
**/
|
2011-12-22 03:09:52 +04:00
|
|
|
static int pseries_suspend_sysfs_register(struct device *dev)
|
2010-07-07 16:31:02 +04:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2011-12-22 03:09:52 +04:00
|
|
|
if ((rc = subsys_system_register(&suspend_subsys, NULL)))
|
2010-07-07 16:31:02 +04:00
|
|
|
return rc;
|
|
|
|
|
2011-12-22 03:09:52 +04:00
|
|
|
dev->id = 0;
|
|
|
|
dev->bus = &suspend_subsys;
|
2010-07-07 16:31:02 +04:00
|
|
|
|
2011-12-22 03:09:52 +04:00
|
|
|
if ((rc = device_create_file(suspend_subsys.dev_root, &dev_attr_hibernate)))
|
|
|
|
goto subsys_unregister;
|
2010-07-07 16:31:02 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2011-12-22 03:09:52 +04:00
|
|
|
subsys_unregister:
|
|
|
|
bus_unregister(&suspend_subsys);
|
2010-07-07 16:31:02 +04:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pseries_suspend_init - initcall for pSeries suspend
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* 0 on success / other on failure
|
|
|
|
**/
|
|
|
|
static int __init pseries_suspend_init(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2014-07-16 06:02:43 +04:00
|
|
|
if (!firmware_has_feature(FW_FEATURE_LPAR))
|
2010-07-07 16:31:02 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
suspend_data.token = rtas_token("ibm,suspend-me");
|
|
|
|
if (suspend_data.token == RTAS_UNKNOWN_SERVICE)
|
|
|
|
return 0;
|
|
|
|
|
2011-12-22 03:09:52 +04:00
|
|
|
if ((rc = pseries_suspend_sysfs_register(&suspend_dev)))
|
2010-07-07 16:31:02 +04:00
|
|
|
return rc;
|
|
|
|
|
|
|
|
ppc_md.suspend_disable_cpu = pseries_suspend_cpu;
|
2014-02-26 08:02:18 +04:00
|
|
|
ppc_md.suspend_enable_irqs = pseries_suspend_enable_irqs;
|
2010-07-07 16:31:02 +04:00
|
|
|
suspend_set_ops(&pseries_suspend_ops);
|
|
|
|
return 0;
|
|
|
|
}
|
2014-07-16 06:02:43 +04:00
|
|
|
machine_device_initcall(pseries, pseries_suspend_init);
|