Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
shimv2: Close vhostfd after vm get vhostfd
Browse files Browse the repository at this point in the history
If kata containers is using vfio and vhost net,the unbinding
of vfio would be hang. In the scenario, vhost net kernel thread
takes a reference to the qemu's mm, and the reference also includes
the mmap regions on the vfio device file. so vhost kernel thread
would be not released when qemu is killed as the vhost file
descriptor still is opened by shim v2 process, and the vfio device
is not released because there's still a reference to the mmap.

Fixes: #1669

Signed-off-by: Yang, Wei <[email protected]>
Signed-off-by: Eric Ernst <[email protected]>
(cherry picked from commit 071030b)
Signed-off-by: Ganesh Maharaj Mahalingam <[email protected]>
  • Loading branch information
xs3c authored and Ganesh Maharaj Mahalingam committed Jun 4, 2019
1 parent db441a8 commit 5564b6d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions virtcontainers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ func createSandboxFromConfig(ctx context.Context, sandboxConfig SandboxConfig, f
}
}()

s.postCreatedNetwork()

if err = s.getAndStoreGuestDetails(); err != nil {
return nil, err
}
Expand Down
26 changes: 26 additions & 0 deletions virtcontainers/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,32 @@ func (n *Network) Add(ctx context.Context, config *NetworkConfig, hypervisor hyp
return endpoints, nil
}

func (n *Network) PostAdd(ctx context.Context, ns *NetworkNamespace, hotplug bool) error {
if hotplug {
return nil
}

if ns.Endpoints == nil {
return nil
}

endpoints := ns.Endpoints

for _, endpoint := range endpoints {
netPair := endpoint.NetworkPair()
if netPair == nil {
continue
}
if netPair.VhostFds != nil {
for _, VhostFd := range netPair.VhostFds {
VhostFd.Close()
}
}
}

return nil
}

// Remove network endpoints in the network namespace. It also deletes the network
// namespace in case the namespace has been created by us.
func (n *Network) Remove(ctx context.Context, ns *NetworkNamespace, hypervisor hypervisor, hotunplug bool) error {
Expand Down
1 change: 1 addition & 0 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ func (q *qemu) hotAddNetDevice(name, hardAddr string, VMFds, VhostFds []*os.File
if err := q.qmpMonitorCh.qmp.ExecuteGetFD(q.qmpMonitorCh.ctx, fdName, VhostFd); err != nil {
return err
}
VhostFd.Close()
VhostFdNames = append(VhostFdNames, fdName)
}
return q.qmpMonitorCh.qmp.ExecuteNetdevAddByFds(q.qmpMonitorCh.ctx, "tap", name, VMFdNames, VhostFdNames)
Expand Down
5 changes: 5 additions & 0 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,11 @@ func (s *Sandbox) createNetwork() error {
return s.store.Store(store.Network, s.networkNS)
}

func (s *Sandbox) postCreatedNetwork() error {

return s.network.PostAdd(s.ctx, &s.networkNS, s.factory != nil)
}

func (s *Sandbox) removeNetwork() error {
span, _ := s.trace("removeNetwork")
defer span.Finish()
Expand Down

0 comments on commit 5564b6d

Please sign in to comment.