Bug 18304

Summary: xf86MapVidMem() aborts entire server instead of failing gracefuly
Product: xorg Reporter: Arkadiusz Miskiewicz <arekm>
Component: Server/GeneralAssignee: Adam Jackson <ajax>
Status: RESOLVED FIXED QA Contact: Xorg Project Team <xorg-team>
Severity: normal    
Priority: medium CC: jesserayadkins
Version: 7.4 (2008.09)   
Hardware: All   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments:
Description Flags
proposed patch none

Description Arkadiusz Miskiewicz 2008-10-30 02:50:21 UTC
Created attachment 19959 [details] [review]
proposed patch

The problem is that linux kernel introduced restrictions on /dev/mem access (ie. 2.6.27 with CONFIG_STRICT_DEVMEM turned on).

Driver sis tries to do:
    if(SISPTR(pScrn)->Primary) {
       base = xf86MapVidMem(pScrn->scrnIndex, VIDMEM_MMIO, 0, 0x2000);
       if(!base) {
          SISErrorLog(pScrn, "(Could not map BIOS scratch area)\n");
          return ret;
       }

unfortunately xf86MapVidMem() implementation for linux does bad things like:

    if (base == MAP_FAILED) {
        FatalError("xf86MapVidMem: Could not mmap framebuffer"
                   " (0x%08lx,0x%lx) (%s)\n", Base, Size,
                   strerror(errno));
    }

On linux with the restriction xservers ends its life with:

xf86MapVidMem: Could not mmap framebuffer (0x00000000,0x2000) (Operation not permitted)

while driver is fully prepared to handle case where xf86MapVidMem fails.

Proposed patch attached.
Comment 1 Jesse Adkins 2010-10-29 17:04:23 UTC
Can you make a patch generated by git format-patch, and send it to xorg-devel@lists.freedesktop.org?

Patches made by git format-patch are easier to apply (and also preserve ownership, in case that's useful to you later).
Comment 2 Adam Jackson 2017-05-23 15:24:43 UTC
commit 9db2af6f757ef9680c70eb731698b7c9f9aca203
Author: Adam Jackson <ajax@redhat.com>
Date:   Fri May 2 12:14:10 2014 -0400

    xfree86: Remove xf86{Map,Unmap}VidMem
    
    This API sucks.  Fortunately it's mostly unused at this point.  geode,
    sis, and xgi need minor patches to use the corresponding pciaccess code,
    neomagic will (more explicitly) lose its non-PCI support, and newport
    will need to be ported to /dev/mem or the platform bus or something.
    
    This should also make it pretty clear that alpha's sparse memory support
    was basically not a thing anymore, very few tears shed.
    
    Reviewed-by: Eric Anholt <eric@anholt.net>
    Signed-off-by: Adam Jackson <ajax@redhat.com>

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.