Skip to content

Commit 01244fc

Browse files
vishals4ghbonzini
authored andcommitted
KVM: selftests: Add helpers to do KVM_HC_MAP_GPA_RANGE hypercalls (x86)
Add helpers for x86 guests to invoke the KVM_HC_MAP_GPA_RANGE hypercall, which KVM will forward to userspace and thus can be used by tests to coordinate private<=>shared conversions between host userspace code and guest code. Signed-off-by: Vishal Annapurve <vannapurve@google.com> [sean: drop shared/private helpers (let tests specify flags)] Signed-off-by: Sean Christopherson <seanjc@google.com> Message-Id: <20231027182217.3615211-29-seanjc@google.com> Reviewed-by: Fuad Tabba <tabba@google.com> Tested-by: Fuad Tabba <tabba@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent f7fa674 commit 01244fc

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

tools/testing/selftests/kvm/include/x86_64/processor.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <asm/msr-index.h>
1616
#include <asm/prctl.h>
1717

18+
#include <linux/kvm_para.h>
1819
#include <linux/stringify.h>
1920

2021
#include "../kvm_util.h"
@@ -1194,6 +1195,20 @@ uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2,
11941195
uint64_t __xen_hypercall(uint64_t nr, uint64_t a0, void *a1);
11951196
void xen_hypercall(uint64_t nr, uint64_t a0, void *a1);
11961197

1198+
static inline uint64_t __kvm_hypercall_map_gpa_range(uint64_t gpa,
1199+
uint64_t size, uint64_t flags)
1200+
{
1201+
return kvm_hypercall(KVM_HC_MAP_GPA_RANGE, gpa, size >> PAGE_SHIFT, flags, 0);
1202+
}
1203+
1204+
static inline void kvm_hypercall_map_gpa_range(uint64_t gpa, uint64_t size,
1205+
uint64_t flags)
1206+
{
1207+
uint64_t ret = __kvm_hypercall_map_gpa_range(gpa, size, flags);
1208+
1209+
GUEST_ASSERT(!ret);
1210+
}
1211+
11971212
void __vm_xsave_require_permission(uint64_t xfeature, const char *name);
11981213

11991214
#define vm_xsave_require_permission(xfeature) \

0 commit comments

Comments
 (0)