ANDROID: pkvm: x86: Fix inline asm in pkvm_init_ept_page()
LLVM produces the following code for host_ept_zalloc_page() with inlined
pkvm_init_ept_page():
pushq %rbp
movq %rsp, %rbp
movq $0, %rdi
xorl %esi, %esi
callq 0x12 <host_ept_zalloc_page+0x12>
movq %rax, %rdi
testq %rax, %rax
je 0x2c <host_ept_zalloc_page+0x2c>
movabsq $-9223372036854775808, %rax # imm = 0x8000000000000000
movl $512, %ecx # imm = 0x200
rep stosq %rax, %es:(%rdi)
movq %rdi, %rax
popq %rbp
jmp 0x35 <pkvm_page_count>
i.e. the RAX register (the return value of host_ept_zalloc_page()) is
corrupted with the RDI register value which has been modified by
"rep stosq" in the inline asm. As a result, kernel bootup fails.
The problem is that RDI is specified as input-only, so the compiler
assumes that RDI is not modified by the inline asm. It can be fixed by
making RDI also an output operand. This is properly implemented in
memset64() in arch/x86/include/asm/string_64.h. So just replace this
inline asm with memset64().
Fixes: 346eeda8c163 ("pkvm: x86: Initialize every SEPT entry with "suppress #VE" bit set")
Bug: 395299836
Test: Boot, verify cpus are de-privileged and run a minimal protected vm.
Change-Id: I8dcb8e3a5be0fd2f96ba27f8ea65238e4e4b6ec3
Signed-off-by:
Dmytro Maluka <dmy@semihalf.com>
Signed-off-by:
Vineeth Pillai <vineethrp@google.com>
Loading
Please sign in to comment