Skip to contentSkip to conversation

Xen BUG at page_alloc.c:1738 (Xen 4.5)

DISCUSSION Jason Fritcher 4 participants 11 messages May 29, 2015 – Jun 6, 2015

lore
Share & tools
lore
#0 lore raw
Quoted 10 lines · Major Hayden
Quoted 9 lines · Jan Beulich

Considering that no-one else is seeing this - is this perhaps connected to you building Xen with pre-release gcc 5.0.1? This is also because in order for the above to indeed occur, mmio_ro_do_page_fault()'s put_page() would need to drop the last reference of a page, yet page_get_owner_and_reference() doesn't obtain a reference when a page is unallocated (and hence unowned), i.e. normally a page would have a refcount of at least 2 here. Hence this would be possible only due to a race, but the exact same race to be observed on different hardware _and_ under an emulator is extremely unlikely.

You could try with the xen.gz file from
https://copr-be.cloud.fedoraproject.org/results/myoung/xentest/fedora-21-x86_64/xen-4.5.1-0.rc1.fc21/xen-hypervisor-4.5.1-0.rc1.fc21.x86_64.rpm <https://copr-be.cloud.fedoraproject.org/results/myoung/xentest/fedora-21-x86_64/xen-4.5.1-0.rc1.fc21/xen-hypervisor-4.5.1-0.rc1.fc21.x86_64.rpm>
It is roughly the same version of xen but built against Fedora 21 and gcc
4.9.2. If that works then it probably is gcc 5.
Greetings,

I have run into pretty much the same issue as the original poster.

I am running a recently updated Arch Linux system, with GCC 5.1.0, using UEFI and gummiboot to boot. I currently have a build of Xen 4.4.1, built with GCC 4.9.2 from before my last update, that is functioning correctly on this machine. But the builds of Xen 4.5.0, using GCC 5 and mingw64-binutils for the EFI binary, are all failing when Xen starts the Linux kernel, with the same error mentioned in the subject. Below is the boot log I captured via the serial port.

http://pastebin.com/bBC78306

Wondering if my specific toolchain was the issue, I downloaded the Fedora 22 version of xen-hypervisor and installed its EFI Xen binary over my compiled binary and received an identical error message, with slightly different addresses in the panic dump. The Fedora version was compiled with GCC 5.0.1. Below is the boot log I captured from that binary.

http://pastebin.com/jvg1JazC <http://pastebin.com/jvg1JazC>

After finding this thread, and specifically, the quoted message above, I downloaded that xen-hypervisor package and installed its EFI Xen binary. That binary boots successfully, as seen by the captured boot log below.

http://pastebin.com/DKxwaU2U

So, while I’m not familiar enough with Xen to begin to have an idea of what could possibly be wrong with Xen or GCC 5 to be causing this bug, I’d like to do what I can to track down the issue so I can get a working build of Xen 4.5. :)

Thanks!

—
Jason Fritcher

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#1 lore raw
Quoted 45 lines · Jason Fritcher
Quoted 10 lines · Major Hayden

/ On 05/20/2015 05:41 AM, Jan Beulich wrote:/
/ > Considering that no-one else is seeing this - is this perhaps connected/ / > to you building Xen with pre-release gcc 5.0.1? This is also because in/ / > order for the above to indeed occur, mmio_ro_do_page_fault()'s/ / > put_page() would need to drop the last reference of a page, yet/ / > page_get_owner_and_reference() doesn't obtain a reference when/ / > a page is unallocated (and hence unowned), i.e. normally a page/ / > would have a refcount of at least 2 here. Hence this would be/ / > possible only due to a race, but the exact same race to be observed/ / > on different hardware _and_ under an emulator is extremely unlikely./

You could try with the xen.gz file from
https://copr-be.cloud.fedoraproject.org/results/myoung/xentest/fedora-21-x86_64/xen-4.5.1-0.rc1.fc21/xen-hypervisor-4.5.1-0.rc1.fc21.x86_64.rpm
It is roughly the same version of xen but built against Fedora 21 and gcc 4.9.2. If that works then it probably is gcc 5.
Greetings,

I have run into pretty much the same issue as the original poster.

I am running a recently updated Arch Linux system, with GCC 5.1.0, using UEFI and gummiboot to boot. I currently have a build of Xen 4.4.1, built with GCC 4.9.2 from before my last update, that is functioning correctly on this machine. But the builds of Xen 4.5.0, using GCC 5 and mingw64-binutils for the EFI binary, are all failing when Xen starts the Linux kernel, with the same error mentioned in the subject. Below is the boot log I captured via the serial port.

