Re: [RFC PATCH v5 4/4] x86/acrn: Add hypercall for ACRN guest

From: Borislav Petkov
Date: Thu Apr 25 2019 - 07:00:35 EST


On Thu, Apr 25, 2019 at 06:16:02PM +0800, Zhao, Yakui wrote:
> The parameter register for the VMCALL is predefined in ACRN hypervisor. Now
> the R8 is used to pass the hcall_id.
> It seems that there is no special constraint for R8~R15.
> So the explicit register variable is used so that the R8 can be passed.

If you're going to use the constraint "D" for param1, you can just as
well do

"=a" (result)

everywhere since you have the letter constraint for %rax instead of
declaring it with "register".

Also, you can completely get rid of those "register" declarations
and let gcc have all the freedom to pass in hcall_id and the other
parameters:

unsigned long result;

asm volatile("mov %[hcall_id], %%r8\n\t"
"vmcall\n\t"
: "=a" (result)
: [hcall_id] "g" (hcall_id)
: "r8");

return result;

and %r8 will be in the clobber list so gcc will reload it if needed.

gcc turns it into

0000000000001040 <main>:
1040: 4c 8b 05 e1 2f 00 00 mov 0x2fe1(%rip),%r8 # 4028 <hcall_id>
1047: 0f 01 c1 vmcall
104a: c3 retq
104b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)

here.

--
Regards/Gruss,
Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.