[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <dc3fa33d-8f9e-46f0-9fd1-248684a36c8b@linux.microsoft.com>
Date: Wed, 3 Dec 2025 11:36:08 -0800
From: Nuno Das Neves <nunodasneves@...ux.microsoft.com>
To: Stanislav Kinsburskii <skinsburskii@...ux.microsoft.com>,
kys@...rosoft.com, haiyangz@...rosoft.com, wei.liu@...nel.org,
decui@...rosoft.com
Cc: linux-hyperv@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v7 5/7] Drivers: hv: Improve region overlap detection in
partition create
On 12/3/2025 10:58 AM, Nuno Das Neves wrote:
> 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@...ux.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.
>
Apologies, after sending this I realized you already dropped the patch.
>> - }
>>
>> rg = mshv_region_create(mem->guest_pfn, nr_pages,
>> mem->userspace_addr, mem->flags,
>>
>>
>
Powered by blists - more mailing lists