http://pastebin.com/bBC78306

Wondering if my specific toolchain was the issue, I downloaded the Fedora 22 version of xen-hypervisor and installed its EFI Xen binary over my compiled binary and received an identical error message, with slightly different addresses in the panic dump. The Fedora version was compiled with GCC 5.0.1. Below is the boot log I captured from that binary.

http://pastebin.com/jvg1JazC

After finding this thread, and specifically, the quoted message above, I downloaded that xen-hypervisor package and installed its EFI Xen binary. That binary boots successfully, as seen by the captured boot log below.

Quoted 6 lines

http://pastebin.com/DKxwaU2U

So, while I’m not familiar enough with Xen to begin to have an idea of what could possibly be wrong with Xen or GCC 5 to be causing this bug, I’d like to do what I can to track down the issue so I can get a working build of Xen 4.5. :)

Are you in a position to compile identical Xen 4.5 source with two different versions of gcc? (current staging-4.5 staging even has the gcc5 build fix in)

If it is a gcc compiler bug, we would expect the version compiled with gcc 4.9 to work fine, but the one compiled with 5 to fail in the identified manor.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
Quoted 7 lines · Andrew Cooper

Are you in a position to compile identical Xen 4.5 source with two different versions of gcc?  (current staging-4.5 staging even has the gcc5 build fix in)

If it is a gcc compiler bug, we would expect the version compiled with gcc 4.9 to work fine, but the one compiled with 5 to fail in the identified manor.

I did a bit of testing - xen-4.5.1-rc1 built on Fedora 22 (gcc5) doesn't boot for me, but if I replace xen.gz with one from the same code built on Fedora 21 (gcc4) then it does boot. There are rpms and build logs available via
http://copr.fedoraproject.org/coprs/myoung/xentest/build/93366/
if anyone else wants to do some testing.

Michael Young

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw
Quoted 9 lines · M A Young
Quoted 7 lines · Andrew Cooper

Are you in a position to compile identical Xen 4.5 source with two different versions of gcc? (current staging-4.5 staging even has the gcc5 build fix in)

If it is a gcc compiler bug, we would expect the version compiled with gcc 4.9 to work fine, but the one compiled with 5 to fail in the identified manor.

Quoted 8 lines

I did a bit of testing - xen-4.5.1-rc1 built on Fedora 22 (gcc5) doesn't boot for me, but if I replace xen.gz with one from the same code built on Fedora 21 (gcc4) then it does boot. There are rpms and build logs available via
http://copr.fedoraproject.org/coprs/myoung/xentest/build/93366/
if anyone else wants to do some testing.

Michael Young

Do you have easy access to xen-syms from each build?

~Andrew

#4 lore raw
Quoted 17 lines · Andrew Cooper
Quoted 16 lines · M A Young
Quoted 7 lines · Andrew Cooper

Are you in a position to compile identical Xen 4.5 source with two different versions of gcc? (current staging-4.5 staging even has the gcc5 build fix in)

If it is a gcc compiler bug, we would expect the version compiled with gcc 4.9 to work fine, but the one compiled with 5 to fail in the identified manor.

I did a bit of testing - xen-4.5.1-rc1 built on Fedora 22 (gcc5) doesn't boot for me, but if I replace xen.gz with one from the same code built on Fedora 21 (gcc4) then it does boot. There are rpms and build logs available via
http://copr.fedoraproject.org/coprs/myoung/xentest/build/93366/
if anyone else wants to do some testing.

Quoted 3 lines
Quoted 1 line

Michael Young

Do you have easy access to xen-syms from each build?

Yes.

Michael Young

#5 lore raw
Quoted 8 lines · M A Young
Quoted 8 lines
Quoted 8 lines

I did a bit of testing - xen-4.5.1-rc1 built on Fedora 22 (gcc5) doesn't boot for me, but if I replace xen.gz with one from the same code built on Fedora 21 (gcc4) then it does boot. There are rpms and build logs available via
http://copr.fedoraproject.org/coprs/myoung/xentest/build/93366/
if anyone else wants to do some testing.

Quoted 4 lines
Quoted 2 lines
Quoted 1 line

Michael Young

Do you have easy access to xen-syms from each build?

Yes.

Thankyou very much.

GCC 5 is indeed miscompiling the code. Comparing the fc21 vs fc22 builds:

The C snippet from mmio_ro_do_page_fault():

struct page_info *page = mfn_to_page(mfn);
struct domain *owner = page_get_owner_and_reference(page); if ( owner )

    put_page(page);

