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 {
8686 phys_addr_t head ;
8787 unsigned long nr_pages ;
8888 struct pkvm_mapping * mapping ; /* only used from EL1 */
89+
90+ #define HYP_MEMCACHE_ACCOUNT_STAGE2 BIT(1)
8991 unsigned long flags ;
9092};
9193
Original file line number Diff line number Diff line change @@ -1088,12 +1088,24 @@ void kvm_free_stage2_pgd(struct kvm_s2_mmu *mmu)
10881088
10891089static void hyp_mc_free_fn (void * addr , void * mc )
10901090{
1091+ struct kvm_hyp_memcache * memcache = mc ;
1092+
1093+ if (memcache -> flags & HYP_MEMCACHE_ACCOUNT_STAGE2 )
1094+ kvm_account_pgtable_pages (addr , -1 );
1095+
10911096 free_page ((unsigned long )addr );
10921097}
10931098
10941099static void * hyp_mc_alloc_fn (void * mc )
10951100{
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 ;
10971109}
10981110
10991111void 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)
165165 handle = ret ;
166166
167167 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 );
168170
169171 /* Donate memory for the vcpus at hyp and initialize it. */
170172 hyp_vcpu_sz = PAGE_ALIGN (PKVM_HYP_VCPU_SIZE );
171173 kvm_for_each_vcpu (idx , host_vcpu , host_kvm ) {
172174 void * hyp_vcpu ;
173175
176+ host_vcpu -> arch .pkvm_memcache .flags |= HYP_MEMCACHE_ACCOUNT_STAGE2 ;
177+
174178 /* Indexing of the vcpus to be sequential starting at 0. */
175179 if (WARN_ON (host_vcpu -> vcpu_idx != idx )) {
176180 ret = - EINVAL ;
You can’t perform that action at this time.
0 commit comments