ARM MALI: use standard GFP_FLAGS for allocations to prevent failures
authorMandeep Singh Baines <msb@chromium.org>
Wed, 8 Aug 2012 21:50:31 +0000 (14:50 -0700)
committerGerrit <chrome-bot@google.com>
Thu, 9 Aug 2012 21:38:20 +0000 (14:38 -0700)
We would prefer if mali allocations did not fail. When mali allocations
fail, we get random failures in gl calls which are really HARD to debug
since the stack trace and failure mode in chrome is always different. So
multiple bugs get opened.

We'd much prefer to OOM when running out of memory. We get a nice stack
trace and detailed state information for the vm system. We also know
immediately that there is an out of memory issue.

The previous GFP_FLAGS are available via a Kconfig option.

BUG=chrome-os-partner:12316
TEST=Verified that bug 12316 now causes an OOM

[  518.884239] chrome invoked oom-killer: gfp_mask=0xd2, order=0, oom_adj=3, oom_
score_adj=200
[  518.884269] [<80015f54>] (unwind_backtrace+0x0/0x128) from [<804f09d4>] (dump_
stack+0x20/0x24)
[  518.884287] [<804f09d4>] (dump_stack+0x20/0x24) from [<800b51bc>] (dump_header
.isra.10+0x7c/0x174)
[  518.884301] [<800b51bc>] (dump_header.isra.10+0x7c/0x174) from [<800b53f8>] (o
om_kill_process.part.13.constprop.14+0x4c/0x20c)
[  518.884314] [<800b53f8>] (oom_kill_process.part.13.constprop.14+0x4c/0x20c) fr
om [<800b5a08>] (out_of_memory+0x2dc/0x39c)
[  518.884328] [<800b5a08>] (out_of_memory+0x2dc/0x39c) from [<800b89f0>] (__allo
c_pages_nodemask+0x524/0x66c)
[  518.884343] [<800b89f0>] (__alloc_pages_nodemask+0x524/0x66c) from [<8029bfd4>
] (kbase_phy_pages_alloc+0x80/0x33c)
[  518.884356] [<8029bfd4>] (kbase_phy_pages_alloc+0x80/0x33c) from [<8029c590>]
(kbase_alloc_phy_pages_helper+0x108/0x230)
[  518.884370] [<8029c590>] (kbase_alloc_phy_pages_helper+0x108/0x230) from [<802
9d000>] (kbase_alloc_phy_pages+0x58/0x78)
[  518.884382] [<8029d000>] (kbase_alloc_phy_pages+0x58/0x78) from [<8029d1d8>] (
kbase_tmem_alloc+0x140/0x1b8)
[  518.884398] [<8029d1d8>] (kbase_tmem_alloc+0x140/0x1b8) from [<802aba80>] (kba
se_dispatch+0xbc/0x3e8)
[  518.884412] [<802aba80>] (kbase_dispatch+0xbc/0x3e8) from [<802a91bc>] (ukk_di
spatch+0x44/0x84)
[  518.884425] [<802a91bc>] (ukk_dispatch+0x44/0x84) from [<802aa880>] (kbase_ioc
tl+0xa8/0x10c)
[  518.884440] [<802aa880>] (kbase_ioctl+0xa8/0x10c) from [<800fbf2c>] (do_vfs_io
ctl+0x4f4/0x568)
[  518.884451] [<800fbf2c>] (do_vfs_ioctl+0x4f4/0x568) from [<800fc000>] (sys_ioc
tl+0x60/0x84)
[  518.884464] [<800fc000>] (sys_ioctl+0x60/0x84) from [<8000e7c0>] (ret_fast_sys
call+0x0/0x30)

Change-Id: If670941123ca8151219a6f4751af3bf3d87f77e2
Signed-off-by: Mandeep Singh Baines <msb@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/29662
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
drivers/gpu/arm/t6xx/kbase/Kconfig
drivers/gpu/arm/t6xx/kbase/osk/src/linux/include/osk/mali_osk_arch_low_level_mem.h

index 9491c9a..95e0060 100644 (file)
@@ -95,6 +95,28 @@ config MALI_UNCACHED
        help
          Select this option to disable CPU caching for all GPU memory regions.
 
+config MALI_BASE_ALLOC_FAIL
+       bool "Change allocation GFP flags so that allocations can fail"
+       depends on MALI_T6XX && MALI_EXPERT
+       default n
+       help
+         Change the default memory allocation GFP flags so that allocations
+         can fail.
+
+         By default, kbase memory allocations don't fail. This is consisent
+         with other GPU drivers. However, kbase (i.e. texture memory)
+         allocations are accounted to the process which caused the allocation.
+         This means there's a potential DoS attack an application could make
+         by just allocating lots and lots of memory (E.g. textures). That
+         memory wouldn't be seen as being owned by the malicious/buggy
+         application and so the OOM killer wouldn't kill that app's process.
+         By permitting allocations to fail in low memory situations, we can
+         avoid that DoS attack vector at the cost of GL allocations being able
+         to fail.
+
+         Turn this on if you're confident your code can handle GL allocations
+         failures.
+
 config MALI_BASE_TRACK_MEMLEAK
        bool "Enable the tracking of memory leaks and support for simulated failures"
        depends on MALI_T6XX && MALI_EXPERT
index 6e9f15f..24a8ee5 100644 (file)
@@ -59,14 +59,18 @@ OSK_STATIC_INLINE u32 oskp_phy_os_pages_alloc(oskp_phy_os_allocator *allocator,
                struct page *p;
                void * mp;
 
+#ifdef CONFIG_MALI_BASE_ALLOC_FAIL
                p = alloc_page(__GFP_IO |
-                              __GFP_FS |
-                              __GFP_COLD |
-                              __GFP_NOWARN |
-                              __GFP_NORETRY |
-                              __GFP_NOMEMALLOC |
-                              __GFP_HIGHMEM |
-                              __GFP_HARDWALL);
+                              __GFP_FS |
+                              __GFP_COLD |
+                              __GFP_NOWARN |
+                              __GFP_NORETRY |
+                              __GFP_NOMEMALLOC |
+                              __GFP_HIGHMEM |
+                              __GFP_HARDWALL);
+#else
+               p = alloc_page(GFP_KERNEL | __GFP_HIGHMEM);
+#endif
                if (NULL == p)
                {
                        break;