Bug 27845 - Introduce retry mechanism when KVM fails to pin pages for CSV3 shared memory
Summary: Introduce retry mechanism when KVM fails to pin pages for CSV3 shared memory
Status: NEW
Alias: None
Product: ANCK 5.10 Dev
Classification: ANCK
Component: ARCH(unspecified) (show other bugs) ARCH(unspecified)
Version: unspecified
Hardware: All Linux
: P3-Medium S3-normal
Target Milestone: ---
Assignee: 谭钦云
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-12-09 16:31 UTC by wojiaohanliyang
Modified: 2025-12-22 11:43 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description wojiaohanliyang hygon_group 2025-12-09 16:31:49 UTC
Description of problem:

There is a bug related to the LRU flag in the Anolis OS community's 5.10 kernel. The root cause is that when memory pages are held in a pagevec and have not yet been moved to their correct LRU lists, repeated setting of the LRU flag occurs. During memory page migration in the host kernel's mm subsystem, this incorrect LRU flag causes failures in locking memory pages.

If a shared memory region of a CSV3 virtual machine is not mapped in the nested page tables, accessing this region will trigger a #NPF (Nested Page Fault). In such cases, KVM needs to pin (lock) the corresponding physical page to back the shared memory region for the virtual machine. However, if pinning the physical page fails and an error is returned to QEMU, the virtual machine may hang—a behavior that is unfriendly to production users.
A better approach is to resume the virtual machine directly upon pinning failure, allowing it to re-trigger the #NPF. Unless the host kernel’s memory management subsystem has a severe bug or is under sustained extreme memory pressure, the virtual machine’s subsequent #NPF will eventually be handled correctly.

The shared memory regions of a CSV3 virtual machine may be backed by either standard 4KB small pages or 2MB hugetlb/THP (Transparent Huge Pages) large pages. KVM tracks all physical pages corresponding to the shared memory regions of CSV3 virtual machines, but it does not record whether each physical page is a small page or a large page.
When a memory region of the virtual machine transitions from shared back to private, KVM or QEMU should release the corresponding physical pages. However, because KVM currently lacks information about whether those pages are small or large, blindly releasing physical pages poses a potential risk: if a single large page contains multiple small shared memory regions, releasing it prematurely could corrupt other still-shared regions.
This patch introduces fine-grained tracking of how physical pages are used by shared memory regions in CSV3 virtual machines. It ensures that a physical page is released only when it no longer contains any shared memory region.
Additionally, this patch adds a new interface for interaction with QEMU. When a memory region transitions from private to shared, QEMU can now directly pin (lock) the physical pages backing that shared region. Consequently, when the virtual machine accesses the shared memory and triggers a #NPF (Nested Page Fault), the #NPF handler can immediately retrieve the already-pinned physical page, significantly accelerating #NPF resolution. This optimization alleviates contention during concurrent #NPF handling across many CSV3 virtual machines trying to pin pages simultaneously, thereby improving perceived responsiveness and user experience.

Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1.
2.
3.

Actual results:


Expected results:


Additional info:
Comment 1 小龙 admin 2025-12-09 16:44:36 UTC
The PR Link: https://gitee.com/anolis/cloud-kernel/pulls/6120