In fc21 is:

movabs $0xffff82e000000000,%rbp

shr    %cl,%rax
or     %rdx,%rax
shl    $0x5,%rax
add    %rax,%rbp
mov    %rbp,%rdi
callq  ffff82d080186900 <page_get_owner_and_reference>
test   %rax,%rax
mov    %rax,%r12
je     ffff82d080189c4e <mmio_ro_do_page_fault+0x11e>
mov    %rbp,%rdi
callq  ffff82d080188ec0 <put_page>

and in fc22 is:

movabs $0xffff82e000000000,%r8

shr    %cl,%rax
or     %rdx,%rax
shl    $0x5,%rax
lea    (%r8,%rax,1),%rdi
callq  ffff82d0801874f0 <page_get_owner_and_reference>
test   %rax,%rax
mov    %rax,%rbp
je     ffff82d08018ca14 <mmio_ro_do_page_fault+0x114>
mov    %r8,%rdi
callq  ffff82d080189a90 <put_page>

"lea (%r8,%rax,1),%rdi" in FC22 is slightly shorter than "add %rax,%rbp; mov %rbp,%rdi" in FC21. In both cases %rdi is now 'page' from the C snippet.

In FC21, the result is stored in %rbp, then reloaded from %rbp into %rdi for call to put_page().

However, in FC22, the result of the calculation is only held in %rdi, and clobbered by the call to page_get_owner_and_reference(). When it comes to call put_page(), %r8 is reloaded, which is still a pointer to the base of the frametable, not the page we actually took a reference on.

FC22 is miscompiling the C to:

struct page_info *page = mfn_to_page(mfn);
struct domain *owner = page_get_owner_and_reference(page); if ( owner )

    put_page(mfn_to_page(0));

which is wrong, and why free_domheap_pages() does legitimately complain about the wonky refcount.

~Andrew

#6 lore raw
Quoted 68 lines · Andrew Cooper
Quoted 8 lines · M A Young
Quoted 8 lines
Quoted 8 lines

I did a bit of testing - xen-4.5.1-rc1 built on Fedora 22 (gcc5) doesn't boot for me, but if I replace xen.gz with one from the same code built on Fedora 21 (gcc4) then it does boot. There are rpms and build logs available via
http://copr.fedoraproject.org/coprs/myoung/xentest/build/93366/
if anyone else wants to do some testing.

Quoted 4 lines
Quoted 2 lines
Quoted 1 line

Michael Young

Do you have easy access to xen-syms from each build?

Yes.

Thankyou very much.

GCC 5 is indeed miscompiling the code. Comparing the fc21 vs fc22 builds:

The C snippet from mmio_ro_do_page_fault():

struct page_info *page = mfn_to_page(mfn);
struct domain *owner = page_get_owner_and_reference(page); if ( owner )

    put_page(page);

In fc21 is:

movabs $0xffff82e000000000,%rbp

shr    %cl,%rax
or     %rdx,%rax
shl    $0x5,%rax
add    %rax,%rbp
mov    %rbp,%rdi
callq  ffff82d080186900 <page_get_owner_and_reference>
test   %rax,%rax
mov    %rax,%r12
je     ffff82d080189c4e <mmio_ro_do_page_fault+0x11e>
mov    %rbp,%rdi
callq  ffff82d080188ec0 <put_page>

and in fc22 is:

movabs $0xffff82e000000000,%r8

shr    %cl,%rax
or     %rdx,%rax
shl    $0x5,%rax
lea    (%r8,%rax,1),%rdi
callq  ffff82d0801874f0 <page_get_owner_and_reference>
test   %rax,%rax
mov    %rax,%rbp
je     ffff82d08018ca14 <mmio_ro_do_page_fault+0x114>
mov    %r8,%rdi
callq  ffff82d080189a90 <put_page>

"lea (%r8,%rax,1),%rdi" in FC22 is slightly shorter than "add %rax,%rbp; mov %rbp,%rdi" in FC21. In both cases %rdi is now 'page' from the C snippet.

In FC21, the result is stored in %rbp, then reloaded from %rbp into %rdi for call to put_page().

However, in FC22, the result of the calculation is only held in %rdi, and clobbered by the call to page_get_owner_and_reference(). When it comes to call put_page(), %r8 is reloaded, which is still a pointer to the base of the frametable, not the page we actually took a reference on.

FC22 is miscompiling the C to:

Quoted 7 lines

struct page_info *page = mfn_to_page(mfn);
struct domain *owner = page_get_owner_and_reference(page); if ( owner )

    put_page(mfn_to_page(0));

