On Tue, Jul 01, 2025 at 07:28:15PM +0200, Magnus Kulke wrote:
> Create the MSHV virtual machine by opening a partition and issuing
> the necessary ioctl to initialize it. This sets up the basic VM
> structure and initial configuration used by MSHV to manage guest state.
> 
> Signed-off-by: Magnus Kulke <magnusku...@linux.microsoft.com>
> ---
>  accel/mshv/mshv-all.c        | 210 ++++++++++++++++++++++++++++++++++-
>  accel/mshv/trace-events      |   3 +
>  accel/mshv/trace.h           |   1 +
>  include/system/mshv.h        |  20 +++-
>  meson.build                  |   1 +
>  target/i386/mshv/meson.build |   1 +
>  target/i386/mshv/mshv-cpu.c  |  71 ++++++++++++
>  7 files changed, 300 insertions(+), 7 deletions(-)
>  create mode 100644 accel/mshv/trace-events
>  create mode 100644 accel/mshv/trace.h
>  create mode 100644 target/i386/mshv/mshv-cpu.c
> 
> diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c
> index 9e0590c4f9..712e651627 100644
> --- a/accel/mshv/mshv-all.c
> +++ b/accel/mshv/mshv-all.c
> @@ -46,8 +46,177 @@ DECLARE_INSTANCE_CHECKER(MshvState, MSHV_STATE, 
> TYPE_MSHV_ACCEL)
>  
>  bool mshv_allowed;
>  
> -MshvState *mshv_state;
> +MshvState *mshv_state = NULL;

This is not needed. Global variables are initialized to zero by default.

>  
> +static int init_mshv(int *mshv_fd)
> +{
> +    int fd = open("/dev/mshv", O_RDWR | O_CLOEXEC);
> +    if (fd < 0) {
> +        error_report("Failed to open /dev/mshv: %s", strerror(errno));
> +        return -1;
> +    }
> +     *mshv_fd = fd;
> +     return 0;

Tabs here.

> +}
> +
> +/* freeze 1 to pause, 0 to resume */
> +static int set_time_freeze(int vm_fd, int freeze)
> +{
> +    int ret;
> +
> +    if (freeze != 0 && freeze != 1) {
> +        error_report("Invalid time freeze value");
> +        return -1;
> +    }
> +

This is a static function. You know all callers already, so you can
dro the check here.

> +    struct hv_input_set_partition_property in = {0};
> +    in.property_code = HV_PARTITION_PROPERTY_TIME_FREEZE;
> +    in.property_value = freeze;
> +
> +    struct mshv_root_hvcall args = {0};
> +    args.code = HVCALL_SET_PARTITION_PROPERTY;
> +    args.in_sz = sizeof(in);
> +    args.in_ptr = (uint64_t)&in;
> +
> +    ret = mshv_hvcall(vm_fd, &args);
> +    if (ret < 0) {
> +        error_report("Failed to set time freeze");
> +        return -1;
> +    }
> +
> +    return 0;
> +}
> +
[...]
>  typedef struct MshvState {
> -    AccelState parent_obj;
> -    int vm;
> -    MshvMemoryListener memory_listener;
> -    /* number of listeners */
> -    int nr_as;
> -    MshvAddressSpace *as;
> +     AccelState parent_obj;
> +     int vm;
> +     MshvMemoryListener memory_listener;
> +     /* number of listeners */
> +     int nr_as;
> +     MshvAddressSpace *as;

Unnecessary changes due to tabs.

> +    int fd;
>  } MshvState;
>  extern MshvState *mshv_state;

Wei

Reply via email to