Skip to content

Commit 0ca0d33

Browse files
MPState Get/Set API and Get_TSC_KHZ API Changes (#67)
Add support for: - KVM_{GET,SET}_MP_STATE - KVM_GET_TSC_KHZ
1 parent 0061a2c commit 0ca0d33

20 files changed

+1066
-43
lines changed

shim/include/handle_vcpu_kvm_get_mp_state.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <kvm_mp_state.h>
3131
#include <mv_types.h>
32+
#include <shim_vcpu_t.h>
3233

3334
#ifdef __cplusplus
3435
extern "C"
@@ -40,11 +41,12 @@ extern "C"
4041
* @brief Handles the execution of kvm_get_mp_state.
4142
*
4243
* <!-- inputs/outputs -->
43-
* @param pmut_ioctl_args the arguments provided by userspace
44+
* @param vcpu to pass the vsid to hypercall
45+
* @param pmut_args the arguments provided by userspace
4446
* @return SHIM_SUCCESS on success, SHIM_FAILURE on failure.
4547
*/
46-
NODISCARD int64_t
47-
handle_vcpu_kvm_get_mp_state(struct kvm_mp_state *const pmut_ioctl_args) NOEXCEPT;
48+
NODISCARD int64_t handle_vcpu_kvm_get_mp_state(
49+
struct shim_vcpu_t const *const vcpu, struct kvm_mp_state *const pmut_args) NOEXCEPT;
4850

4951
#ifdef __cplusplus
5052
}

shim/include/handle_vcpu_kvm_get_tsc_khz.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ extern "C"
3939
* @brief Handles the execution of kvm_get_tsc_khz.
4040
*
4141
* <!-- inputs/outputs -->
42+
* @param pmut_tsc_khz returns the virtual tsc khz
4243
* @return SHIM_SUCCESS on success, SHIM_FAILURE on failure.
4344
*/
44-
NODISCARD int64_t handle_vcpu_kvm_get_tsc_khz(void) NOEXCEPT;
45+
NODISCARD int64_t handle_vcpu_kvm_get_tsc_khz(uint64_t *const pmut_tsc_khz) NOEXCEPT;
4546

4647
#ifdef __cplusplus
4748
}

shim/include/handle_vcpu_kvm_set_mp_state.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <kvm_mp_state.h>
3131
#include <mv_types.h>
32+
#include <shim_vcpu_t.h>
3233

3334
#ifdef __cplusplus
3435
extern "C"
@@ -40,11 +41,12 @@ extern "C"
4041
* @brief Handles the execution of kvm_set_mp_state.
4142
*
4243
* <!-- inputs/outputs -->
43-
* @param pmut_ioctl_args the arguments provided by userspace
44+
* @param vcpu to pass the vsid to hypercall
45+
* @param args the arguments provided by userspace
4446
* @return SHIM_SUCCESS on success, SHIM_FAILURE on failure.
4547
*/
46-
NODISCARD int64_t
47-
handle_vcpu_kvm_set_mp_state(struct kvm_mp_state *const pmut_ioctl_args) NOEXCEPT;
48+
NODISCARD int64_t handle_vcpu_kvm_set_mp_state(
49+
struct shim_vcpu_t const *const vcpu, struct kvm_mp_state const *const args) NOEXCEPT;
4850

4951
#ifdef __cplusplus
5052
}

shim/include/kvm_constants.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ extern "C"
6666
#define KVM_CAP_IMMEDIATE_EXIT 136
6767
/** @brief defines MICROV_MAX_MCE_BANKS */
6868
#define MICROV_MAX_MCE_BANKS 32
69+
/** @brief defines KVM_MP_STATE_RUNNABLE for mp state */
70+
#define KVM_MP_STATE_RUNNABLE 0
71+
/** @brief defines KVM_MP_STATE_UNINITIALIZED for mp state */
72+
#define KVM_MP_STATE_UNINITIALIZED 1
73+
/** @brief defines KVM_MP_STATE_INIT_RECEIVED for mp state */
74+
#define KVM_MP_STATE_INIT_RECEIVED 2
75+
/** @brief defines KVM_MP_STATE_HALTED for mp state */
76+
#define KVM_MP_STATE_HALTED 3
77+
/** @brief defines KVM_MP_STATE_SIPI_RECEIVED for mp state */
78+
#define KVM_MP_STATE_SIPI_RECEIVED 4
6979

