Commit 85ef1ac
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 <[email protected]>1 parent 4a43efc commit 85ef1ac
2 files changed
+91
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2271 | 2271 | | |
2272 | 2272 | | |
2273 | 2273 | | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
2274 | 2277 | | |
2275 | 2278 | | |
2276 | 2279 | | |
| |||
4775 | 4778 | | |
4776 | 4779 | | |
4777 | 4780 | | |
| 4781 | + | |
| 4782 | + | |
| 4783 | + | |
| 4784 | + | |
| 4785 | + | |
| 4786 | + | |
| 4787 | + | |
| 4788 | + | |
| 4789 | + | |
| 4790 | + | |
| 4791 | + | |
| 4792 | + | |
| 4793 | + | |
| 4794 | + | |
| 4795 | + | |
| 4796 | + | |
| 4797 | + | |
| 4798 | + | |
| 4799 | + | |
| 4800 | + | |
| 4801 | + | |
| 4802 | + | |
| 4803 | + | |
| 4804 | + | |
| 4805 | + | |
| 4806 | + | |
| 4807 | + | |
4778 | 4808 | | |
4779 | 4809 | | |
4780 | 4810 | | |
| |||
4830 | 4860 | | |
4831 | 4861 | | |
4832 | 4862 | | |
| 4863 | + | |
4833 | 4864 | | |
4834 | 4865 | | |
4835 | 4866 | | |
| |||
4860 | 4891 | | |
4861 | 4892 | | |
4862 | 4893 | | |
| 4894 | + | |
| 4895 | + | |
| 4896 | + | |
| 4897 | + | |
| 4898 | + | |
| 4899 | + | |
| 4900 | + | |
| 4901 | + | |
| 4902 | + | |
| 4903 | + | |
4863 | 4904 | | |
4864 | 4905 | | |
4865 | 4906 | | |
| |||
4870 | 4911 | | |
4871 | 4912 | | |
4872 | 4913 | | |
| 4914 | + | |
| 4915 | + | |
| 4916 | + | |
| 4917 | + | |
| 4918 | + | |
| 4919 | + | |
| 4920 | + | |
| 4921 | + | |
| 4922 | + | |
4873 | 4923 | | |
4874 | 4924 | | |
4875 | 4925 | | |
| |||
| 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 | | |
| |||
592 | 608 | | |
593 | 609 | | |
594 | 610 | | |
595 | | - | |
| 611 | + | |
596 | 612 | | |
597 | 613 | | |
598 | 614 | | |
| |||
610 | 626 | | |
611 | 627 | | |
612 | 628 | | |
613 | | - | |
| 629 | + | |
614 | 630 | | |
615 | 631 | | |
616 | 632 | | |
| |||
622 | 638 | | |
623 | 639 | | |
624 | 640 | | |
625 | | - | |
| 641 | + | |
626 | 642 | | |
627 | | - | |
| 643 | + | |
628 | 644 | | |
629 | | - | |
| 645 | + | |
630 | 646 | | |
631 | 647 | | |
632 | 648 | | |
| |||
654 | 670 | | |
655 | 671 | | |
656 | 672 | | |
657 | | - | |
| 673 | + | |
658 | 674 | | |
659 | 675 | | |
660 | 676 | | |
| |||
710 | 726 | | |
711 | 727 | | |
712 | 728 | | |
713 | | - | |
| 729 | + | |
714 | 730 | | |
715 | 731 | | |
716 | 732 | | |
717 | 733 | | |
718 | 734 | | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
719 | 739 | | |
720 | 740 | | |
721 | 741 | | |
| |||
738 | 758 | | |
739 | 759 | | |
740 | 760 | | |
741 | | - | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
742 | 764 | | |
| 765 | + | |
743 | 766 | | |
744 | 767 | | |
745 | 768 | | |
| |||
0 commit comments