which is wrong, and why free_domheap_pages() does legitimately complain about the wonky refcount.

With a bit of experimentation I have found that compiling with the -fno-caller-saves flag gets this code segment back to the Fedora 21 version, thus avoiding the bug.

Michael Young

#7 lore raw
Quoted 73 lines · M A Young
Quoted 71 lines · Andrew Cooper
Quoted 11 lines · M A Young
Quoted 9 lines
Quoted 8 lines

I did a bit of testing - xen-4.5.1-rc1 built on Fedora 22 (gcc5) doesn't boot for me, but if I replace xen.gz with one from the same code built on Fedora 21 (gcc4) then it does boot. There are rpms and build logs available via
http://copr.fedoraproject.org/coprs/myoung/xentest/build/93366/
if anyone else wants to do some testing.

Michael Young

Do you have easy access to xen-syms from each build?

Yes.

Thankyou very much.

GCC 5 is indeed miscompiling the code. Comparing the fc21 vs fc22 builds:

The C snippet from mmio_ro_do_page_fault():

struct page_info *page = mfn_to_page(mfn);
struct domain *owner = page_get_owner_and_reference(page); if ( owner )

    put_page(page);

In fc21 is:

movabs $0xffff82e000000000,%rbp

shr    %cl,%rax
or     %rdx,%rax
shl    $0x5,%rax
add    %rax,%rbp
mov    %rbp,%rdi
callq  ffff82d080186900 <page_get_owner_and_reference>
test   %rax,%rax
mov    %rax,%r12
je     ffff82d080189c4e <mmio_ro_do_page_fault+0x11e>
mov    %rbp,%rdi
callq  ffff82d080188ec0 <put_page>

and in fc22 is:

movabs $0xffff82e000000000,%r8

shr    %cl,%rax
or     %rdx,%rax
shl    $0x5,%rax
lea    (%r8,%rax,1),%rdi
callq  ffff82d0801874f0 <page_get_owner_and_reference>
test   %rax,%rax
mov    %rax,%rbp
je     ffff82d08018ca14 <mmio_ro_do_page_fault+0x114>
mov    %r8,%rdi
callq  ffff82d080189a90 <put_page>

"lea (%r8,%rax,1),%rdi" in FC22 is slightly shorter than "add %rax,%rbp; mov %rbp,%rdi" in FC21. In both cases %rdi is now 'page' from the C snippet.

In FC21, the result is stored in %rbp, then reloaded from %rbp into %rdi for call to put_page().

However, in FC22, the result of the calculation is only held in %rdi, and clobbered by the call to page_get_owner_and_reference(). When it comes to call put_page(), %r8 is reloaded, which is still a pointer to the base of the frametable, not the page we actually took a reference on.

FC22 is miscompiling the C to:

struct page_info *page = mfn_to_page(mfn);
struct domain *owner = page_get_owner_and_reference(page); if ( owner )

    put_page(mfn_to_page(0));
Quoted 5 lines
Quoted 2 lines

which is wrong, and why free_domheap_pages() does legitimately complain about the wonky refcount.

With a bit of experimentation I have found that compiling with the -fno-caller-saves flag gets this code segment back to the Fedora 21 version, thus avoiding the bug.

After sending this email, I wondered whether the optimiser as assuming that %rdi was preserved. Indeed, it turns out that the generated code for page_get_owner_and_reference leaves %rdi unmodified, and safe for reuse after return.

If the 'mov %r8,%rdi' were simply omitted, the code would work, as %rdi still contains the correct result of the original calculation.

Therefore, I suspect that the bug is in the -fcaller-saves optimisation code.

~Andrew

#8 lore raw
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 31.05.15 at 00:43, <[email protected]> wrote:
Quoted 8 lines · M A Young
Quoted 7 lines · Andrew Cooper

FC22 is miscompiling the C to:

struct page_info *page = mfn_to_page(mfn);
struct domain *owner = page_get_owner_and_reference(page); if ( owner )

    put_page(mfn_to_page(0));
Quoted 5 lines
Quoted 2 lines

which is wrong, and why free_domheap_pages() does legitimately complain about the wonky refcount.

With a bit of experimentation I have found that compiling with the -fno-caller-saves flag gets this code segment back to the Fedora 21 version, thus avoiding the bug.

Quoted 7 lines

After sending this email, I wondered whether the optimiser as assuming that %rdi was preserved. Indeed, it turns out that the generated code for page_get_owner_and_reference leaves %rdi unmodified, and safe for reuse after return.

