[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PULL v2 37/61] accel/kvm: Extract common KVM vCPU {creation,parking
From: |
Peter Maydell |
Subject: |
Re: [PULL v2 37/61] accel/kvm: Extract common KVM vCPU {creation,parking} code |
Date: |
Thu, 25 Jul 2024 13:27:15 +0100 |
On Thu, 25 Jul 2024 at 13:05, Salil Mehta <salil.mehta@huawei.com> wrote:
>
> HI Peter,
>
> > From: Peter Maydell <peter.maydell@linaro.org>
> > Sent: Thursday, July 25, 2024 11:36 AM
> > To: Michael S. Tsirkin <mst@redhat.com>
> >
> > On Tue, 23 Jul 2024 at 11:58, Michael S. Tsirkin <mst@redhat.com> wrote:
> > >
> > > From: Salil Mehta <salil.mehta@huawei.com>
> > >
> > > KVM vCPU creation is done once during the vCPU realization when Qemu
> > > vCPU thread is spawned. This is common to all the architectures as of
> > now.
> > >
> > > Hot-unplug of vCPU results in destruction of the vCPU object in QOM
> > > but the corresponding KVM vCPU object in the Host KVM is not destroyed
> > > as KVM doesn't support vCPU removal. Therefore, its representative KVM
> > > vCPU object/context in Qemu is parked.
> > >
> > > Refactor architecture common logic so that some APIs could be reused
> > > by vCPU Hotplug code of some architectures likes ARM, Loongson etc.
> > > Update new/old APIs with trace events. New APIs
> > > qemu_{create,park,unpark}_vcpu() can be externally called. No functional
> > change is intended here.
> >
> > Hi; Coverity points out an issue with this code (CID 1558552):
> >
> > > +int kvm_unpark_vcpu(KVMState *s, unsigned long vcpu_id) {
> > > + struct KVMParkedVcpu *cpu;
> > > + int kvm_fd = -ENOENT;
> > > +
> > > + QLIST_FOREACH(cpu, &s->kvm_parked_vcpus, node) {
> > > + if (cpu->vcpu_id == vcpu_id) {
> > > + QLIST_REMOVE(cpu, node);
> > > + kvm_fd = cpu->kvm_fd;
> > > + g_free(cpu);
> > > + }
> > > + }
> >
> > If you are going to remove an entry from a list as you iterate over it, you
> > can't use QLIST_FOREACH(), because QLIST_FOREACH will look at the next
> > pointer of the iteration variable at the end of the loop when it wants to
> > advance to the next node. In this case we've already freed 'cpu', so it
> > would
> > be reading freed memory.
> >
> > Should we break out of the loop when we find the entry?
>
>
> Thanks for identifying this. Yes, a break is missing. Should I send a fix
> for this
> now or you can incorporate it?
The code is already in upstream git, so please send a patch
to fix the bug.
thanks
-- PMM
- [PULL v2 33/61] virtio-pci: Implement SR-IOV PF, (continued)
- [PULL v2 33/61] virtio-pci: Implement SR-IOV PF, Michael S. Tsirkin, 2024/07/23
- [PULL v2 32/61] pcie_sriov: Allow user to create SR-IOV device, Michael S. Tsirkin, 2024/07/23
- [PULL v2 34/61] virtio-net: Implement SR-IOV VF, Michael S. Tsirkin, 2024/07/23
- [PULL v2 35/61] docs: Document composable SR-IOV device, Michael S. Tsirkin, 2024/07/23
- [PULL v2 36/61] smbios: make memory device size configurable per Machine, Michael S. Tsirkin, 2024/07/23
- [PULL v2 37/61] accel/kvm: Extract common KVM vCPU {creation,parking} code, Michael S. Tsirkin, 2024/07/23
[PULL v2 38/61] hw/acpi: Move CPU ctrl-dev MMIO region len macro to common header file, Michael S. Tsirkin, 2024/07/23
[PULL v2 39/61] hw/acpi: Update ACPI GED framework to support vCPU Hotplug, Michael S. Tsirkin, 2024/07/23
[PULL v2 40/61] hw/acpi: Update GED _EVT method AML with CPU scan, Michael S. Tsirkin, 2024/07/23
[PULL v2 41/61] hw/acpi: Update CPUs AML with cpu-(ctrl)dev change, Michael S. Tsirkin, 2024/07/23
[PULL v2 42/61] physmem: Add helper function to destroy CPU AddressSpace, Michael S. Tsirkin, 2024/07/23
[PULL v2 43/61] gdbstub: Add helper function to unregister GDB register space, Michael S. Tsirkin, 2024/07/23
[PULL v2 45/61] virtio-iommu: Remove probe_done, Michael S. Tsirkin, 2024/07/23
[PULL v2 44/61] Revert "virtio-iommu: Clear IOMMUDevice when VFIO device is unplugged", Michael S. Tsirkin, 2024/07/23
[PULL v2 46/61] virtio-iommu: Free [host_]resv_ranges on unset_iommu_devices, Michael S. Tsirkin, 2024/07/23