public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* Run user level code in guest in a new KVM selftest
@ 2023-10-26 17:59 Xin Li
  2023-10-27  0:54 ` Sean Christopherson
  0 siblings, 1 reply; 2+ messages in thread
From: Xin Li @ 2023-10-26 17:59 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: kvm

Hi Sean,

I'm adding a nested exception selftest for FRED, which needs to run
user level code in guest.  I have to add the following hack for that:

diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c 
b/tools/testing/selftests/kvm/lib/x86_64/processor.c
index d8288374078e..72928c07ccbe 100644
--- a/tools/testing/selftests/kvm/lib/x86_64/processor.c
+++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c
@@ -159,6 +159,7 @@ static uint64_t *virt_create_upper_pte(struct kvm_vm 
*vm,

         if (!(*pte & PTE_PRESENT_MASK)) {
                 *pte = PTE_PRESENT_MASK | PTE_WRITABLE_MASK;
+               *pte |= PTE_USER_MASK;
                 if (current_level == target_level)
                         *pte |= PTE_LARGE_MASK | (paddr & 
PHYSICAL_PAGE_MASK);
                 else
@@ -222,6 +223,7 @@ void __virt_pg_map(struct kvm_vm *vm, uint64_t 
vaddr, uint64_t paddr, int level)
         TEST_ASSERT(!(*pte & PTE_PRESENT_MASK),
                     "PTE already present for 4k page at vaddr: 
0x%lx\n", vaddr);
         *pte = PTE_PRESENT_MASK | PTE_WRITABLE_MASK | (paddr & 
PHYSICAL_PAGE_MASK);
+       *pte |= PTE_USER_MASK;
  }

  void virt_arch_pg_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr)


Is there an exiting selftest running user level code in guest?

It seems there is none as the USER bit in PTEs is never set, what have I
missed?

If such a facility doesn't exist, we probably need to find a
clean solution to add the USER bit in user level page table mappings
(which seems not yet clearly defined yet).

Thanks!
     Xin

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-27  0:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-26 17:59 Run user level code in guest in a new KVM selftest Xin Li
2023-10-27  0:54 ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox