RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1350391 - Libvirt should check multifunction is enabled on function 0 for multi-functional devices
Summary: Libvirt should check multifunction is enabled on function 0 for multi-functio...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt
Version: 7.3
Hardware: Unspecified
OS: Unspecified
low
low
Target Milestone: rc
: ---
Assignee: Laine Stump
QA Contact: lijuan men
URL:
Whiteboard:
: 1445634 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-06-27 10:28 UTC by Yang Yang
Modified: 2017-08-01 23:53 UTC (History)
7 users (show)

Fixed In Version: libvirt-3.1.0-1.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-08-01 17:11:42 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHEA-2017:1846 0 normal SHIPPED_LIVE libvirt bug fix and enhancement update 2017-08-01 18:02:50 UTC

Description Yang Yang 2016-06-27 10:28:57 UTC
Description of problem:
If multifunction is not enabled on function 0 and setting the function of a device's address to be !=0, the device cannot be found in guest

Version-Release number of selected component (if applicable):
libvirt-1.3.5-1.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1. start vm with 2 virtio disks, function in pci address of vdb is non-zero. I did not enable multifunction on function 0 for slot '0x12' 

<disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/mnt/nfs2/RHEL-7.3-latest.qcow2'/>
      <target dev='vda' bus='virtio'/>
      <boot order='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/mnt/nfs2/virtio1.img'/>
      <target dev='vdb' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x12' function='0x2'/>
    </disk>

# virsh start vm1
Domain vm1 started

# virsh dumpxml vm1 | grep 0x12
      <address type='pci' domain='0x0000' bus='0x00' slot='0x12' function='0x2'/>


2. check disks in guest, cannot find disk vdb
guest]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda           252:0    0   10G  0 disk 
├─vda1        252:1    0  500M  0 part /boot
└─vda2        252:2    0  9.5G  0 part 
  ├─rhel-root 253:0    0  8.5G  0 lvm  /
  └─rhel-swap 253:1    0    1G  0 lvm  [SWAP]

3.

Actual results:
vm is startup normally when I uses multifunction but do not enable multifunction on function 0. Multi-function device cannot be detected
in guest

Expected results:
Libvirt should check function 0 of a multi-function slot is defined and check multifunction is enabled on function 0. And provide prompt messages to users

Additional info:
See also Bug 1341610 - PCI: QEMU must check function 0 is present for multi-function devices

Comment 2 Laine Stump 2016-06-28 15:53:23 UTC
I could never quite understand why qemu's "multifunction" option was exposed to libvirt config at all, since it must always be set for function 0 of a multifunction device, and never set anywhere else at any time (as far as I know), it would make sense to automatically set multifunction=on for function 0 anytime there were other functions used on the same slot. I *think* it also makes sense to forbid having a device attached to a non-0 function on a slot that doesn't have a multifunction=1 device in function 0. But before making a patch to do those things, I want a sanity check from Marcel that there is *absolutely no valid case* for any of the following:

1) setting multifunction=on for any non-0 function
2) leaving multifunction=off on function 0 when there are multiple active 
   functions in the slot..
3) leaving function 0 empty when there are other functions in use on the slot

Comment 3 Marcel Apfelbaum 2016-07-25 12:59:43 UTC
(In reply to Laine Stump from comment #2)
> I could never quite understand why qemu's "multifunction" option was exposed
> to libvirt config at all, since it must always be set for function 0 of a
> multifunction device, and never set anywhere else at any time (as far as I
> know), it would make sense to automatically set multifunction=on for
> function 0 anytime there were other functions used on the same slot. I
> *think* it also makes sense to forbid having a device attached to a non-0
> function on a slot that doesn't have a multifunction=1 device in function 0.
> But before making a patch to do those things, I want a sanity check from
> Marcel that there is *absolutely no valid case* for any of the following:
> 

Hi Laine,

> 1) setting multifunction=on for any non-0 function

Indeed, is not needed, multifuncion flag is per device
PCI spec: 6.2.1
"Header Type: This byte identifies the layout of the second part of the     
              predefined header (beginning at byte 10h in Configuration Space)    
              and alsowhether or not the device contains multiple functions."

> 2) leaving multifunction=off on function 0 when there are multiple active 
>    functions in the slot..

Definitely not allowed. Multifunction is a *device* flag, however in QEMU
we don't have such a modelling. For QEMU function 0 represents the device.

> 3) leaving function 0 empty when there are other functions in use on the slot

Definitely not allowed. The same answer as for 2)

Thanks,
Marcel

Comment 5 Jaroslav Suchanek 2017-04-26 14:55:35 UTC
*** Bug 1445634 has been marked as a duplicate of this bug. ***

Comment 6 Laine Stump 2017-05-22 07:40:16 UTC
This was fixed upstream in libvirt 3.0.0, so it is already in the RHEL7.4 libvirt build:

