Re: [PATCH v3 2/8] x86/sev: Add support for the RMPREAD instruction

From: Tom Lendacky
Date: Mon Oct 21 2024 - 13:11:11 EST


On 10/21/24 10:41, Borislav Petkov wrote:
> On Fri, Oct 18, 2024 at 10:14:04AM -0500, Tom Lendacky wrote:
>> I don't think so. RCX does not change on output, the contents that RCX
>> points to changes, but the register value does not so the "+" is not
>> correct. The instruction doesn't take a memory location as part of
>> operands (like a MOV instruction could), which is why the "memory" clobber
>> is specified.
>
> Just confirmed it with my compiler guy: yes, you're right. The rule is this:
> *if* RCX itself doesn't change but memory it points to, does change, then you
> need the "memory" clobber. Otherwise the compiler can reorder accesses.
>
>> For RAX, yes, if I set "ret" to the input value then I can use "+"
>> specification. But the way it's coded now is also correct.
>
> If you set ret, it means a smaller and simpler inline asm which is always
> better.

The input value is a 64-bit value and on output the return code is in
EAX, a 32-bit value. So the use of the "=a" (ret) for output and "a"
(pfn << PAGE_SHIFT) for input is more accurate.

It's not a complicated statement and is much clearer to me.

I can change it if you really want the "+a" thing (including changing
the ret variable to a u64), but would prefer not to do that.

Thanks,
Tom

>
> :-)
>
> Thx.
>