Skip to content

Commit

Permalink
libkvmi: add kvmi_alloc_gfn and kvmi_free_gfn
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdangl committed Nov 29, 2023
1 parent 5676f8c commit b021c74
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/libkvmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ int kvmi_control_ept_view( void *dom, unsigned short vcpu, unsigned short vi
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
12 changes: 11 additions & 1 deletion include/linux/kvmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ enum {
KVMI_CONTROL_CMD_RESPONSE = 27,
KVMI_SET_VE_INFO_PAGE = 28,
KVMI_GET_MAX_GFN = 29,
KVMI_GET_NEXT_AVAILABLE_GFN = 31,
KVMI_GET_NEXT_AVAILABLE_GFN = 31,
KVMI_SWITCH_EPT_VIEW = 32,
KVMI_DISABLE_VE = 33,
KVMI_GET_EPT_VIEW = 34,
Expand All @@ -53,6 +53,8 @@ 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_VCPU_CHANGE_GFN = 60,

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

struct kvmi_vcpu_alloc_gfn {
__u64 gfn;
};

struct kvmi_vcpu_free_gfn {
__u64 gfn;
};

/*
* ioctls for /dev/kvmmem
*/
Expand Down
20 changes: 20 additions & 0 deletions src/kvmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2714,3 +2714,23 @@ 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 );
}
2 changes: 2 additions & 0 deletions src/version.ld
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ KVMI_1.0 {
kvmi_disable_ve;
kvmi_get_ept_view;
kvmi_control_ept_view;
kvmi_alloc_gfn;
kvmi_free_gfn;
local:
*;
};

0 comments on commit b021c74

Please sign in to comment.