Re: [PATCH] x86/acrn: Improve ACRN hypercalls

From: H. Peter Anvin
Date: Mon Aug 08 2022 - 15:01:07 EST


On August 4, 2022 12:03:56 PM PDT, Dave Hansen <dave.hansen@xxxxxxxxx> wrote:
On 8/4/22 11:56, Uros Bizjak wrote:
The %r8 is not preserved across function calls, so your statement
above is correct. But as long as there is no function call *between*
the variable definition and the assembly, the approach with the local
register variable works without any problems. It is even something GCC
itself has used in its library for years.

I'm glad it's workout out for GCC. But, the kernel is not GCC. I
specifically asked for the ACRN code to be the way that it is today and
your argument is not making me reconsider it in the slightest.

So, thanks for the patch, but I don't think we should apply it.

Well, this is universally used, so it isn't going to break. x86 is kind of unique in that it often doesn't need it, because it has predicates for so many of the specific registers, but even x86 needs it for inlining system calls in glibc, for example.

There is a way to do it right, which is to wrap the assignments (which don't have to be the declarations, but customarily are) and asm() statements in a block (e.g. an inline function, but can also just be a plain old statement block.)