Re: [PATCH v2 03/13] powerpc/prom_init: Add the ESM call to prom_init

From: Segher Boessenkool
Date: Thu Jul 18 2019 - 15:59:19 EST


(Sorry to hijack your reply).

On Thu, Jul 18, 2019 at 06:11:48PM +1000, Alexey Kardashevskiy wrote:
> On 13/07/2019 16:00, Thiago Jung Bauermann wrote:
> >From: Ram Pai <linuxram@xxxxxxxxxx>
> >+static int enter_secure_mode(unsigned long kbase, unsigned long fdt)
> >+{
> >+ register uint64_t func asm("r3") = UV_ESM;
> >+ register uint64_t arg1 asm("r4") = (uint64_t)kbase;
> >+ register uint64_t arg2 asm("r5") = (uint64_t)fdt;
>
> What does UV do with kbase and fdt precisely? Few words in the commit
> log will do.
>
> >+
> >+ asm volatile("sc 2\n"
> >+ : "=r"(func)
> >+ : "0"(func), "r"(arg1), "r"(arg2)
> >+ :);
> >+
> >+ return (int)func;
>
> And why "func"? Is it "function"? Weird name. Thanks,

Maybe the three vars should just be called "r3", "r4", and "r5" --
r3 is used as return value as well, so "func" isn't a great name for it.

Some other comments about this inline asm:

The "\n" makes the generated asm look funny and has no other function.
Instead of using backreferences you can use a "+" constraint, "inout".
Empty clobber list is strange.
Casts to the return type, like most other casts, are an invitation to
bugs and not actually useful.

So this can be written

static int enter_secure_mode(unsigned long kbase, unsigned long fdt)
{
register uint64_t r3 asm("r3") = UV_ESM;
register uint64_t r4 asm("r4") = kbase;
register uint64_t r4 asm("r5") = fdt;

asm volatile("sc 2" : "+r"(r3) : "r"(r4), "r"(r5));

return r3;
}

(and it probably should use u64 instead of both uint64_t and unsigned long?)


Segher