Commit 7cd138d
KVM: x86/mmu: Optimize and clean up so called "last nonleaf level" logic
Drop the pre-computed last_nonleaf_level, which is arguably wrong and at
best confusing. Per the comment:
Can have large pages at levels 2..last_nonleaf_level-1.
the intent of the variable would appear to be to track what levels can
_legally_ have large pages, but that intent doesn't align with reality.
The computed value will be wrong for 5-level paging, or if 1gb pages are
not supported.
The flawed code is not a problem in practice, because except for 32-bit
PSE paging, bit 7 is reserved if large pages aren't supported at the
level. Take advantage of this invariant and simply omit the level magic
math for 64-bit page tables (including PAE).
For 32-bit paging (non-PAE), the adjustments are needed purely because
bit 7 is ignored if PSE=0. Retain that logic as is, but make
is_last_gpte() unique per PTTYPE so that the PSE check is avoided for
PAE and EPT paging. In the spirit of avoiding branches, bump the "last
nonleaf level" for 32-bit PSE paging by adding the PSE bit itself.
Note, bit 7 is ignored or has other meaning in CR3/EPTP, but despite
FNAME(walk_addr_generic) briefly grabbing CR3/EPTP in "pte", they are
not PTEs and will blow up all the other gpte helpers.
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20210622175739.3610207-51-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>1 parent 616007c commit 7cd138d
3 files changed
Lines changed: 30 additions & 35 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
457 | 457 | | |
458 | 458 | | |
459 | 459 | | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | 460 | | |
464 | 461 | | |
465 | 462 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4071 | 4071 | | |
4072 | 4072 | | |
4073 | 4073 | | |
4074 | | - | |
4075 | | - | |
4076 | | - | |
4077 | | - | |
4078 | | - | |
4079 | | - | |
4080 | | - | |
4081 | | - | |
4082 | | - | |
4083 | | - | |
4084 | | - | |
4085 | | - | |
4086 | | - | |
4087 | | - | |
4088 | | - | |
4089 | | - | |
4090 | | - | |
4091 | | - | |
4092 | | - | |
4093 | | - | |
4094 | 4074 | | |
4095 | 4075 | | |
4096 | 4076 | | |
| |||
4491 | 4471 | | |
4492 | 4472 | | |
4493 | 4473 | | |
4494 | | - | |
4495 | | - | |
4496 | | - | |
4497 | | - | |
4498 | | - | |
4499 | | - | |
4500 | | - | |
4501 | | - | |
4502 | | - | |
4503 | 4474 | | |
4504 | 4475 | | |
4505 | 4476 | | |
| |||
4509 | 4480 | | |
4510 | 4481 | | |
4511 | 4482 | | |
4512 | | - | |
4513 | 4483 | | |
4514 | 4484 | | |
4515 | 4485 | | |
| |||
4783 | 4753 | | |
4784 | 4754 | | |
4785 | 4755 | | |
4786 | | - | |
4787 | 4756 | | |
4788 | 4757 | | |
4789 | 4758 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
308 | 337 | | |
309 | 338 | | |
310 | 339 | | |
| |||
421 | 450 | | |
422 | 451 | | |
423 | 452 | | |
424 | | - | |
| 453 | + | |
425 | 454 | | |
426 | 455 | | |
427 | 456 | | |
| |||
0 commit comments