Commit 11d9846
KVM: x86: Allocate/free user_return_msrs at kvm.ko (un)loading time
Move user_return_msrs allocation/free from vendor modules (kvm-intel.ko and
kvm-amd.ko) (un)loading time to kvm.ko's to make it less risky to access
user_return_msrs in kvm.ko. Tying the lifetime of user_return_msrs to
vendor modules makes every access to user_return_msrs prone to
use-after-free issues as vendor modules may be unloaded at any time.
Opportunistically turn the per-CPU variable into full structs, as there's
no practical difference between statically allocating the memory and
allocating it unconditionally during module_init().
Zero out kvm_nr_uret_msrs on vendor module exit to further minimize the
chances of consuming stale data, and WARN on vendor module load if KVM
thinks there are existing user-return MSRs.
Note! The user-return MSRs also need to be "destroyed" if
ops->hardware_setup() fails, as both SVM and VMX expect common KVM to
clean up (because common code, not vendor code, is responsible for
kvm_nr_uret_msrs).
Signed-off-by: Chao Gao <chao.gao@intel.com>
Co-developed-by: Sean Christopherson <seanjc@google.com>
Link: https://patch.msgid.link/20251108013601.902918-1-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>1 parent e78fb96 commit 11d9846
1 file changed
+13
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
212 | | - | |
| 212 | + | |
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| |||
572 | 572 | | |
573 | 573 | | |
574 | 574 | | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
581 | | - | |
582 | | - | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
| 575 | + | |
587 | 576 | | |
588 | 577 | | |
589 | 578 | | |
590 | 579 | | |
591 | | - | |
| 580 | + | |
592 | 581 | | |
593 | | - | |
| 582 | + | |
594 | 583 | | |
595 | 584 | | |
596 | 585 | | |
| |||
653 | 642 | | |
654 | 643 | | |
655 | 644 | | |
656 | | - | |
| 645 | + | |
657 | 646 | | |
658 | 647 | | |
659 | 648 | | |
| |||
675 | 664 | | |
676 | 665 | | |
677 | 666 | | |
678 | | - | |
| 667 | + | |
679 | 668 | | |
680 | 669 | | |
681 | 670 | | |
| |||
693 | 682 | | |
694 | 683 | | |
695 | 684 | | |
696 | | - | |
| 685 | + | |
697 | 686 | | |
698 | 687 | | |
699 | 688 | | |
700 | 689 | | |
701 | 690 | | |
702 | | - | |
| 691 | + | |
703 | 692 | | |
704 | 693 | | |
705 | 694 | | |
| |||
10022 | 10011 | | |
10023 | 10012 | | |
10024 | 10013 | | |
10025 | | - | |
10026 | | - | |
10027 | | - | |
10028 | | - | |
10029 | 10014 | | |
10030 | 10015 | | |
10031 | | - | |
| 10016 | + | |
10032 | 10017 | | |
10033 | 10018 | | |
10034 | 10019 | | |
| |||
10053 | 10038 | | |
10054 | 10039 | | |
10055 | 10040 | | |
| 10041 | + | |
| 10042 | + | |
10056 | 10043 | | |
10057 | 10044 | | |
10058 | 10045 | | |
| |||
10125 | 10112 | | |
10126 | 10113 | | |
10127 | 10114 | | |
| 10115 | + | |
10128 | 10116 | | |
10129 | | - | |
10130 | | - | |
10131 | 10117 | | |
10132 | 10118 | | |
10133 | 10119 | | |
| |||
10155 | 10141 | | |
10156 | 10142 | | |
10157 | 10143 | | |
| 10144 | + | |
10158 | 10145 | | |
10159 | | - | |
10160 | 10146 | | |
10161 | 10147 | | |
10162 | 10148 | | |
| |||
0 commit comments