Skip to content

Commit 91dc182

Browse files
Dave C Boutcherpaulusmack
authored andcommitted
[PATCH] powerpc: special-case ibm,suspend-me RTAS call
Handle the ibm,suspend-me RTAS call specially. It needs to be wrapped in a set of synchronization hypervisor calls (H_Join). When the H_Join calls are made on all CPUs, the intent is that only one will return with H_Continue, meaning that he is the "last man standing". That CPU then issues the ibm,suspend-me call. What is interesting, of course, is that the CPU running when the rtas syscall is made, may NOT be the CPU that ultimately executes the ibm,suspend-me rtas call. Signed-off-by: Dave Boutcher <sleddog@us.ibm.com> Signed-off-by: Paul Mackerras <paulus@samba.org>
1 parent 91f62a2 commit 91dc182

1 file changed

Lines changed: 95 additions & 1 deletion

File tree

‎arch/powerpc/kernel/rtas.c‎

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ struct rtas_t rtas = {
3636
.lock = SPIN_LOCK_UNLOCKED
3737
};
3838

39+
struct rtas_suspend_me_data {
40+
long waiting;
41+
struct rtas_args *args;
42+
};
43+
3944
EXPORT_SYMBOL(rtas);
4045

4146
DEFINE_SPINLOCK(rtas_data_buf_lock);
@@ -556,13 +561,88 @@ void rtas_os_term(char *str)
556561
} while (status == RTAS_BUSY);
557562
}
558563

564+
static int ibm_suspend_me_token = RTAS_UNKNOWN_SERVICE;
565+
#ifdef CONFIG_PPC_PSERIES
566+
static void rtas_percpu_suspend_me(void *info)
567+
{
568+
long rc;
569+
long flags;
570+
struct rtas_suspend_me_data *data =
571+
(struct rtas_suspend_me_data *)info;
572+
573+
/*
574+
* We use "waiting" to indicate our state. As long
575+
* as it is >0, we are still trying to all join up.
576+
* If it goes to 0, we have successfully joined up and
577+
* one thread got H_Continue. If any error happens,
578+
* we set it to <0.
579+
*/
580+
local_irq_save(flags);
581+
do {
582+
rc = plpar_hcall_norets(H_JOIN);
583+
smp_rmb();
584+
} while (rc == H_Success && data->waiting > 0);
585+
if (rc == H_Success)
586+
goto out;
587+
588+
if (rc == H_Continue) {
589+
data->waiting = 0;
590+
rtas_call(ibm_suspend_me_token, 0, 1,
591+
data->args->args);
592+
} else {
593+
data->waiting = -EBUSY;
594+
printk(KERN_ERR "Error on H_Join hypervisor call\n");
595+
}
596+
597+
out:
598+
/* before we restore interrupts, make sure we don't
599+
* generate a spurious soft lockup errors
600+
*/
601+
touch_softlockup_watchdog();
602+
local_irq_restore(flags);
603+
return;
604+
}
605+
606+
static int rtas_ibm_suspend_me(struct rtas_args *args)
607+
{
608+
int i;
609+
610+
struct rtas_suspend_me_data data;
611+
612+
data.waiting = 1;
613+
data.args = args;
614+
615+
/* Call function on all CPUs. One of us will make the
616+
* rtas call
617+
*/
618+
if (on_each_cpu(rtas_percpu_suspend_me, &data, 1, 0))
619+
data.waiting = -EINVAL;
620+
621+
if (data.waiting != 0)
622+
printk(KERN_ERR "Error doing global join\n");
623+
624+
/* Prod each CPU. This won't hurt, and will wake
625+
* anyone we successfully put to sleep with H_Join
626+
*/
627+
for_each_cpu(i)
628+
plpar_hcall_norets(H_PROD, i);
629+
630+
return data.waiting;
631+
}
632+
#else /* CONFIG_PPC_PSERIES */
633+
static int rtas_ibm_suspend_me(struct rtas_args *args)
634+
{
635+
return -ENOSYS;
636+
}
637+
#endif
559638

560639
asmlinkage int ppc_rtas(struct rtas_args __user *uargs)
561640
{
562641
struct rtas_args args;
563642
unsigned long flags;
564643
char *buff_copy, *errbuf = NULL;
565644
int nargs;
645+
int rc;
566646

567647
if (!capable(CAP_SYS_ADMIN))
568648
return -EPERM;
@@ -581,6 +661,17 @@ asmlinkage int ppc_rtas(struct rtas_args __user *uargs)
581661
nargs * sizeof(rtas_arg_t)) != 0)
582662
return -EFAULT;
583663

664+
if (args.token == RTAS_UNKNOWN_SERVICE)
665+
return -EINVAL;
666+
667+
/* Need to handle ibm,suspend_me call specially */
668+
if (args.token == ibm_suspend_me_token) {
669+
rc = rtas_ibm_suspend_me(&args);
670+
if (rc)
671+
return rc;
672+
goto copy_return;
673+
}
674+
584675
buff_copy = get_errorlog_buffer();
585676

586677
spin_lock_irqsave(&rtas.lock, flags);
@@ -604,6 +695,7 @@ asmlinkage int ppc_rtas(struct rtas_args __user *uargs)
604695
kfree(buff_copy);
605696
}
606697

698+
copy_return:
607699
/* Copy out args. */
608700
if (copy_to_user(uargs->args + nargs,
609701
args.args + nargs,
@@ -675,8 +767,10 @@ void __init rtas_initialize(void)
675767
* the stop-self token if any
676768
*/
677769
#ifdef CONFIG_PPC64
678-
if (_machine == PLATFORM_PSERIES_LPAR)
770+
if (_machine == PLATFORM_PSERIES_LPAR) {
679771
rtas_region = min(lmb.rmo_size, RTAS_INSTANTIATE_MAX);
772+
ibm_suspend_me_token = rtas_token("ibm,suspend-me");
773+
}
680774
#endif
681775
rtas_rmo_buf = lmb_alloc_base(RTAS_RMOBUF_MAX, PAGE_SIZE, rtas_region);
682776

0 commit comments

Comments
 (0)