]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
mshv: Fix error handling in mshv_region_pin
authorStanislav Kinsburskii <skinsburskii@linux.microsoft.com>
Tue, 17 Mar 2026 15:04:55 +0000 (15:04 +0000)
committerWei Liu <wei.liu@kernel.org>
Wed, 18 Mar 2026 16:18:49 +0000 (16:18 +0000)
commitc0e296f257671ba10249630fe58026f29e4804d9
tree15244ebc5e65d91f5832db482caee18ac0389fe2
parentb2ae73d954f71c7dd605eecfd817ed018dce7cc7
mshv: Fix error handling in mshv_region_pin

The current error handling has two issues:

First, pin_user_pages_fast() can return a short pin count (less than
requested but greater than zero) when it cannot pin all requested pages.
This is treated as success, leading to partially pinned regions being
used, which causes memory corruption.

Second, when an error occurs mid-loop, already pinned pages from the
current batch are not properly accounted for before calling
mshv_region_invalidate_pages(), causing a page reference leak.

Treat short pins as errors and fix partial batch accounting before
cleanup.

Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>
drivers/hv/mshv_regions.c