Bug 1452454

Summary: libvirt attach nvdimm device with invalid access type
Product: Red Hat Enterprise Linux 7 Reporter: chhu
Component: libvirtAssignee: Peter Krempa <pkrempa>
Status: CLOSED ERRATA QA Contact: chhu
Severity: medium Docs Contact:
Priority: unspecified    
Version: 7.4CC: dyuan, lhuang, pkrempa, rbalakri, xuzhang, yalzhang
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-3.2.0-6.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-08-02 01:34:35 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 chhu 2017-05-19 05:01:21 UTC
Description of problem:
libvirt attach nvdimm device with invalid access type

Version-Release number of selected component (if applicable):
libvirt-3.2.0-5.el7.x86_64
qemu-kvm-rhev-2.9.0-4.el7.x86_64
kernel-3.10.0-660.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1. Create nvdimm file on the host:
     # truncate -s 512M /tmp/nvdimm
     # truncate -s 256M /tmp/nvdimm2

2. Start a guest with one nvdimm device successfully.
 <maxMemory slots='16' unit='M'>2048</maxMemory>
  <memory unit='M'>1024</memory>
  <currentMemory unit='M'>512</currentMemory>
  <vcpu placement='static'>4</vcpu>
  .......
  <cpu mode='host-model' check='partial'>
    <model fallback='allow'/>
    <topology sockets='2' cores='1' threads='1'/>
    <numa>
      <cell id='0' cpus='0-1' memory='512' unit='M'/>
      <cell id='1' cpus='2-3' memory='512' unit='M'/>
    </numa>
  </cpu>
......
         <memory model='nvdimm' access='shared'>
      <source>
        <path>/tmp/nvdimm</path>
      </source>
      <target>
        <size unit='M'>512</size>
        <node>1</node>
        <label>
          <size unit='KiB'>256</size>
        </label>
      </target>
      <address type='dimm' slot='0'/>
    </memory>
  </devices>

3. Try to attach a nvdimm device with access='shar', attached the device, the access='(null)'
# cat  nvdimm.xml
   <memory model='nvdimm' access='shar'>
      <source>
        <path>/tmp/nvdimm2</path>
      </source>
      <target>
        <size unit='M'>256</size>
        <node>1</node>
         <label>
          <size unit='KiB'>128</size>
        </label>
      </target>
      <address type='dimm' slot='1'/>
    </memory>

# virsh attach-device r7-4 nvdimm.xml
Device attached successfully

# virsh dumpxml r7-4 | grep nvdimm -A 15
    <memory model='nvdimm' access='shared'>
      <source>
        <path>/tmp/nvdimm</path>
      </source>
      <target>
        <size unit='KiB'>524288</size>
        <node>1</node>
        <label>
          <size unit='KiB'>256</size>
        </label>
      </target>
      <alias name='nvdimm0'/>
      <address type='dimm' slot='0' base='0x100000000'/>
    </memory>
    <memory model='nvdimm' access='(null)'>
      <source>
        <path>/tmp/nvdimm2</path>
      </source>
      <target>
        <size unit='KiB'>262144</size>
        <node>1</node>
        <label>
          <size unit='KiB'>128</size>
        </label>
      </target>
      <alias name='nvdimm1'/>
      <address type='dimm' slot='1' base='0x11ffc0000'/>
    </memory>

Actual results:
Attached nvdimm device with access='shar' in step3, and the access='null' in dumpxml.

Expected results:
Get error in step3, as the access type should be 'shared' or 'private'.

Comment 2 Peter Krempa 2017-05-19 10:21:40 UTC
Fixed upstream:

commit 85d62624c5d02c38e00a275dc2b2957584454908
Author: Peter Krempa <pkrempa>
Date:   Fri May 19 10:25:00 2017 +0200

    conf: Don't assign value from ..TypeFromString directly to enum
    
    Enums are unsigned, so it's impossible to check whether the helper
    returned -1 for invalid conversions.

Comment 5 chhu 2017-06-09 05:56:41 UTC
Verified on packages:
libvirt-3.2.0-9.el7.x86_64
qemu-img-rhev-2.9.0-9.el7.x86_64
kernel-3.10.0-679.el7.x86_64

Test steps:
1. Create nvdimm file on the host:
     # truncate -s 512M /tmp/nvdimm
     # truncate -s 256M /tmp/nvdimm2

2. Start a guest with one nvdimm device successfully.
 <maxMemory slots='16' unit='M'>2048</maxMemory>
  <memory unit='M'>1024</memory>
  <currentMemory unit='M'>512</currentMemory>
  <vcpu placement='static'>4</vcpu>
  .......
  <cpu mode='host-model' check='partial'>
    <model fallback='allow'/>
    <topology sockets='2' cores='2' threads='1'/>
    <numa>
      <cell id='0' cpus='0-1' memory='512' unit='M'/>
      <cell id='1' cpus='2-3' memory='512' unit='M'/>
    </numa>
  </cpu>
......
         <memory model='nvdimm' access='shared'>
      <source>
        <path>/tmp/nvdimm</path>
      </source>
      <target>
        <size unit='M'>512</size>
        <node>0</node>
        <label>
          <size unit='KiB'>256</size>
        </label>
      </target>
      <address type='dimm' slot='0'/>
    </memory>
  </devices>

3. Try to attach a nvdimm device with access='shar', failed with error message.
# cat nvdimm.xml
   <memory model='nvdimm' access='shar'>
      <source>
        <path>/tmp/nvdimm2</path>
      </source>
      <target>
        <size unit='M'>256</size>
        <node>1</node>
         <label>
          <size unit='KiB'>128</size>
        </label>
      </target>
      <address type='dimm' slot='1'/>
    </memory>

# virsh attach-device r7t nvdimm.xml
error: Failed to attach device from nvdimm.xml
error: XML error: invalid access mode 'shar'

4. Edit the access='shared', attach the nvdimm device to the guest.
# virsh attach-device r7t nvdimm.xml
Device attached successfully

Comment 6 errata-xmlrpc 2017-08-02 01:34:35 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