File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,8 @@ struct kvm_hyp_memcache {
86
86
phys_addr_t head ;
87
87
unsigned long nr_pages ;
88
88
struct pkvm_mapping * mapping ; /* only used from EL1 */
89
+
90
+ #define HYP_MEMCACHE_ACCOUNT_STAGE2 BIT(1)
89
91
unsigned long flags ;
90
92
};
91
93
Original file line number Diff line number Diff line change @@ -1088,12 +1088,24 @@ void kvm_free_stage2_pgd(struct kvm_s2_mmu *mmu)
1088
1088
1089
1089
static void hyp_mc_free_fn (void * addr , void * mc )
1090
1090
{
1091
+ struct kvm_hyp_memcache * memcache = mc ;
1092
+
1093
+ if (memcache -> flags & HYP_MEMCACHE_ACCOUNT_STAGE2 )
1094
+ kvm_account_pgtable_pages (addr , -1 );
1095
+
1091
1096
free_page ((unsigned long )addr );
1092
1097
}
1093
1098
1094
1099
static void * hyp_mc_alloc_fn (void * mc )
1095
1100
{
1096
- return (void * )__get_free_page (GFP_KERNEL_ACCOUNT );
1101
+ struct kvm_hyp_memcache * memcache = mc ;
1102
+ void * addr ;
1103
+
1104
+ addr = (void * )__get_free_page (GFP_KERNEL_ACCOUNT );
1105
+ if (addr && memcache -> flags & HYP_MEMCACHE_ACCOUNT_STAGE2 )
1106
+ kvm_account_pgtable_pages (addr , 1 );
1107
+
1108
+ return addr ;
1097
1109
}
1098
1110
1099
1111
void free_hyp_memcache (struct kvm_hyp_memcache * mc )
Original file line number Diff line number Diff line change @@ -165,12 +165,16 @@ static int __pkvm_create_hyp_vm(struct kvm *host_kvm)
165
165
handle = ret ;
166
166
167
167
host_kvm -> arch .pkvm .handle = handle ;
168
+ host_kvm -> arch .pkvm .stage2_teardown_mc .flags |= HYP_MEMCACHE_ACCOUNT_STAGE2 ;
169
+ kvm_account_pgtable_pages (pgd , pgd_sz / PAGE_SIZE );
168
170
169
171
/* Donate memory for the vcpus at hyp and initialize it. */
170
172
hyp_vcpu_sz = PAGE_ALIGN (PKVM_HYP_VCPU_SIZE );
171
173
kvm_for_each_vcpu (idx , host_vcpu , host_kvm ) {
172
174
void * hyp_vcpu ;
173
175
176
+ host_vcpu -> arch .pkvm_memcache .flags |= HYP_MEMCACHE_ACCOUNT_STAGE2 ;
177
+
174
178
/* Indexing of the vcpus to be sequential starting at 0. */
175
179
if (WARN_ON (host_vcpu -> vcpu_idx != idx )) {
176
180
ret = - EINVAL ;
You can’t perform that action at this time.
0 commit comments