Bug 1249981

Summary: iothreadpin will pin one of libvirtd thread with qemu 1.5
Product: Red Hat Enterprise Linux 7 Reporter: Luyao Huang <lhuang>
Component: libvirtAssignee: John Ferlan <jferlan>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: low Docs Contact:
Priority: low    
Version: 7.2CC: dyuan, lmen, mzhan, rbalakri, xuzhang
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-1.3.1-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-11-03 18:22:13 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Luyao Huang 2015-08-04 09:56:32 UTC
Description of problem:
iothreadpin will pin one of libvirtd thread with qemu 1.5

Version-Release number of selected component (if applicable):
qemu-kvm-1.5.3-97.el7.x86_64
libvirt-1.2.17-3.el7.x86_64

How reproducible:
100%

Steps to Reproduce:

1. prepare a guest with iothreadpin:

# virsh dumpxml test4 |grep iothread
  <iothreads>1</iothreads>
  <iothreadids>
    <iothread id='1'/>
  </iothreadids>
    <iothreadpin iothread='1' cpuset='2'/>


2. start it and check libvirt set in cgroup

# ll /proc/9580/task/
total 0
dr-xr-xr-x. 6 qemu qemu 0 Jul 27 10:31 9580    <----emulator
dr-xr-xr-x. 6 qemu qemu 0 Jul 27 10:32 9589    <----vcpu0
dr-xr-xr-x. 6 qemu qemu 0 Jul 27 10:32 9591    <----vcpu1
dr-xr-xr-x. 6 qemu qemu 0 Jul 27 10:32 9600    <----???

# cat /sys/fs/cgroup/cpuset/machine.slice/machine-qemu\\x2dtest4.scope/iothread1/cpuset.cpus
2

# cat /sys/fs/cgroup/cpuset/machine.slice/machine-qemu\\x2dtest4.scope/iothread1/tasks 
4402

# ps -eLf |grep 4402
root      4391     1  4402  0   16 10:28 ?        00:00:00 /usr/sbin/libvirtd
root     16347 19012 16347  0    1 11:15 pts/0    00:00:00 grep --color=auto 4402

3. check taskset
# taskset --cpu-list -p 4402
pid 4402's current affinity list: 2


4. Then try to change the iothreadpin and recheck the result:

# virsh iothreadpin test4 1 3 

# taskset --cpu-list -p 4402
pid 4402's current affinity list: 3

# cat /sys/fs/cgroup/cpuset/machine.slice/machine-qemu\\x2dtest4.scope/iothread1/cpuset.cpus
3


Actual results:
iothreadpin will pin one of libvirtd thread with qemu 1.5

Expected results:
forbid use iotreadpin with qemu which not support iothread

Additional info:

This is because we cannot get iothread_id and it's value is 0, and then we call
sched_setaffinity() and attach thread in cgroup, but when the pid/task is 0, these functions will attach the current thread, you can check kernel doc Documentation/cgroups/cgroups.txt:

You can attach the current shell task by echoing 0:

# echo 0 > tasks

and manual of sched_setaffinity(2):

Specifying pid as 0 will set the attribute for the calling thread

So i think we should also forbid set 0 as a pid when call these functions.

Comment 1 John Ferlan 2015-10-15 21:30:36 UTC
Posted some patches upstream...

v1: http://www.redhat.com/archives/libvir-list/2015-October/msg00417.html
(patches 1 & 2)

v2:  http://www.redhat.com/archives/libvir-list/2015-October/msg00550.html
(patches 1 -> 3)

Comment 2 John Ferlan 2015-10-16 11:10:38 UTC
Patches pushed upstream

$ git describe cc2d49f9be13e439efcdbd4e1c161750f4208995
v1.2.20-112-gcc2d49f
$

Comment 3 John Ferlan 2015-12-02 20:58:59 UTC
*** Bug 1272349 has been marked as a duplicate of this bug. ***

Comment 5 Luyao Huang 2016-08-11 02:36:48 UTC
Verify this bug with qemu-kvm-1.5.3-121.el7.x86_64 and libvirt-2.0.0-5.el7.x86_64:

1. try to start a guest with iothread:

# virsh dumpxml r7-old
<domain type='kvm'>
  <name>r7-old</name>
  <uuid>5b256268-87b9-40bf-a857-38715dd8a37b</uuid>
  <memory unit='KiB'>1048576</memory>
  <currentMemory unit='KiB'>1048576</currentMemory>
  <vcpu placement='auto' current='6'>10</vcpu>
  <iothreads>1</iothreads>

# virsh start r7-old
error: Failed to start domain r7-old
error: unsupported configuration: IOThreads not supported for this QEMU

2. try to attach iothread to a exist guest:

# virsh list
 Id    Name                           State
----------------------------------------------------
 12    r7-old                         running

# virsh iothreadinfo r7-old
error: Unable to get domain IOThreads information
error: unsupported configuration: IOThreads not supported with this binary

# virsh iothreadadd r7-old 1
error: unsupported configuration: IOThreads not supported with this binary

# virsh iothreaddel r7-old 1
error: unsupported configuration: IOThreads not supported with this binary

Comment 7 errata-xmlrpc 2016-11-03 18:22:13 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://rhn.redhat.com/errata/RHSA-2016-2577.html