Re: [PATCH v3 5/8] KVM: selftests: Pass args to vCPU instead of using globals

From: Andrew Jones
Date: Wed Jan 08 2020 - 09:00:10 EST


On Tue, Jan 07, 2020 at 10:26:10AM -0800, Ben Gardon wrote:
> On Tue, Jan 7, 2020 at 7:23 AM Andrew Jones <drjones@xxxxxxxxxx> wrote:
> >
> > On Mon, Dec 16, 2019 at 01:38:58PM -0800, Ben Gardon wrote:
> > > In preparation for supporting multiple vCPUs in the demand paging test,
> > > pass arguments to the vCPU instead of syncing globals to it.
> >
> > This will only work if we don't spill parameters onto the stack and all
> > data we want to pass fit in registers.
>
> That's a great point. I'll see about using globals and deriving the
> cpu ID to look up args. In your pseudocode below I see you use
> arch_get_cpu_id, but I don't believe this function exists in selftests
> and I don't have the knowledge off the top of my head to implement it
> for s390 and aarch64. Do you have any pointers for implementing such a
> function?

Yeah, I never posted the patches that I used this approach on. For aarch64
my "arch_get_cpu_id", which was actually just open-coded in guest_code,
was something similar to this

/* We only look at the first two affinity levels for now. */
int arch_get_cpu_id(void)
{
uint64_t mpidr_el1, aff1, aff0;
asm volatile("mrs %0, mpidr_el1" : "=r" (mpidr_el1));
aff0 = mpidr_el1 & 0xf;
aff1 = (mpidr_el1 >> 8) & 0xff;
return aff1 * 16 + aff0;
}

Thanks,
drew