Bug 1629717 - qemu_ram_mmap: Assertion `is_power_of_2(align)' failed
Summary: qemu_ram_mmap: Assertion `is_power_of_2(align)' failed
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: qemu-kvm-rhev
Version: 7.6
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: rc
: ---
Assignee: David Hildenbrand
QA Contact: Yumei Huang
URL:
Whiteboard:
Depends On:
Blocks: 1649160 1630746 1651787
TreeView+ depends on / blocked
 
Reported: 2018-09-17 12:00 UTC by Yumei Huang
Modified: 2019-08-22 09:19 UTC (History)
8 users (show)

Fixed In Version: qemu-kvm-rhev-2.12.0-19.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1630746 (view as bug list)
Environment:
Last Closed: 2019-08-22 09:18:53 UTC
Target Upstream Version:


Attachments (Terms of Use)


Links
System ID Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2019:2553 None None None 2019-08-22 09:19:46 UTC

Description Yumei Huang 2018-09-17 12:00:24 UTC
Description of problem:
Boot guest with nvdimm device, set align=1.5G, qemu core dumped.
 
qemu-kvm: util/mmap-alloc.c:105: qemu_ram_mmap: Assertion `is_power_of_2(align)' failed.
Aborted (core dumped)

Version-Release number of selected component (if applicable):
qemu-kvm-rhev-2.12.0-16.el7
kernel-3.10.0-948.el7.x86_64

How reproducible:
always

Steps to Reproduce:
1. #  /usr/libexec/qemu-kvm -m 4G,slots=20,maxmem=50G -M pc,nvdimm -object memory-backend-file,id=mem1,size=2G,mem-path=/tmp/nvdimm1,share,align=1.5G -device nvdimm,memdev=mem1,id=nv1 



Actual results:
qemu-kvm: util/mmap-alloc.c:105: qemu_ram_mmap: Assertion `is_power_of_2(align)' failed.
Aborted (core dumped)

Expected results:
No core dump.

Additional info:

Comment 2 Yumei Huang 2018-09-17 12:16:34 UTC
It is introduced by commit '9837684316 hostmem-file: add "align" option'.

Comment 4 Ademar Reis 2018-09-17 16:42:12 UTC
Different assert() being hit, but similar problem as bug 1629720.

I'm lowering the severity and deferring it to 7.7 + 7.6.z, because I don't think this should block RHEL-7.6, just like bug 1629720.

Comment 5 pagupta 2018-09-18 03:56:10 UTC
Hi,

align option is for host side address alignment. "align=1.5G" is not the correct value and it asserts on `is_power_of_2(align)'. It acts as an indication for the user to restart the VM with appropriate value. This is important file backed memory and needs to be power of 2. Check is for expected behaviour. Don't think its a bug or regression.

Thanks,
Pankaj

Comment 6 Yumei Huang 2018-09-18 04:59:04 UTC
(In reply to pagupta from comment #5)
> Hi,
> 
> align option is for host side address alignment. "align=1.5G" is not the
> correct value and it asserts on `is_power_of_2(align)'. It acts as an
> indication for the user to restart the VM with appropriate value. This is
> important file backed memory and needs to be power of 2. Check is for
> expected behaviour. Don't think its a bug or regression.

It's fine to print the error message, but it causes qemu core dumped, which I think is an issue need to be fixed. Besides, if hotplug the backend to a alive guest, qemu would core dumped too, might cause terrible consequence. IMO, that's definitely a bug. Thanks!

> 
> Thanks,
> Pankaj

Comment 7 pagupta 2018-09-18 06:00:17 UTC
(In reply to Yumei Huang from comment #6)
> (In reply to pagupta from comment #5)
> > Hi,
> > 
> > align option is for host side address alignment. "align=1.5G" is not the
> > correct value and it asserts on `is_power_of_2(align)'. It acts as an
> > indication for the user to restart the VM with appropriate value. This is
> > important file backed memory and needs to be power of 2. Check is for
> > expected behaviour. Don't think its a bug or regression.
> 
> It's fine to print the error message, but it causes qemu core dumped, which
> I think is an issue need to be fixed. Besides, if hotplug the backend to a
> alive guest, qemu would core dumped too, might cause terrible consequence.
> IMO, that's definitely a bug. Thanks!

Agree, Just thinking what's the right thing to do:

1] Asset VM start if file backed memory is misalign.

2] Throw an error at VM start and allow VM to start with :
   a) Not properly align file backed memory - might not be the best thing to do.
   b) Should not allow to add file backed memory if it is not properly aligned.

3] If hotplug backend to live guest also has misalign memory than hotplug   
   interface should check and throw an error thus does not effect live VM.

Among these scenarios I feel 1] & 3] should be right thing to do.

Thanks,
Pankaj

Comment 8 pagupta 2018-09-19 10:41:12 UTC
Hi,

This is fixed in upstream qemu, version >= v3.0.0. New check is added for align "is_power_of_2" in function "file_ram_alloc". This avoids assert in function "mmap-alloc.c:qemu_ram_mmap".
------------------

commit 61362b71c105ccb151ca16897a7d56534423f390
Author: David Hildenbrand <david@redhat.com>
Date:   Thu Jun 7 17:47:05 2018 +0200

    exec: check that alignment is a power of two
    
    Right now we can crash QEMU using e.g.
    
    qemu-system-x86_64 -m 256M,maxmem=20G,slots=2 \
     -object memory-backend-file,id=mem0,size=12288,mem-path=/dev/zero,align=12288 \
     -device pc-dimm,id=dimm1,memdev=mem0
    
    qemu-system-x86_64: util/mmap-alloc.c:115:
     qemu_ram_mmap: Assertion `is_power_of_2(align)' failed
    
    Fix this by adding a proper check.
    
    Signed-off-by: David Hildenbrand <david@redhat.com>
    Message-Id: <20180607154705.6316-3-david@redhat.com>
    Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
    Reviewed-by: Igor Mammedov <imammedo@redhat.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>


Thanks,
Pankaj

Comment 9 Miroslav Rezanina 2018-11-21 15:14:18 UTC
Fix included in qemu-kvm-rhev-2.12.0-19.el7

Comment 10 Yumei Huang 2018-11-29 08:03:20 UTC
Verify:
qemu-kvm-rhev-2.12.0-19.el7

QEMU quits with error message when boot with align=1.5G:

# /usr/libexec/qemu-kvm -m 4G,slots=20,maxmem=50G -M pc,nvdimm -object memory-backend-file,id=mem1,size=2G,mem-path=/tmp/nvdimm1,share,align=1.5G -device nvdimm,memdev=mem1,id=nv1 
qemu-kvm: -object memory-backend-file,id=mem1,size=2G,mem-path=/tmp/nvdimm1,share,align=1.5G: alignment 0x60000000 must be a power of two


If hotplug the object after guest boot up, hmp prints error message and guest works well.

# /usr/libexec/qemu-kvm -m 4G,slots=20,maxmem=50G -M pc,nvdimm -monitor  stdio  rhel76-64-virtio-scsi.qcow2  -vnc :0
(qemu) object_add  memory-backend-file,id=mem1,size=2G,mem-path=/tmp/nvdimm1,share,align=1.5G
alignment 0x60000000 must be a power of two
(qemu) info memdev

(qemu) info status
VM status: running

Comment 12 errata-xmlrpc 2019-08-22 09:18:53 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/RHSA-2019:2553


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