Bug 1540817

Summary: Libvirt should ignore the cachetune element which have invalid vcpus
Product: Red Hat Enterprise Linux 7 Reporter: Luyao Huang <lhuang>
Component: libvirtAssignee: Martin Kletzander <mkletzan>
Status: CLOSED ERRATA QA Contact: Luyao Huang <lhuang>
Severity: medium Docs Contact:
Priority: low    
Version: 7.5CC: dyuan, lmiksik, mkletzan, mtessun, rbalakri, xuzhang, yalzhang
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-3.9.0-12.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-04-10 11:06:14 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 2018-02-01 05:22:09 UTC
Description of problem:
Libvirt should forbid start a guest with invalid vcpus in the cachetune

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

How reproducible:
100%

Steps to Reproduce:
1. edit guest and set a cachetune element which vcpus > maxvcpus:

  <vcpu placement='static' cpuset='0-2' current='2'>4</vcpu>
  <cputune>
    <cachetune vcpus='0'>
      <cache id='0' level='3' type='code' size='1' unit='MiB'/>
      <cache id='0' level='3' type='data' size='2' unit='MiB'/>
    </cachetune>
    <cachetune vcpus='1'>
      <cache id='0' level='3' type='code' size='2' unit='MiB'/>
      <cache id='0' level='3' type='data' size='1' unit='MiB'/>
    </cachetune>
    <cachetune vcpus='3'>
      <cache id='0' level='3' type='code' size='1' unit='MiB'/>
      <cache id='0' level='3' type='data' size='1' unit='MiB'/>
    </cachetune>
    <cachetune vcpus='1000'>
      <cache id='0' level='3' type='data' size='1' unit='MiB'/>
    </cachetune>
  </cputune>

2. start guest

3. check the resctrl dir, libvirt create a dir for vcpus 1000

# ll /sys/fs/resctrl/
total 0
-rw-r--r--. 1 root root 0 Jan 29 03:44 cpus
-rw-r--r--. 1 root root 0 Jan 29 03:44 cpus_list
dr-xr-xr-x. 5 root root 0 Jan 31 21:29 info
dr-xr-xr-x. 3 root root 0 Jan 31 21:29 mon_data
dr-xr-xr-x. 2 root root 0 Jan 31 21:29 mon_groups
drwxr-xr-x. 4 root root 0 Feb  1 00:18 qemu-3-vm1-vcpus_0
drwxr-xr-x. 4 root root 0 Feb  1 00:18 qemu-3-vm1-vcpus_1
drwxr-xr-x. 4 root root 0 Feb  1 00:18 qemu-3-vm1-vcpus_1000
drwxr-xr-x. 4 root root 0 Feb  1 00:18 qemu-3-vm1-vcpus_3
-rw-r--r--. 1 root root 0 Jan 31 21:28 schemata
-rw-r--r--. 1 root root 0 Jan 29 03:44 tasks

Actual results:
Libvirt allow start a guest with cachtune point to invalid vcpu

Expected results:
report error when start a guest (or forbid this when define/edit guest )

Additional info:

Comment 1 Martin Kletzander 2018-02-01 08:05:22 UTC
It should not be forbidden, but that definitions should just be removed from the XML cleanly.  The same way it is done with `vcpupin` and other tuning options.  The reasoning behind that is that if you have various tunings for a vcpu and you then remove that vcpu (lower the number of them for example) it will take care of removing relevant parts for you.  I'll look into this, thanks for such a quick testing.

Comment 2 Luyao Huang 2018-02-01 08:21:59 UTC
(In reply to Martin Kletzander from comment #1)
> It should not be forbidden, but that definitions should just be removed from
> the XML cleanly.  The same way it is done with `vcpupin` and other tuning
> options.  The reasoning behind that is that if you have various tunings for
> a vcpu and you then remove that vcpu (lower the number of them for example)

Make sense, i will change the bug's description to this, and also thanks for your clearly explanation.

> it will take care of removing relevant parts for you.  I'll look into this,
> thanks for such a quick testing.

You are welcome, that is my duty ;)

Comment 3 Martin Kletzander 2018-02-02 07:26:54 UTC
Patches posted upstream:

https://www.redhat.com/archives/libvir-list/2018-February/msg00088.html

Comment 6 Luyao Huang 2018-02-05 08:44:01 UTC
Verify this bug with libvirt-3.9.0-11.el7.x86_64:

1. try to add a cachetune which have a vcpus number >= maxvcpus:

# virsh edit vm1

  <vcpu placement='static' cpuset='0-2' current='2'>4</vcpu>
  <cputune>
    <cachetune vcpus='0'>
      <cache id='0' level='3' type='both' size='1' unit='MiB'/>
      <cache id='1' level='3' type='both' size='2' unit='MiB'/>
    </cachetune>
    <cachetune vcpus='1'>
      <cache id='0' level='3' type='both' size='2' unit='MiB'/>
      <cache id='1' level='3' type='both' size='1' unit='MiB'/>
    </cachetune>
    <cachetune vcpus='3'>
      <cache id='0' level='3' type='both' size='1' unit='MiB'/>
      <cache id='1' level='3' type='both' size='1' unit='MiB'/>
    </cachetune>
    <cachetune vcpus='4'>
      <cache id='0' level='3' type='both' size='1' unit='MiB'/>
      <cache id='1' level='3' type='both' size='1' unit='MiB'/>
    </cachetune>
    <cachetune vcpus='1000'>
      <cache id='0' level='3' type='both' size='1' unit='MiB'/>
      <cache id='1' level='3' type='both' size='1' unit='MiB'/>
    </cachetune>
  </cputune>


2. recheck xml and libvirt drop the invalid config:

# virsh dumpxml vm1
<domain type='kvm'>
  <name>vm1</name>
  <uuid>f98741e7-ddad-4be1-82c0-0ae3655d1c25</uuid>
  <memory unit='KiB'>1024000</memory>
  <currentMemory unit='KiB'>1024000</currentMemory>
  <vcpu placement='static' cpuset='0-2' current='2'>4</vcpu>
  <cputune>
    <cachetune vcpus='0'>
      <cache id='0' level='3' type='both' size='1' unit='MiB'/>
      <cache id='1' level='3' type='both' size='2' unit='MiB'/>
    </cachetune>
    <cachetune vcpus='1'>
      <cache id='0' level='3' type='both' size='2' unit='MiB'/>
      <cache id='1' level='3' type='both' size='1' unit='MiB'/>
    </cachetune>
    <cachetune vcpus='3'>
      <cache id='0' level='3' type='both' size='1' unit='MiB'/>
      <cache id='1' level='3' type='both' size='1' unit='MiB'/>
    </cachetune>
  </cputune>

Comment 8 Luyao Huang 2018-02-08 02:00:49 UTC
Retest with the same steps in comment 6 on libvirt-3.9.0-12.el7.x86_64, get the same result. Move this bug to verified.

Comment 12 errata-xmlrpc 2018-04-10 11:06:14 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-2018:0704