On Fri, Dec 31, 2021, Zeng Guang wrote: > +static int vmx_expand_pid_table(struct kvm_vmx *kvm_vmx, int entry_idx) > +{ > + u64 *last_pid_table; > + int last_table_size, new_order; > + > + if (entry_idx <= kvm_vmx->pid_last_index) > + return 0; > + > + last_pid_table = kvm_vmx->pid_table; > + last_table_size = table_index_to_size(kvm_vmx->pid_last_index + 1); > + new_order = get_order(table_index_to_size(entry_idx + 1)); > + > + if (vmx_alloc_pid_table(kvm_vmx, new_order)) > + return -ENOMEM; > + > + memcpy(kvm_vmx->pid_table, last_pid_table, last_table_size); > + kvm_make_all_cpus_request(&kvm_vmx->kvm, KVM_REQ_PID_TABLE_UPDATE); > + > + /* Now old PID table can be freed safely as no vCPU is using it. */ > + free_pages((unsigned long)last_pid_table, get_order(last_table_size)); This is terrifying. I think it's safe? But it's still terrifying. Rather than dynamically react as vCPUs are created, what about we make max_vcpus common[*], extend KVM_CAP_MAX_VCPUS to allow userspace to override max_vcpus, and then have the IPIv support allocate the PID table on first vCPU creation instead of in vmx_vm_init()? That will give userspace an opportunity to lower max_vcpus to reduce memory consumption without needing to dynamically muck with the table in KVM. Then this entire patch goes away.