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

Kimchi should re-attach PCI to host when detaching from guest #1073

Closed
alinefm opened this issue Nov 1, 2016 · 0 comments
Closed

Kimchi should re-attach PCI to host when detaching from guest #1073

alinefm opened this issue Nov 1, 2016 · 0 comments
Assignees
Labels
Milestone

Comments

@alinefm
Copy link
Member

alinefm commented Nov 1, 2016

Assignment of PCI adapter to the guest immediately removes device and it's children from the host. But when detaching it, it is still missing on host.
When detaching a PCI device, it should be re-attached to the host.

@alinefm alinefm added the bug label Nov 1, 2016
@alinefm alinefm added this to the Kimchi 2.3.1 milestone Nov 1, 2016
@alinefm alinefm self-assigned this Nov 1, 2016
@alinefm alinefm closed this as completed in a45663b Jan 4, 2017
alinefm pushed a commit that referenced this issue Jan 30, 2017
Before this commit, Kimchi was mass detaching PCI devices when
trying to detach a single dev 'hostdev0' following this criteria:

- using the source address element, see all hostdevs that share
the same PCI address (domain x bus x slot) as 'hostdev0';

- if more than one is found, 'hostdev0' is considered to be
a multifunction device an a mass detachment of all devices found
is made.

This logic is flawed when considering SR-IOV devices (CX4 cards
for example). Although all virtual functions share the same
source PCI address, each VF should be attached and detached
individually.

Following the current libvirt documentation
(https://libvirt.org/formatdomain.html), there is an attribute
called 'multifunction' that can be used:

'Also available is the multifunction attribute, which controls
turning on the multifunction bit for a particular slot/function
in the PCI control register (...) multifunction defaults to 'off',
but should be set to 'on' for function 0 of a slot that will have
multiple functions used.'

Further experimentation showed that, in multifunction devices,
the device PCI address differs only in the 'function' attribute,
while in the VFs for example they are different. This means that
the device address is a better place to look for paired devices
instead of using the source PCI address.

This patch implements these changes to fix #1096: use the multifunction
attribute to determine if a hostdev is multifuction and changed
the 'get_devices_same_addr' method to use the device address instead
of the source PCI address as comparison.

This patch also makes changes on the work done in bug fix #1073.
The re-attach of the recently detached devices is not necessary
when the device was set to 'managed' mode. In fact, re-attaching
VFs set with managed='yes' was causing libvirt instability. This patch
adds this verification and avoids the re-attach in these cases.

Minor simplications of vmhostdevs.py code were also made, such
as use a dict instead of an array of tuples to easily retrieve
elements by a key and moved the NotFound verification up in
the '_detach_device' method.

Unit tests included.

Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
pgurenko pushed a commit to pgurenko/kimchi that referenced this issue Apr 22, 2019
…it from guest

Signed-off-by: Aline Manera <alinefm@linux.vnet.ibm.com>
pgurenko pushed a commit to pgurenko/kimchi that referenced this issue Apr 22, 2019
… address

Before this commit, Kimchi was mass detaching PCI devices when
trying to detach a single dev 'hostdev0' following this criteria:

- using the source address element, see all hostdevs that share
the same PCI address (domain x bus x slot) as 'hostdev0';

- if more than one is found, 'hostdev0' is considered to be
a multifunction device an a mass detachment of all devices found
is made.

This logic is flawed when considering SR-IOV devices (CX4 cards
for example). Although all virtual functions share the same
source PCI address, each VF should be attached and detached
individually.

Following the current libvirt documentation
(https://libvirt.org/formatdomain.html), there is an attribute
called 'multifunction' that can be used:

'Also available is the multifunction attribute, which controls
turning on the multifunction bit for a particular slot/function
in the PCI control register (...) multifunction defaults to 'off',
but should be set to 'on' for function 0 of a slot that will have
multiple functions used.'

Further experimentation showed that, in multifunction devices,
the device PCI address differs only in the 'function' attribute,
while in the VFs for example they are different. This means that
the device address is a better place to look for paired devices
instead of using the source PCI address.

This patch implements these changes to fix kimchi-project#1096: use the multifunction
attribute to determine if a hostdev is multifuction and changed
the 'get_devices_same_addr' method to use the device address instead
of the source PCI address as comparison.

This patch also makes changes on the work done in bug fix kimchi-project#1073.
The re-attach of the recently detached devices is not necessary
when the device was set to 'managed' mode. In fact, re-attaching
VFs set with managed='yes' was causing libvirt instability. This patch
adds this verification and avoids the re-attach in these cases.

Minor simplications of vmhostdevs.py code were also made, such
as use a dict instead of an array of tuples to easily retrieve
elements by a key and moved the NotFound verification up in
the '_detach_device' method.

Unit tests included.

Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant