Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

libkvmi: add kvmi_alloc_gfn, kvmi_free_gfn, kvmi_create_ept_view, kvmi_destroy_ept_view #20

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/libkvmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,15 @@ int kvmi_set_ept_page_conv( void *dom, unsigned short index, unsigned long l
int kvmi_get_ept_page_conv( void *dom, unsigned short index, unsigned long long gpa, bool *sve );
int kvmi_switch_ept_view( void *dom, unsigned short vcpu, unsigned short view );
int kvmi_disable_ve( void *dom, unsigned short vcpu );
int kvmi_create_ept_view( void *dom, unsigned short *view );
int kvmi_destroy_ept_view( void *dom, unsigned short view );
int kvmi_get_ept_view( void *dom, unsigned short vcpu, unsigned short *view );
int kvmi_control_ept_view( void *dom, unsigned short vcpu, unsigned short view, bool visible );
bool kvmi_remote_mapping_v2( void );
size_t kvmi_get_pending_events( void *dom );
int kvmi_change_gfn( void *dom, unsigned short vcpu, __u64 old_gfn, __u64 new_gfn );
int kvmi_alloc_gfn( void *dom, __u64 gfn );
int kvmi_free_gfn( void *dom, __u64 gfn );

#ifdef __cplusplus
}
Expand Down
22 changes: 22 additions & 0 deletions include/linux/kvmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ enum {
KVMI_VCPU_GET_XCR = 37,
KVMI_VCPU_SET_XSAVE = 38,
KVMI_QUERY_PHYSICAL = 39,
KVMI_VCPU_ALLOC_GFN = 41,
KVMI_VCPU_FREE_GFN = 42,
KVMI_CREATE_EPT_VIEW = 43,
KVMI_DESTROY_EPT_VIEW = 44,
KVMI_VCPU_CHANGE_GFN = 60,

KVMI_VCPU_CONTROL_SINGLESTEP = 63,
Expand Down Expand Up @@ -343,6 +347,24 @@ struct kvmi_vcpu_change_gfn {
__u64 new_gfn;
};

struct kvmi_vcpu_alloc_gfn {
__u64 gfn;
};

struct kvmi_vcpu_free_gfn {
__u64 gfn;
};

struct kvmi_create_ept_view_reply {
__u16 view;
__u16 pad[3];
};

struct kvmi_destroy_ept_view {
__u16 view;
__u16 pad[3];
};

/*
* ioctls for /dev/kvmmem
*/
Expand Down
40 changes: 40 additions & 0 deletions src/kvmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2714,3 +2714,43 @@ int kvmi_change_gfn( void *dom, unsigned short vcpu, __u64 old_gfn, __u64 new_gf

return request( dom, KVMI_VCPU_CHANGE_GFN, &req, sizeof( req ), NULL, NULL );
}

int kvmi_alloc_gfn( void *dom, __u64 gfn )
{
struct {
struct kvmi_vcpu_hdr vcpu;
struct kvmi_vcpu_alloc_gfn cmd;
} req = { .vcpu = { .vcpu = 0 }, .cmd = { .gfn = gfn } };

return request( dom, KVMI_VCPU_ALLOC_GFN, &req, sizeof( req ), NULL, NULL );
}

int kvmi_free_gfn( void *dom, __u64 gfn )
{
struct {
struct kvmi_vcpu_hdr vcpu;
struct kvmi_vcpu_free_gfn cmd;
} req = { .vcpu = { .vcpu = 0 }, .cmd = { .gfn = gfn } };

return request( dom, KVMI_VCPU_FREE_GFN, &req, sizeof( req ), NULL, NULL );
}

int kvmi_create_ept_view( void *dom, unsigned short *view )
{
struct kvmi_create_ept_view_reply rpl;
int err;
size_t received = sizeof( rpl );

err = request( dom, KVMI_CREATE_EPT_VIEW, NULL, 0, &rpl, &received );
if ( !err && view )
*view = rpl.view;

return err;
}

int kvmi_destroy_ept_view( void *dom, unsigned short view )
{
struct kvmi_destroy_ept_view req = { .view = view };

return request( dom, KVMI_DESTROY_EPT_VIEW, &req, sizeof( req ), NULL, 0 );
}
4 changes: 4 additions & 0 deletions src/version.ld
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ KVMI_1.0 {
kvmi_disable_ve;
kvmi_get_ept_view;
kvmi_control_ept_view;
kvmi_alloc_gfn;
kvmi_free_gfn;
kvmi_create_ept_view;
kvmi_destroy_ept_view;
local:
*;
};