Bug 42628 - [llvmpipe] calling feenableexcept(FE_INVALID) causes SIGFPE Crash
Summary: [llvmpipe] calling feenableexcept(FE_INVALID) causes SIGFPE Crash
Status: RESOLVED NOTOURBUG
Alias: None
Product: Mesa
Classification: Unclassified
Component: Other (show other bugs)
Version: 7.11
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Jose Fonseca
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-05 11:21 UTC by Catalin Badea
Modified: 2012-07-19 16:30 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
Bug reproduced in gdb. (13.27 KB, text/x-log)
2011-11-05 14:37 UTC, Catalin Badea
Details

Description Catalin Badea 2011-11-05 11:21:13 UTC
FreedroidRPG (opengl mode) crashes when entering the level editor. The crash seems to be caused by a bug in the opengl driver.
After reproducing the bug several times, I've noticed that the crash has a random delay between (0 and 2 seconds) before it occurs.

I have attached the apitrace and the gdb log.
Comment 1 Catalin Badea 2011-11-05 11:29:40 UTC
The apitrace size is bigger than the attachment size limit.
External link: http://swarm.cs.pub.ro/~cbadea/freedroid/freedroid_llvmpipe.tar.gz
Comment 2 Catalin Badea 2011-11-05 14:37:01 UTC
Created attachment 53197 [details]
Bug reproduced in gdb.

Added the gdb log separately. The apitrace does not fully reproduce the bug - replaying it doesn't trigger the bug. I've tried keeping the game running past the SIGFPE signals, but the apitrace ends at the first SIGFPE signal.
Comment 3 Jose Fonseca 2011-11-06 01:32:29 UTC
The game says

  Hello, this is FreedroidRPG, version 0.14.1+svn.
  This seems to be a development version, so we'll exit on floating point exceptions.

And it appears the game is going out of its way to enable floating point exceptions, from freedroid/src/init.c:

        // Let's see if we're dealing with a real release or rather if
        // we're dealing with a svn version.  The difference is this:
        // Releases shouldn't terminate upon a floating point exception
        // while the current svn code (for better debugging) should
        // do so.  Therefore we check for 'svn' in the current version
        // string and enable/disable the exceptions accordingly...
        if (strstr(VERSION, "svn")) {
                DebugPrintf(-4, "\nThis seems to be a development version, so we'll exit on floating point exceptions.");
                // feenableexcept ( FE_ALL_EXCEPT );
                // feenableexcept ( FE_INEXACT ) ;
                // feenableexcept ( FE_UNDERFLOW ) ;
                // feenableexcept ( FE_OVERFLOW ) ;
                feenableexcept(FE_INVALID);
                feenableexcept(FE_DIVBYZERO);
        } else {
                DebugPrintf(-4, "\nThis seems to be a 'stable' release, so no exit on floating point exceptions.");
                fedisableexcept(FE_INVALID);
                fedisableexcept(FE_DIVBYZERO);
        }

But I'm not sure which is the default though.

llvmpipe uses the cpu for rendering, and it often needs to process extra padding data, for alignment reasons. It's very likely that that data is invalid. Also, applications can provide invalid floating point data themselves.

Did you build the game yourself? And if so, can you comment this code to see wheather it makes a difference?
Comment 4 Catalin Badea 2011-11-06 06:56:04 UTC
I'm using the development version. Commenting feenableexcept(FE_INVALID); in src/init.c fixes the crash.

The driver crashing due to legal operations in the application looks like an odd behaviour to me. Is this the expected behaviour or is it a bug in llvmpipe?
Comment 5 Jose Fonseca 2011-11-06 07:50:33 UTC
(In reply to comment #4)
> The driver crashing due to legal operations in the application looks like an
> odd behaviour to me. Is this the expected behaviour or is it a bug in llvmpipe?

I'm not 100% sure this is a legal operation.

Floating point exception mode and rounding mode have usually effect for the whole process/thread.

It's fine for an application to change floating point behavior whithin itself, but it's probably good practice to reset to their system defaults when calling into third party libraries (such as OpenGL).

Unless the OpenGL ABI spec dictates the driver needs to be robust against this, I'm more inclined to consider this as an application bug.

This affects llvmpipe more than hardware OpenGL drivers because llvmpipe uses the CPU for everything. And there is no way to prevent floating point exceptions without disabling them, and doing so every GL call would affect performance for all apps.

I need to research a bit more on what's the right thing here.
Comment 6 Jose Fonseca 2012-07-19 16:30:44 UTC
I don't think there's anything we can do here. The app must not do this.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.