If the 'mov %r8,%rdi' were simply omitted, the code would work, as %rdi still contains the correct result of the original calculation.

And %r8 is known to be preserved too?

Quoted 2 lines

Therefore, I suspect that the bug is in the -fcaller-saves optimisation code.

I suppose together with us allowing it to do such for global functions by marking everything hidden (i.e. something possibly not seeing much testing).

Questions now are:
1) Was a bug against gcc opened already?
2) What do we do about it? Working around the issue by setting -fno-caller-saves seems awkward, as we'd likely have nothing but the gcc version to tie this to. And considering distros carry their own patch sets, the version alone may not even be enough. (I didn't see any reports against our tip facing a similar issue despite it being built with gcc 5 now too afaik.)

Jan

#9 lore raw
Quoted 33 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 31.05.15 at 00:43, <[email protected]> wrote:
Quoted 8 lines · M A Young
Quoted 7 lines · Andrew Cooper

FC22 is miscompiling the C to:

struct page_info *page = mfn_to_page(mfn);
struct domain *owner = page_get_owner_and_reference(page); if ( owner )

    put_page(mfn_to_page(0));
Quoted 5 lines
Quoted 2 lines

which is wrong, and why free_domheap_pages() does legitimately complain about the wonky refcount.

With a bit of experimentation I have found that compiling with the -fno-caller-saves flag gets this code segment back to the Fedora 21 version, thus avoiding the bug.

Quoted 7 lines

After sending this email, I wondered whether the optimiser as assuming that %rdi was preserved. Indeed, it turns out that the generated code for page_get_owner_and_reference leaves %rdi unmodified, and safe for reuse after return.

If the 'mov %r8,%rdi' were simply omitted, the code would work, as %rdi still contains the correct result of the original calculation.

And %r8 is known to be preserved too?

Quoted 2 lines

Therefore, I suspect that the bug is in the -fcaller-saves optimisation code.

I suppose together with us allowing it to do such for global functions by marking everything hidden (i.e. something possibly not seeing much testing).

Quoted 8 lines

Questions now are:
1) Was a bug against gcc opened already?
2) What do we do about it? Working around the issue by setting -fno-caller-saves seems awkward, as we'd likely have nothing but the gcc version to tie this to. And considering distros carry their own patch sets, the version alone may not even be enough. (I didn't see any reports against our tip facing a similar issue despite it being built with gcc 5 now too afaik.)

There is a Fedora bug on this
https://bugzilla.redhat.com/show_bug.cgi?id=1219197
which I updated and reassigned to gcc yesterday.

Michael Young

#10 lore raw
Quoted 44 lines · M A Young
Quoted 33 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 31.05.15 at 00:43, <[email protected]> wrote:
Quoted 8 lines · M A Young
Quoted 7 lines · Andrew Cooper

FC22 is miscompiling the C to:

struct page_info *page = mfn_to_page(mfn);
struct domain *owner = page_get_owner_and_reference(page); if ( owner )

    put_page(mfn_to_page(0));
Quoted 5 lines
Quoted 2 lines

which is wrong, and why free_domheap_pages() does legitimately complain about the wonky refcount.

With a bit of experimentation I have found that compiling with the -fno-caller-saves flag gets this code segment back to the Fedora 21 version, thus avoiding the bug.

Quoted 7 lines

After sending this email, I wondered whether the optimiser as assuming that %rdi was preserved. Indeed, it turns out that the generated code for page_get_owner_and_reference leaves %rdi unmodified, and safe for reuse after return.

If the 'mov %r8,%rdi' were simply omitted, the code would work, as %rdi still contains the correct result of the original calculation.

And %r8 is known to be preserved too?

Quoted 2 lines

Therefore, I suspect that the bug is in the -fcaller-saves optimisation code.

I suppose together with us allowing it to do such for global functions by marking everything hidden (i.e. something possibly not seeing much testing).

Quoted 8 lines

Questions now are:
1) Was a bug against gcc opened already?
2) What do we do about it? Working around the issue by setting -fno-caller-saves seems awkward, as we'd likely have nothing but the gcc version to tie this to. And considering distros carry their own patch sets, the version alone may not even be enough. (I didn't see any reports against our tip facing a similar issue despite it being built with gcc 5 now too afaik.)

Quoted 3 lines

There is a Fedora bug on this
https://bugzilla.redhat.com/show_bug.cgi?id=1219197
which I updated and reassigned to gcc yesterday.

The Fedora gcc maintainer has now filed an upstream bug which is
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=66444

Michael Young