7080
#pragma pack(pop)
7181

shim/include/kvm_constants.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ namespace shim
6363
constexpr auto KVM_CAP_UNSUPPORTED{0_i64};
6464
/// @brief defines the size of the KVM_CAP_IMMEDIATE_EXIT
6565
constexpr auto KVM_CAP_IMMEDIATE_EXIT{1_i64};
66+
/// @brief defines the size of the KVM_MP_INITIAL_STATE
67+
constexpr auto KVM_MP_RUNNING_STATE{0_u32};
68+
/// @brief defines the size of the KVM_MP_RUNNING_STATE
69+
constexpr auto KVM_MP_UNINITIALIZED_STATE{1_u32};
70+
/// @brief defines the size of the KVM_MP_WAIT_STATE
71+
constexpr auto KVM_MP_INIT_RECEIVED_STATE{2_u32};
72+
/// @brief defines the size of the KVM_MP_INIT_STATE
73+
constexpr auto KVM_MP_HALTED_STATE{3_u32};
74+
/// @brief defines the size of the KVM_MP_SIPI_STATE
75+
constexpr auto KVM_MP_SIPI_STATE{4_u32};
6676

6777
}
6878
#pragma pack(pop)

shim/include/kvm_mp_state.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ extern "C"
4444
*/
4545
struct kvm_mp_state
4646
{
47-
/** @brief replace me with contents from KVM API */
48-
int32_t dummy;
47+
/** @brief the mp state of the VS to set or get */
48+
uint32_t mp_state;
4949
};
5050

5151
#pragma pack(pop)

shim/include/kvm_mp_state.hpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/// @copyright
2+
/// Copyright (C) 2020 Assured Information Security, Inc.
3+
///
4+
/// @copyright
5+
/// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
/// of this software and associated documentation files (the "Software"), to deal
7+
/// in the Software without restriction, including without limitation the rights
8+
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
/// copies of the Software, and to permit persons to whom the Software is
10+
/// furnished to do so, subject to the following conditions:
11+
///
12+
/// @copyright
13+
/// The above copyright notice and this permission notice shall be included in
14+
/// all copies or substantial portions of the Software.
15+
///
16+
/// @copyright
17+
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
/// SOFTWARE.
24+
25+
#ifndef KVM_MP_STATE_HPP
26+
#define KVM_MP_STATE_HPP
27+
28+
#include <bsl/cstdint.hpp>
29+
30+
#pragma pack(push, 1)
31+
32+
namespace shim
33+
{
34+
/// @struct kvm_mp_state
35+
///
36+
/// <!-- description -->
37+
/// @brief see /include/uapi/linux/kvm.h in Linux for more details.
38+
///
39+
struct kvm_mp_state final
40+
{
41+
/// @brief stores that value of the mp_state
42+
bsl::uint32 mp_state;
43+
};
44+
}
45+
46+
#pragma pack(pop)
47+
48+
#endif

shim/integration/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ microv_add_shim_integration(kvm_get_fpu HEADERS)
4242
microv_add_shim_integration(kvm_set_tss_addr HEADERS)
4343
microv_add_shim_integration(kvm_set_identity_map_addr HEADERS)
4444
microv_add_shim_integration(kvm_check_extension HEADERS)
45+
microv_add_shim_integration(kvm_get_mp_state HEADERS)
46+
microv_add_shim_integration(kvm_set_mp_state HEADERS)
47+
microv_add_shim_integration(kvm_get_tsc_khz HEADERS)

0 commit comments

Comments
 (0)