From: Mukesh R <mrathor@linux.microsoft.com>
To: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>,
kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
decui@microsoft.com, longli@microsoft.com
Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/4] mshv: Fix pre-depositing of pages for partition initialization
Date: Thu, 5 Mar 2026 19:26:45 -0800 [thread overview]
Message-ID: <7ff1c51b-d876-464e-3149-61684a22d788@linux.microsoft.com> (raw)
In-Reply-To: <177258381999.229866.4628731518107275272.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net>
On 3/3/26 16:23, Stanislav Kinsburskii wrote:
> Deposit enough pages upfront to avoid partition initialization failures due
> to low memory. This also speeds up partition initialization.
I am curious what kinda of failures are observerd. Normally, hypercall
would fail with insuff memory, and we continue to deposit till it
succeeds, right? Is there an issue there that some calls are not looping
in the deposit path?
> Move page depositing from the hypercall wrapper to the partition
> initialization code. The required number of pages is empirical. This logic
> fits better in the partition initialization code than in the hypercall
> wrapper.
>
> A partition with nested capability requires 40x more pages (20 MB) to
> accommodate the nested MSHV hypervisor. This may be improved in the future.
>
> Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
> ---
> drivers/hv/mshv_root.h | 1 +
> drivers/hv/mshv_root_hv_call.c | 6 ------
> drivers/hv/mshv_root_main.c | 23 +++++++++++++++++++++--
> 3 files changed, 22 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/hv/mshv_root.h b/drivers/hv/mshv_root.h
> index 947dfb76bb19..40cf7bdbd62f 100644
> --- a/drivers/hv/mshv_root.h
> +++ b/drivers/hv/mshv_root.h
> @@ -106,6 +106,7 @@ struct mshv_partition {
>
> struct hlist_node pt_hnode;
> u64 pt_id;
> + u64 pt_flags;
> refcount_t pt_ref_count;
> struct mutex pt_mutex;
>
> diff --git a/drivers/hv/mshv_root_hv_call.c b/drivers/hv/mshv_root_hv_call.c
> index bdcb8de7fb47..b8d199f95299 100644
> --- a/drivers/hv/mshv_root_hv_call.c
> +++ b/drivers/hv/mshv_root_hv_call.c
> @@ -15,7 +15,6 @@
> #include "mshv_root.h"
>
> /* Determined empirically */
> -#define HV_INIT_PARTITION_DEPOSIT_PAGES 208
> #define HV_UMAP_GPA_PAGES 512
>
> #define HV_PAGE_COUNT_2M_ALIGNED(pg_count) (!((pg_count) & (0x200 - 1)))
> @@ -139,11 +138,6 @@ int hv_call_initialize_partition(u64 partition_id)
>
> input.partition_id = partition_id;
>
> - ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id,
> - HV_INIT_PARTITION_DEPOSIT_PAGES);
> - if (ret)
> - return ret;
> -
> do {
> status = hv_do_fast_hypercall8(HVCALL_INITIALIZE_PARTITION,
> *(u64 *)&input);
> diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
> index d753f41d3b57..fbfc50de332c 100644
> --- a/drivers/hv/mshv_root_main.c
> +++ b/drivers/hv/mshv_root_main.c
> @@ -35,6 +35,10 @@
> #include "mshv.h"
> #include "mshv_root.h"
>
> +/* 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)
This suggests action rather than count. imo, much better would be:
#define MSHV_PT_NUM_DEPOSIT_PAGES (SZ_512K >> PAGE_SHIFT)
#define MSHV_PT_NUM_DEPOSIT_PAGES_NESTED (20 * SZ_1M >> PAGE_SHIFT)
+
> MODULE_AUTHOR("Microsoft");
> MODULE_LICENSE("GPL");
> MODULE_DESCRIPTION("Microsoft Hyper-V root partition VMM interface /dev/mshv");
> @@ -1587,6 +1591,15 @@ mshv_partition_ioctl_set_msi_routing(struct mshv_partition *partition,
> return ret;
> }
>
> +static u64
> +mshv_partition_deposit_pages(struct mshv_partition *partition)
> +{
> + if (partition->pt_flags &
> + HV_PARTITION_CREATION_FLAG_NESTED_VIRTUALIZATION_CAPABLE)
> + return MSHV_PARTITION_DEPOSIT_PAGES_NESTED;
> + return MSHV_PARTITION_DEPOSIT_PAGES;
> +}
> +
> static long
> mshv_partition_ioctl_initialize(struct mshv_partition *partition)
> {
> @@ -1595,6 +1608,11 @@ mshv_partition_ioctl_initialize(struct mshv_partition *partition)
> if (partition->pt_initialized)
> return 0;
>
> + ret = hv_call_deposit_pages(NUMA_NO_NODE, partition->pt_id,
> + mshv_partition_deposit_pages(partition));
> + if (ret)
> + goto withdraw_mem;
> +
> ret = hv_call_initialize_partition(partition->pt_id);
> if (ret)
> goto withdraw_mem;
> @@ -1610,8 +1628,8 @@ mshv_partition_ioctl_initialize(struct mshv_partition *partition)
> finalize_partition:
> hv_call_finalize_partition(partition->pt_id);
> withdraw_mem:
> - hv_call_withdraw_memory(U64_MAX, NUMA_NO_NODE, partition->pt_id);
> -
> + hv_call_withdraw_memory(MSHV_PARTITION_DEPOSIT_PAGES,
> + NUMA_NO_NODE, partition->pt_id);
> return ret;
> }
>
> @@ -2032,6 +2050,7 @@ mshv_ioctl_create_partition(void __user *user_arg, struct device *module_dev)
> return -ENOMEM;
>
> partition->pt_module_dev = module_dev;
> + partition->pt_flags = creation_flags;
> partition->isolation_type = isolation_properties.isolation_type;
>
> refcount_set(&partition->pt_ref_count, 1);
>
>
next prev parent reply other threads:[~2026-03-06 3:26 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-04 0:23 [PATCH 0/4] mshv: Fix and improve memory pre-depositing Stanislav Kinsburskii
2026-03-04 0:23 ` [PATCH 1/4] mshv: Support larger memory deposits Stanislav Kinsburskii
2026-03-05 19:43 ` Michael Kelley
2026-03-06 3:19 ` Mukesh R
2026-03-04 0:23 ` [PATCH 2/4] mshv: Fix pre-depositing of pages for partition initialization Stanislav Kinsburskii
2026-03-05 19:43 ` Michael Kelley
2026-03-06 3:26 ` Mukesh R [this message]
2026-03-04 0:23 ` [PATCH 3/4] mshv: Fix pre-depositing of pages for virtual processor initialization Stanislav Kinsburskii
2026-03-05 19:44 ` Michael Kelley
2026-03-06 3:33 ` Mukesh R
2026-03-04 0:23 ` [PATCH 4/4] mshv: Pre-deposit pages for SLAT creation Stanislav Kinsburskii
2026-03-05 19:44 ` Michael Kelley
2026-03-06 4:15 ` mhklkml
2026-03-06 3:41 ` Mukesh R
2026-03-06 3:54 ` Mukesh R
2026-03-06 3:44 ` [PATCH 0/4] mshv: Fix and improve memory pre-depositing Mukesh R
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7ff1c51b-d876-464e-3149-61684a22d788@linux.microsoft.com \
--to=mrathor@linux.microsoft.com \
--cc=decui@microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=kys@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=longli@microsoft.com \
--cc=skinsburskii@linux.microsoft.com \
--cc=wei.liu@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox