powerpc/rtas: Implement reentrant rtas call

Implement rtas_call_reentrant() for reentrant rtas-calls:
"ibm,int-on", "ibm,int-off",ibm,get-xive" and  "ibm,set-xive".

On LoPAPR Version 1.1 (March 24, 2016), from 7.3.10.1 to 7.3.10.4,
items 2 and 3 say:

2 - For the PowerPC External Interrupt option: The * call must be
reentrant to the number of processors on the platform.
3 - For the PowerPC External Interrupt option: The * argument call
buffer for each simultaneous call must be physically unique.

So, these rtas-calls can be called in a lockless way, if using
a different buffer for each cpu doing such rtas call.

For this, it was suggested to add the buffer (struct rtas_args)
in the PACA struct, so each cpu can have it's own buffer.
The PACA struct received a pointer to rtas buffer, which is
allocated in the memory range available to rtas 32-bit.

Reentrant rtas calls are useful to avoid deadlocks in crashing,
where rtas-calls are needed, but some other thread crashed holding
the rtas.lock.

This is a backtrace of a deadlock from a kdump testing environment:

  #0 arch_spin_lock
  #1  lock_rtas ()
  #2  rtas_call (token=8204, nargs=1, nret=1, outputs=0x0)
  #3  ics_rtas_mask_real_irq (hw_irq=4100)
  #4  machine_kexec_mask_interrupts
  #5  default_machine_crash_shutdown
  #6  machine_crash_shutdown
  #7  __crash_kexec
  #8  crash_kexec
  #9  oops_end

Signed-off-by: Leonardo Bras <leobras.c@gmail.com>
[mpe: Move under #ifdef PSERIES to avoid build breakage]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200518234245.200672-3-leobras.c@gmail.com
This commit is contained in:
Leonardo Bras
2020-05-18 20:42:45 -03:00
committed by Michael Ellerman
parent 783a015b74
commit b664db8e3f
5 changed files with 98 additions and 11 deletions

View File

@@ -41,6 +41,7 @@
#include <asm/time.h>
#include <asm/mmu.h>
#include <asm/topology.h>
#include <asm/paca.h>
/* This is here deliberately so it's only used in this file */
void enter_rtas(unsigned long);
@@ -1014,6 +1015,57 @@ out:
free_cpumask_var(offline_mask);
return atomic_read(&data.error);
}
/**
* rtas_call_reentrant() - Used for reentrant rtas calls
* @token: Token for desired reentrant RTAS call
* @nargs: Number of Input Parameters
* @nret: Number of Output Parameters
* @outputs: Array of outputs
* @...: Inputs for desired RTAS call
*
* According to LoPAR documentation, only "ibm,int-on", "ibm,int-off",
* "ibm,get-xive" and "ibm,set-xive" are currently reentrant.
* Reentrant calls need their own rtas_args buffer, so not using rtas.args, but
* PACA one instead.
*
* Return: -1 on error,
* First output value of RTAS call if (nret > 0),
* 0 otherwise,
*/
int rtas_call_reentrant(int token, int nargs, int nret, int *outputs, ...)
{
va_list list;
struct rtas_args *args;
unsigned long flags;
int i, ret = 0;
if (!rtas.entry || token == RTAS_UNKNOWN_SERVICE)
return -1;
local_irq_save(flags);
preempt_disable();
/* We use the per-cpu (PACA) rtas args buffer */
args = local_paca->rtas_args_reentrant;
va_start(list, outputs);
va_rtas_call_unlocked(args, token, nargs, nret, list);
va_end(list);
if (nret > 1 && outputs)
for (i = 0; i < nret - 1; ++i)
outputs[i] = be32_to_cpu(args->rets[i + 1]);
if (nret > 0)
ret = be32_to_cpu(args->rets[0]);
local_irq_restore(flags);
preempt_enable();
return ret;
}
#else /* CONFIG_PPC_PSERIES */
int rtas_ibm_suspend_me(u64 handle)
{