Commit a3522ac
KVM: x86/mmu: Enforce guest_memfd's max order when recovering hugepages
Rework kvm_mmu_max_mapping_level() to provide the plumbing to consult
guest_memfd (and relevant vendor code) when recovering hugepages, e.g.
after disabling live migration. The flaw has existed since guest_memfd was
originally added, but has gone unnoticed due to lack of guest_memfd support
for hugepages or dirty logging.
Don't actually call into guest_memfd at this time, as it's unclear as to
what the API should be. Ideally, KVM would simply use kvm_gmem_get_pfn(),
but invoking kvm_gmem_get_pfn() would lead to sleeping in atomic context
if guest_memfd needed to allocate memory (mmu_lock is held). Luckily,
the path isn't actually reachable, so just add a TODO and WARN to ensure
the functionality is added alongisde guest_memfd hugepage support, and
punt the guest_memfd API design question to the future.
Note, calling kvm_mem_is_private() in the non-fault path is safe, so long
as mmu_lock is held, as hugepage recovery operates on shadow-present SPTEs,
i.e. calling kvm_mmu_max_mapping_level() with @fault=NULL is mutually
exclusive with kvm_vm_set_mem_attributes() changing the PRIVATE attribute
of the gfn.
Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Fuad Tabba <tabba@google.com>
Message-ID: <20250729225455.670324-15-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>1 parent 1c3fdf1 commit a3522ac
3 files changed
Lines changed: 47 additions & 35 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3302 | 3302 | | |
3303 | 3303 | | |
3304 | 3304 | | |
3305 | | - | |
3306 | | - | |
| 3305 | + | |
| 3306 | + | |
3307 | 3307 | | |
3308 | | - | |
| 3308 | + | |
| 3309 | + | |
3309 | 3310 | | |
3310 | | - | |
3311 | | - | |
| 3311 | + | |
| 3312 | + | |
| 3313 | + | |
| 3314 | + | |
| 3315 | + | |
| 3316 | + | |
| 3317 | + | |
| 3318 | + | |
| 3319 | + | |
| 3320 | + | |
3312 | 3321 | | |
3313 | | - | |
3314 | 3322 | | |
3315 | | - | |
| 3323 | + | |
3316 | 3324 | | |
3317 | | - | |
3318 | | - | |
3319 | | - | |
| 3325 | + | |
| 3326 | + | |
| 3327 | + | |
| 3328 | + | |
| 3329 | + | |
| 3330 | + | |
| 3331 | + | |
| 3332 | + | |
3320 | 3333 | | |
3321 | 3334 | | |
3322 | 3335 | | |
3323 | 3336 | | |
3324 | | - | |
3325 | | - | |
3326 | | - | |
| 3337 | + | |
| 3338 | + | |
3327 | 3339 | | |
3328 | 3340 | | |
3329 | | - | |
| 3341 | + | |
| 3342 | + | |
| 3343 | + | |
| 3344 | + | |
| 3345 | + | |
| 3346 | + | |
| 3347 | + | |
| 3348 | + | |
| 3349 | + | |
| 3350 | + | |
| 3351 | + | |
| 3352 | + | |
3330 | 3353 | | |
3331 | 3354 | | |
3332 | 3355 | | |
| |||
3335 | 3358 | | |
3336 | 3359 | | |
3337 | 3360 | | |
3338 | | - | |
3339 | | - | |
3340 | | - | |
3341 | 3361 | | |
3342 | 3362 | | |
3343 | 3363 | | |
3344 | | - | |
| 3364 | + | |
| 3365 | + | |
| 3366 | + | |
| 3367 | + | |
3345 | 3368 | | |
3346 | 3369 | | |
3347 | 3370 | | |
3348 | | - | |
3349 | | - | |
3350 | | - | |
3351 | | - | |
3352 | | - | |
3353 | | - | |
3354 | | - | |
3355 | | - | |
3356 | | - | |
3357 | 3371 | | |
3358 | 3372 | | |
3359 | 3373 | | |
| |||
3374 | 3388 | | |
3375 | 3389 | | |
3376 | 3390 | | |
3377 | | - | |
3378 | | - | |
3379 | | - | |
| 3391 | + | |
| 3392 | + | |
3380 | 3393 | | |
3381 | 3394 | | |
3382 | 3395 | | |
| |||
4564 | 4577 | | |
4565 | 4578 | | |
4566 | 4579 | | |
4567 | | - | |
4568 | | - | |
| 4580 | + | |
4569 | 4581 | | |
4570 | 4582 | | |
4571 | 4583 | | |
| |||
7165 | 7177 | | |
7166 | 7178 | | |
7167 | 7179 | | |
7168 | | - | |
| 7180 | + | |
7169 | 7181 | | |
7170 | 7182 | | |
7171 | 7183 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
414 | | - | |
| 414 | + | |
415 | 415 | | |
416 | 416 | | |
417 | 417 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1813 | 1813 | | |
1814 | 1814 | | |
1815 | 1815 | | |
1816 | | - | |
| 1816 | + | |
1817 | 1817 | | |
1818 | 1818 | | |
1819 | 1819 | | |
| |||
0 commit comments