Commit c0e0812
committed
[TEMP] KVM: guest_memfd: Update gmem_prepare hook to handle partially-allocated folios
TODO: move to bitmap-based tracking within gmem
Marking the whole folio uptodate as part of kvm_gmem_populate() doesn't
work as expected for THP because kvm_gmem_populate() might only update a
subset of the pages, leaving the other pages still needing the
gmem_prepare hooks to be called when they are faulted in later.
Eventually this will be tracked by introducing a more granular flag than
uptodate that can track whether any particular 4K page has been prepared
or not.
For now however, modify kvm_gmem_populate() to only set the uptodate
flag if the entire 2M range is initialized, and leave it unset afterward
so gmem_prepare hooks still run. The gmem_prepare() hooks themselves
can already track page states at 4K granularity via the RMP table, so
are fully capable of dealing with partially-initialized folios.
As an optimization, also allow kvm_gmem_prepare() to set the uptodate
flag if the whole folio is already in a private/initialized state to
avoid needing to scan the RMP entries for each subpage.
Effectively, this makes the uptodate flag an optimization to skip RMP
checks within a fully-prepared folio, but in the absence of the uptodate
flag the RMP table is ultimately the authority on preparation state of
an individual sub-page within a folio.
Signed-off-by: Michael Roth <michael.roth@amd.com>1 parent 46cf7f3 commit c0e0812
2 files changed
Lines changed: 92 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2189 | 2189 | | |
2190 | 2190 | | |
2191 | 2191 | | |
| 2192 | + | |
| 2193 | + | |
| 2194 | + | |
2192 | 2195 | | |
2193 | 2196 | | |
2194 | 2197 | | |
| |||
4745 | 4748 | | |
4746 | 4749 | | |
4747 | 4750 | | |
| 4751 | + | |
| 4752 | + | |
| 4753 | + | |
| 4754 | + | |
| 4755 | + | |
| 4756 | + | |
| 4757 | + | |
| 4758 | + | |
| 4759 | + | |
| 4760 | + | |
| 4761 | + | |
| 4762 | + | |
| 4763 | + | |
| 4764 | + | |
| 4765 | + | |
| 4766 | + | |
| 4767 | + | |
| 4768 | + | |
| 4769 | + | |
| 4770 | + | |
| 4771 | + | |
| 4772 | + | |
| 4773 | + | |
| 4774 | + | |
| 4775 | + | |
| 4776 | + | |
| 4777 | + | |
4748 | 4778 | | |
4749 | 4779 | | |
4750 | 4780 | | |
| |||
4800 | 4830 | | |
4801 | 4831 | | |
4802 | 4832 | | |
| 4833 | + | |
4803 | 4834 | | |
4804 | 4835 | | |
4805 | 4836 | | |
| |||
4830 | 4861 | | |
4831 | 4862 | | |
4832 | 4863 | | |
| 4864 | + | |
| 4865 | + | |
| 4866 | + | |
| 4867 | + | |
| 4868 | + | |
| 4869 | + | |
| 4870 | + | |
| 4871 | + | |
| 4872 | + | |
| 4873 | + | |
4833 | 4874 | | |
4834 | 4875 | | |
4835 | 4876 | | |
| |||
4840 | 4881 | | |
4841 | 4882 | | |
4842 | 4883 | | |
| 4884 | + | |
| 4885 | + | |
| 4886 | + | |
| 4887 | + | |
| 4888 | + | |
| 4889 | + | |
| 4890 | + | |
| 4891 | + | |
| 4892 | + | |
4843 | 4893 | | |
4844 | 4894 | | |
4845 | 4895 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | 62 | | |
68 | 63 | | |
69 | 64 | | |
| |||
77 | 72 | | |
78 | 73 | | |
79 | 74 | | |
80 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
81 | 78 | | |
82 | 79 | | |
83 | 80 | | |
84 | | - | |
85 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
86 | 85 | | |
87 | 86 | | |
88 | 87 | | |
| |||
126 | 125 | | |
127 | 126 | | |
128 | 127 | | |
129 | | - | |
| 128 | + | |
| 129 | + | |
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
| 133 | + | |
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
139 | 141 | | |
140 | 142 | | |
141 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
142 | 158 | | |
143 | 159 | | |
144 | 160 | | |
| |||
606 | 622 | | |
607 | 623 | | |
608 | 624 | | |
609 | | - | |
| 625 | + | |
| 626 | + | |
610 | 627 | | |
611 | 628 | | |
612 | 629 | | |
| |||
624 | 641 | | |
625 | 642 | | |
626 | 643 | | |
627 | | - | |
| 644 | + | |
628 | 645 | | |
629 | 646 | | |
630 | 647 | | |
| |||
636 | 653 | | |
637 | 654 | | |
638 | 655 | | |
639 | | - | |
| 656 | + | |
640 | 657 | | |
641 | | - | |
| 658 | + | |
642 | 659 | | |
643 | | - | |
| 660 | + | |
644 | 661 | | |
645 | 662 | | |
646 | 663 | | |
| |||
670 | 687 | | |
671 | 688 | | |
672 | 689 | | |
673 | | - | |
| 690 | + | |
674 | 691 | | |
675 | 692 | | |
676 | 693 | | |
| |||
730 | 747 | | |
731 | 748 | | |
732 | 749 | | |
733 | | - | |
| 750 | + | |
734 | 751 | | |
735 | 752 | | |
736 | 753 | | |
737 | 754 | | |
738 | 755 | | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
739 | 760 | | |
740 | 761 | | |
741 | 762 | | |
| |||
758 | 779 | | |
759 | 780 | | |
760 | 781 | | |
761 | | - | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
762 | 785 | | |
| 786 | + | |
763 | 787 | | |
764 | 788 | | |
765 | 789 | | |
| |||
0 commit comments