commit 8f4008713a49873b4bf354321f94b3fdeee14231
Author: Laine Stump <laine>
Date:   Tue Jan 10 00:20:11 2017 -0500

    qemu: use virDomainPCIAddressSetAllMulti() to set multi when needed
    
    If there are multiple devices assigned to the different functions of a
    single PCI slot, they will not work properly if the device at function
    0 doesn't have its "multi" attribute turned on, so it makes sense for
    libvirt to turn it on during PCI address assignment. Setting multi
    then assures that the new setting is stored in the config (so it will
    be used next time the domain is started), preventing any potential
    problems in the case that a future change in the configuration
    eliminates the devices on all non-0 functions (multi will still be set
    for function 0 even though it is the only function in use on the slot,
    which has no useful purpose, but also doesn't cause any problems).
    
    (NB: If we were to instead just decide on the setting for
    multifunction at runtime, a later removal of the non-0 functions of a
    slot would result in a silent change in the guest ABI for the
    remaining device on function 0 (although it may seem like an
    inconsequential guest ABI change, it *is* a guest ABI change to turn
    off the multi bit).)

Comment 9 lijuan men 2017-06-02 03:38:51 UTC
still can reproduce the scenario 

version:
libvirt-3.2.0-7.el7.x86_64
qemu-kvm-rhev-2.9.0-7.el7.x86_64

steps:

1. start a vm with 2 virtio disks, function in pci address of vdb is non-zero. I did not enable multifunction on function 0 for slot '0x09' 

 <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/RHEL-7.4-x86_64-latest.qcow2'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/b.img'/>
      <target dev='vdb' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x2'/>
    </disk>

2.
[root@lmen1 ~]# virsh dumpxml aaa | grep 0x09
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x2'/>

3.check disks in guest, cannot find disk vdb
[root@lmen1 ~]# lsblk
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda           252:0    0  10G  0 disk 
├─vda1        252:1    0   1G  0 part /boot
└─vda2        252:2    0   9G  0 part 
  ├─rhel-root 253:0    0   8G  0 lvm  /
  └─rhel-swap 253:1    0   1G  0 lvm  [SWAP]

Comment 10 Laine Stump 2017-06-19 17:36:36 UTC
Those two devices are on different slots.

As for function 0 of slot 9, there isn't any device using function 0 of slot 9.

The the multifunction attribute will be set automatically for the device on function 0 of slot "X" if another device is assigned to a non-0 function on that same slot "X". That isn't what your test does.

(try using slot='0x08' for both devices and see what happens to the address of the device on function 0)

Comment 11 lijuan men 2017-06-20 03:19:07 UTC
(In reply to Laine Stump from comment #10)
> Those two devices are on different slots.
> 
> As for function 0 of slot 9, there isn't any device using function 0 of slot
> 9.
> 
> The the multifunction attribute will be set automatically for the device on
> function 0 of slot "X" if another device is assigned to a non-0 function on
> that same slot "X". That isn't what your test does.
> 
> (try using slot='0x08' for both devices and see what happens to the address
> of the device on function 0)

thanks for your reply!

1.the scenario I test in comment9 is the same as the bug description

In this scenario, there isn't any device using function 0 of slot 9,but there is one device using function 2 of slot 9,what is the expected result? is it expected that I can't find the device in the guest?



2.I tried the scenario you mentioned in comment10,yes,the result of this scenario is as you said.

1)start a guest with the xml:
<disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/RHEL-7.4-x86_64-latest.qcow2'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/test1.img'/>
      <target dev='vdb' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x2'/>
    </disk>

[root@lmen1 ~]# virsh destroy test;virsh start test
Domain test destroyed

Domain test started

2)check the multifunction='on'
[root@lmen1 ~]# virsh dumpxml test | grep 0x09
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0' multifunction='on'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x2'/>

3)check the disk in the guest

# fdisk -l

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000ab07b

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     2099199     1048576   83  Linux
/dev/vda2         2099200    20971519     9436160   8e  Linux LVM

Disk /dev/vdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

disk can be read/wrote

Comment 12 Laine Stump 2017-06-20 14:10:49 UTC
Okay, I see now that although the Summary of the BZ only mentioned that libvirt should check that multifunction='on' for function 0 when multiple functions of a slot are used, the description and ensuing comments also point out that it should be an error if a slot has nothing in function 0, but devices int any other non-0 functions (I even participated in that discussion, but had forgotten it and didnt read closely when I came back through the BZ several months later).

At this point in the release cycle, I don't think it's advisable to add a patch that results in classifying some configs as incorrect (it could end up causing a previously working config to fail). But since the patch that's already in does fix the problem given in the Summary, I think we should set this BZ to VERIFIED, and open a new BZ to request that any use of a non-0 function on a slot should be an error unless function 0 of that slot is also used.

Comment 13 lijuan men 2017-06-22 03:34:44 UTC
(In reply to Laine Stump from comment #12)
> Okay, I see now that although the Summary of the BZ only mentioned that
> libvirt should check that multifunction='on' for function 0 when multiple
> functions of a slot are used, the description and ensuing comments also
> point out that it should be an error if a slot has nothing in function 0,
> but devices int any other non-0 functions (I even participated in that
> discussion, but had forgotten it and didnt read closely when I came back
> through the BZ several months later).
> 
> At this point in the release cycle, I don't think it's advisable to add a
> patch that results in classifying some configs as incorrect (it could end up
> causing a previously working config to fail). But since the patch that's
> already in does fix the problem given in the Summary, I think we should set
> this BZ to VERIFIED, and open a new BZ to request that any use of a non-0
> function on a slot should be an error unless function 0 of that slot is also
> used.

ok,mark this bug as verified

and file a new bug to track this issue:
Bug 1463892 - any use of a non-0 function on a slot should be an error unless function 0 of that slot is also used

Comment 14 errata-xmlrpc 2017-08-01 17:11:42 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2017:1846

Comment 15 errata-xmlrpc 2017-08-01 23:53:19 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2017:1846


Note You need to log in before you can comment on or make changes to this bug.