Linux-HyperV List
 help / color / mirror / Atom feed
From: Mukesh R <mrathor@linux.microsoft.com>
To: sashiko-reviews@lists.linux.dev
Cc: linux-hyperv@vger.kernel.org
Subject: Re: [PATCH V2 2/3] mshv: Redesign hypervisor memory deposit logic
Date: Fri, 25 Sep 2026 14:33:18 -0700	[thread overview]
Message-ID: <44536e5f-efcd-c9d4-7619-d2343c7b7f9f@linux.microsoft.com> (raw)
In-Reply-To: <20260912001508.0C31C1F000FF@smtp.kernel.org>

On 9/11/26 17:15, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] Memory leak of all un-deposited pages when `hv_do_rep_hypercall` returns `U64_MAX`.
> --
> 
> commit 68b286f4de61fdc1a888242cfc4b1a1ea3d187dc
> Author: Mukesh R <mrathor@linux.microsoft.com>
> 
> mshv: Redesign hypervisor memory deposit logic
> 
> This commit redesigns the hypervisor memory deposit logic to optimize
> performance and address preexisting issues. It defaults to allocating and
> depositing 2M chunks when possible to reduce overhead and avoids unnecessary
> interrupt disabling during the process.
> 
>> diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c
>> index 57864bb5bcd8c..df39a5c587ca2 100644
>> --- a/drivers/hv/hv_proc.c
>> +++ b/drivers/hv/hv_proc.c
> [ ... ]
>> +static int hv_call_deposit_pages(int node, u64 partition_id, bool contiguous)
>> +{
> [ ... ]
>> +	/* Not using hyperv_pcpu_input_arg, so no need to disable interrupts */
>> +
>> +	status = hv_do_rep_hypercall(HVCALL_DEPOSIT_MEMORY, num_pages, 0,
>> +				     hc_input, NULL);
>> +	if (!hv_result_success(status))
>> +		goto err_free_dep_pages;
>> +
>> +	if (lastpfn) {
>> +		hc_input->gpa_page_list[0] = lastpfn;
>> +		status = hv_do_rep_hypercall(HVCALL_DEPOSIT_MEMORY, 1, 0,
>> +					     hc_input, NULL);
>> +
>> +		if (!hv_result_success(status) && hv_repcomp(status) == 0)
> 
> [Severity: Medium]
> Will this leak the page pointed to by lastpfn if hv_do_rep_hypercall() returns
> U64_MAX?
> 
> If the hypervisor is unavailable or hypercalls are unsupported,
> hv_do_rep_hypercall() can return the sentinel value U64_MAX, which is explicitly
> handled by hv_result_to_errno() elsewhere.
> 
> When status is U64_MAX, the hv_repcomp(status) macro extracts bits 43:32, which
> results in 4095 instead of 0.
> 
> Does this cause the condition to evaluate to false and skip freeing the page?

This hypercall will not return U64_MAX.


>> +			/* We deposited lot earlier, so give it a go */
>> +			__free_page(pfn_to_page(lastpfn));
>> +	}
>> +
>> +	free_page((unsigned long)hc_input);
>> +	return 0;
>> +
>> +err_free_dep_pages:
>> +	hv_status_err(status, "\n");
>> +	rc = hv_result_to_errno(status);
>> +
>> +	for (i = hv_repcomp(status); i < num_pages; i++)
> 
> [Severity: Medium]
> Will this loop fail to free any pages in the pfna[] array when status is
> U64_MAX?
> 
> Similar to the check above, if status is U64_MAX, hv_repcomp(status) evaluates
> to 4095.
> 
> Since num_pages is bounded to a maximum of 511 (HV_DEPOSIT_INP_MAX) in this
> path, the loop initialization sets i = 4095, making the condition i < num_pages
> immediately false.
> 
> Does this cause the loop to terminate without executing, silently leaking up to
> 511 allocated pages per failed deposit attempt?


status cannot be U64_MAX for this hypercall.


>> +		__free_page(pfn_to_page(pfna[i]));
>> +	if (lastpfn)
>> +		__free_page(pfn_to_page(lastpfn));
>> +
>> +out_free:
>> +	free_page((unsigned long)hc_input);
>> +	return rc;
>> +}
> 


  reply	other threads:[~2026-09-25 21:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-12  0:03 [PATCH V2 0/3] MSHV: Redesign memory deposit logic Mukesh R
2026-09-12  0:03 ` [PATCH V2 1/3] mshv: Rename memory deposit memory functions to _old Mukesh R
2026-09-12  0:03 ` [PATCH V2 2/3] mshv: Redesign hypervisor memory deposit logic Mukesh R
2026-09-12  0:15   ` sashiko-bot
2026-09-25 21:33     ` Mukesh R [this message]
2026-10-01  7:03   ` Souradeep Chakrabarti
2026-09-12  0:03 ` [PATCH V2 3/3] mshv: Remove unused *_old memory deposit functions 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=44536e5f-efcd-c9d4-7619-d2343c7b7f9f@linux.microsoft.com \
    --to=mrathor@linux.microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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