From: Stanislav Kinsburskii <[email protected]> Sent: Tuesday, 
March 3, 2026 4:24 PM
> 
> Deposit enough pages up front to avoid virtual processor creation failures
> due to low memory. This also speeds up guest creation. A VP uses 25% more
> pages in a partition with nested virtualization enabled, but the exact
> number doesn't vary much, so deposit a fixed number of pages per VP that
> works for nested virtualization.
> 
> Move page depositing from the hypercall wrapper to the virtual processor
> creation code. The required number of pages is based on empirical data.
> This logic fits better in the virtual processor creation code than in the
> hypercall wrapper.
> 
> Also withdraw the deposited memory if virtual processor creation fails.
> 
> Signed-off-by: Stanislav Kinsburskii <[email protected]>
> ---
>  drivers/hv/hv_proc.c        |    8 --------
>  drivers/hv/mshv_root_main.c |   11 ++++++++++-
>  2 files changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c
> index 0f84a70def30..3d41f52efd9a 100644
> --- a/drivers/hv/hv_proc.c
> +++ b/drivers/hv/hv_proc.c
> @@ -251,14 +251,6 @@ int hv_call_create_vp(int node, u64 partition_id, u32
> vp_index, u32 flags)
>       unsigned long irq_flags;
>       int ret = 0;
> 
> -     /* Root VPs don't seem to need pages deposited */
> -     if (partition_id != hv_current_partition_id) {
> -             /* The value 90 is empirically determined. It may change. */
> -             ret = hv_call_deposit_pages(node, partition_id, 90);
> -             if (ret)
> -                     return ret;
> -     }
> -
>       do {
>               local_irq_save(irq_flags);
> 
> diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
> index fbfc50de332c..48c842b6938d 100644
> --- a/drivers/hv/mshv_root_main.c
> +++ b/drivers/hv/mshv_root_main.c
> @@ -38,6 +38,7 @@
>  /* The deposit values below are empirical and may need to be adjusted. */
>  #define MSHV_PARTITION_DEPOSIT_PAGES         (SZ_512K >> PAGE_SHIFT)
>  #define MSHV_PARTITION_DEPOSIT_PAGES_NESTED  (20 * SZ_1M >> PAGE_SHIFT)
> +#define MSHV_VP_DEPOSIT_PAGES                        (1 * SZ_1M >> 
> PAGE_SHIFT)
> 
>  MODULE_AUTHOR("Microsoft");
>  MODULE_LICENSE("GPL");
> @@ -1077,10 +1078,15 @@ mshv_partition_ioctl_create_vp(struct mshv_partition 
> *partition,
>       if (partition->pt_vp_array[args.vp_index])
>               return -EEXIST;
> 
> +     ret = hv_call_deposit_pages(NUMA_NO_NODE, partition->pt_id,
> +                                 MSHV_VP_DEPOSIT_PAGES);
> +     if (ret)
> +             return ret;
> +
>       ret = hv_call_create_vp(NUMA_NO_NODE, partition->pt_id, args.vp_index,
>                               0 /* Only valid for root partition VPs */);
>       if (ret)
> -             return ret;
> +             goto withdraw_mem;
> 
>       ret = hv_map_vp_state_page(partition->pt_id, args.vp_index,
>                                  HV_VP_STATE_PAGE_INTERCEPT_MESSAGE,
> @@ -1177,6 +1183,9 @@ mshv_partition_ioctl_create_vp(struct mshv_partition 
> *partition,
>                              intercept_msg_page, input_vtl_zero);
>  destroy_vp:
>       hv_call_delete_vp(partition->pt_id, args.vp_index);
> +withdraw_mem:
> +     hv_call_withdraw_memory(MSHV_VP_DEPOSIT_PAGES, NUMA_NO_NODE,
> +                             partition->pt_id);

If the partition is an L1VH partition, hv_call_deposit_pages() will have 
deposited
2 * MSHV_VP_DEPOSIT_PAGES, but here in the failure case you are withdrawing
only MSHV_VP_DEPOSIT_PAGES.

>  out:
>       trace_mshv_create_vp(partition->pt_id, args.vp_index, ret);
>       return ret;
> 
> 

Reply via email to