Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vsock: avoid circular references #499

Merged
merged 3 commits into from
Oct 27, 2023

Conversation

stefano-garzarella
Copy link
Member

Summary of the PR

We have the following circular references found by Li Zebin:
VhostUserBackend ==> VhostUserVsockThread ==> VringEpollHandler

In addition to causing a resource leak, this causes also an error after we merged commit 38caab2 ("vsock: Don't allow duplicate CIDs"). When the VM reboot or shutdown, the application exits with the following error:

[ERROR vhost_device_vsock] Could not create backend:
    CID already in use by another vsock device

This happened because we have these circular references and VhostUserVsockThread::drop() is never invoked. So, we don't remove the cid from the map.

Let's fix this problem by simply removing the reference to VringEpollHandler from VhostUserVsockThread. In fact, we do not need to keep the reference for the lifetime of VhostUserVsockThread, as we only need to add the handlers once.

Let's also rename the fields to follow the current VhostUserDaemon API.

Closes #438

Reported-by: Li Zebin cutelizebin@gmail.com

Requirements

Before submitting your PR, please make sure you addressed the following
requirements:

  • All commits in this PR are signed (with git commit -s), and the commit
    message has max 60 characters for the summary and max 75 characters for each
    description line.
  • All added/changed functionality has a corresponding unit/integration
    test.
  • All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • Any newly added unsafe code is properly documented.

We have the following circular references found by Li Zebin:
    VhostUserBackend ==> VhostUserVsockThread ==> VringEpollHandler

In addition to causing a resource leak, this causes also an error
after we merged commit 38caab2 ("vsock: Don't allow duplicate CIDs").
When the VM reboot or shutdown, the application exits with the
following error:

    [ERROR vhost_device_vsock] Could not create backend:
        CID already in use by another vsock device

This happened because we have these circular references and
VhostUserVsockThread::drop() is never invoked. So, we don't remove
the cid from the map.

Let's fix this problem by simply removing the reference to
VringEpollHandler from VhostUserVsockThread. In fact, we do not
need to keep the reference for the lifetime of VhostUserVsockThread,
as we only need to add the handlers once.

Let's also rename the fields to follow the current VhostUserDaemon
API.

Closes rust-vmm#438

Reported-by: Li Zebin <cutelizebin@gmail.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
@stefano-garzarella
Copy link
Member Author

Rebased

@vireshk vireshk enabled auto-merge (rebase) October 25, 2023 07:45
@vireshk vireshk merged commit 09e9da3 into rust-vmm:main Oct 27, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] vsock: Mem leak caused by circular referencing
5 participants