From: Nuno Das Neves <nunodasneves@linux.microsoft.com>
To: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>,
kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
decui@microsoft.com
Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 5/7] Drivers: hv: Improve region overlap detection in partition create
Date: Wed, 3 Dec 2025 10:58:12 -0800 [thread overview]
Message-ID: <2c853152-c2f8-49c6-a16c-be8aa1b59234@linux.microsoft.com> (raw)
In-Reply-To: <176412295734.447063.5692907557041244468.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net>
On 11/25/2025 6:09 PM, Stanislav Kinsburskii wrote:
> Refactor region overlap check in mshv_partition_create_region to use
> mshv_partition_region_by_gfn for both start and end guest PFNs, replacing
> manual iteration.
>
> This is a cleaner approach that leverages existing functionality to
> accurately detect overlapping memory regions.
>
> Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
> ---
> drivers/hv/mshv_root_main.c | 8 ++------
> 1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
> index 5dfb933da981..ae600b927f49 100644
> --- a/drivers/hv/mshv_root_main.c
> +++ b/drivers/hv/mshv_root_main.c
> @@ -1086,13 +1086,9 @@ static int mshv_partition_create_region(struct mshv_partition *partition,
> u64 nr_pages = HVPFN_DOWN(mem->size);
>
> /* Reject overlapping regions */
> - hlist_for_each_entry(rg, &partition->pt_mem_regions, hnode) {
> - if (mem->guest_pfn + nr_pages <= rg->start_gfn ||
> - rg->start_gfn + rg->nr_pages <= mem->guest_pfn)
> - continue;
> -
> + if (mshv_partition_region_by_gfn(partition, mem->guest_pfn) ||
> + mshv_partition_region_by_gfn(partition, mem->guest_pfn + nr_pages - 1))
> return -EEXIST;
This logic does not work. I fixed this check in
ba9eb9b86d23 mshv: Fix create memory region overlap check
This change would just be reverting that fix.
Consider an existing region at 0x2000 of size 0x1000. The user
tries to map a new region at 0x1000 of size 0x3000. Since the new region
starts before and ends after the existing region, the overlap would not
be detected by this logic. It just checks if an existing region contains
0x1000 or 0x4000 - 1 which it does not. This is why a manual iteration
here is needed.
> - }
>
> rg = mshv_region_create(mem->guest_pfn, nr_pages,
> mem->userspace_addr, mem->flags,
>
>
next prev parent reply other threads:[~2025-12-03 18:58 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-26 2:08 [PATCH v7 0/7] Introduce movable pages for Hyper-V guests Stanislav Kinsburskii
2025-11-26 2:08 ` [PATCH v7 1/7] Drivers: hv: Refactor and rename memory region handling functions Stanislav Kinsburskii
2025-12-01 11:20 ` Anirudh Rayabharam
2025-11-26 2:08 ` [PATCH v7 2/7] Drivers: hv: Centralize guest memory region destruction Stanislav Kinsburskii
2025-12-01 11:12 ` Anirudh Rayabharam
2025-11-26 2:09 ` [PATCH v7 3/7] Drivers: hv: Move region management to mshv_regions.c Stanislav Kinsburskii
2025-12-01 11:06 ` Anirudh Rayabharam
2025-12-01 16:46 ` Stanislav Kinsburskii
2025-12-03 18:13 ` Nuno Das Neves
2025-12-03 18:20 ` Stanislav Kinsburskii
2025-11-26 2:09 ` [PATCH v7 4/7] Drivers: hv: Fix huge page handling in memory region traversal Stanislav Kinsburskii
2025-11-27 10:59 ` kernel test robot
2025-12-01 15:09 ` Anirudh Rayabharam
2025-12-01 18:26 ` Stanislav Kinsburskii
2025-12-03 18:50 ` Nuno Das Neves
2025-12-04 16:03 ` Michael Kelley
2025-12-04 21:08 ` Stanislav Kinsburskii
2025-12-11 17:37 ` Michael Kelley
2025-12-15 20:12 ` Stanislav Kinsburskii
2025-12-17 0:54 ` Stanislav Kinsburskii
2025-11-26 2:09 ` [PATCH v7 5/7] Drivers: hv: Improve region overlap detection in partition create Stanislav Kinsburskii
2025-12-01 15:06 ` Anirudh Rayabharam
2025-12-02 18:39 ` Michael Kelley
2025-12-03 17:46 ` Stanislav Kinsburskii
2025-12-03 18:58 ` Nuno Das Neves [this message]
2025-12-03 19:36 ` Nuno Das Neves
2025-11-26 2:09 ` [PATCH v7 6/7] Drivers: hv: Add refcount and locking to mem regions Stanislav Kinsburskii
2025-12-04 16:48 ` Michael Kelley
2025-12-04 21:23 ` Stanislav Kinsburskii
2025-11-26 2:09 ` [PATCH v7 7/7] Drivers: hv: Add support for movable memory regions Stanislav Kinsburskii
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=2c853152-c2f8-49c6-a16c-be8aa1b59234@linux.microsoft.com \
--to=nunodasneves@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=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