Skip to content

Commit

Permalink
ENGR00309915 [#1087] enhanced video memory mutex
Browse files Browse the repository at this point in the history
this patch can fix NULL pointer issue in GPU kernel driver with the following log

[<7f240438>] (gckEVENT_AddList+0x0/0x810 [galcore]) from [<7f239ebc>] (gckCOMMAND_Commit+0xf28/0x118c [galcore])
[<7f238f94>] (gckCOMMAND_Commit+0x0/0x118c [galcore]) from [<7f2362dc>] (gckKERNEL_Dispatch+0x120c/0x24e4 [galcore])
[<7f2350d0>] (gckKERNEL_Dispatch+0x0/0x24e4 [galcore]) from [<7f222280>] (drv_ioctl+0x390/0x540 [galcore])
[<7f221ef0>] (drv_ioctl+0x0/0x540 [galcore]) from [<800facd0>] (vfs_ioctl+0x30/0x44)

The false code is at 0x217bc where the 0-pointer happens (r3 = 0)

gcuVIDMEM_NODE_PTR node = (gcuVIDMEM_NODE_PTR)(gcmUINT64_TO_PTR(Record->info.u.FreeVideoMemory.node));
   217b8:                e5953028             ldr           r3, [r5, torvalds#40]         ; 0x28

                if (node->VidMem.memory->object.type == gcvOBJ_VIDMEM)
   217bc:                e5932000             ldr           r2, [r3]
   217c0:                e5922000             ldr           r2, [r2]
   217c4:                e152000a             cmp       r2, sl
                {
                     gcmkVERIFY_OK(gckKERNEL_RemoveProcessDB(Event->kernel,

Date: Apr 23, 2014
Signed-off-by: Xianzhong <b07117@freescale.com>
Acked-by: Jason Liu
(cherry picked from commit fcde214)
(cherry picked from commit 952142648d76fce2663ef649d9f988f1b7809815)
(cherry picked from commit 9d7b33678f1f944f75644e958c3ceeb7f2e4bac9)
  • Loading branch information
Xianzhong authored and Loren Huang committed Aug 15, 2014
1 parent ee7c962 commit 1b41d9c
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 96 deletions.
14 changes: 11 additions & 3 deletions drivers/mxc/gpu-viv/hal/kernel/gc_hal_kernel.c
Expand Up @@ -165,6 +165,8 @@ gckKERNEL_Construct(
kernel->dvfs = gcvNULL;
#endif

kernel->vidmemMutex = gcvNULL;

/* Initialize the gckKERNEL object. */
kernel->object.type = gcvOBJ_KERNEL;
kernel->os = Os;
Expand Down Expand Up @@ -297,6 +299,9 @@ gckKERNEL_Construct(
gcmkONERROR(gckOS_CreateSyncTimeline(Os, &kernel->timeline));
#endif

/* Construct a video memory mutex. */
gcmkONERROR(gckOS_CreateMutex(Os, &kernel->vidmemMutex));

/* Return pointer to the gckKERNEL object. */
*Kernel = kernel;

Expand Down Expand Up @@ -518,6 +523,8 @@ gckKERNEL_Destroy(
gcmkVERIFY_OK(gckOS_DestroySyncTimeline(Kernel->os, Kernel->timeline));
#endif

gcmkVERIFY_OK(gckOS_DeleteMutex(Kernel->os, Kernel->vidmemMutex));

/* Mark the gckKERNEL object as unknown. */
Kernel->object.type = gcvOBJ_UNKNOWN;

Expand Down Expand Up @@ -767,7 +774,7 @@ _AllocateMemory(
{
gckOS_Print("gpu virtual memory 0x%x cannot be allocated in force contiguous request!\n", physAddr);

gcmkONERROR(gckVIDMEM_Free(node));
gcmkONERROR(gckVIDMEM_Free(Kernel, node));

node = gcvNULL;
}
Expand Down Expand Up @@ -797,7 +804,8 @@ _AllocateMemory(
if (gcmIS_SUCCESS(status))
{
/* Allocate memory. */
status = gckVIDMEM_AllocateLinear(videoMemory,
status = gckVIDMEM_AllocateLinear(Kernel,
videoMemory,
Bytes,
Alignment,
Type,
Expand Down Expand Up @@ -1251,7 +1259,7 @@ gckKERNEL_Dispatch(
#endif
/* Free video memory. */
gcmkONERROR(
gckVIDMEM_Free(node));
gckVIDMEM_Free(Kernel, node));

gcmkONERROR(
gckKERNEL_RemoveProcessDB(Kernel,
Expand Down
8 changes: 2 additions & 6 deletions drivers/mxc/gpu-viv/hal/kernel/gc_hal_kernel.h
Expand Up @@ -453,6 +453,8 @@ struct _gckKERNEL
#if gcdANDROID_NATIVE_FENCE_SYNC
gctHANDLE timeline;
#endif

gctPOINTER vidmemMutex;
};

struct _FrequencyHistory
Expand Down Expand Up @@ -766,9 +768,6 @@ typedef union _gcuVIDMEM_NODE
/* Actual physical address */
gctUINT32 addresses[gcdMAX_GPU_COUNT];

/* Mutex. */
gctPOINTER mutex;

/* Locked counter. */
gctINT32 lockeds[gcdMAX_GPU_COUNT];

Expand Down Expand Up @@ -824,9 +823,6 @@ struct _gckVIDMEM
/* Allocation threshold. */
gctSIZE_T threshold;

/* The heap mutex. */
gctPOINTER mutex;

#if gcdUSE_VIDMEM_PER_PID
/* The Pid this VidMem belongs to. */
gctUINT32 pid;
Expand Down
5 changes: 3 additions & 2 deletions drivers/mxc/gpu-viv/hal/kernel/gc_hal_kernel_command_vg.c
Expand Up @@ -1060,6 +1060,7 @@ _AllocateLinear(

/* Free the command buffer. */
gcmkCHECK_STATUS(gckVIDMEM_Free(
Command->kernel->kernel,
node
));
}
Expand All @@ -1082,7 +1083,7 @@ _FreeLinear(
gcmkERR_BREAK(gckVIDMEM_Unlock(Kernel->kernel, Node, gcvSURF_TYPE_UNKNOWN, gcvNULL));

/* Free the linear buffer. */
gcmkERR_BREAK(gckVIDMEM_Free(Node));
gcmkERR_BREAK(gckVIDMEM_Free(Kernel->kernel, Node));
}
while (gcvFALSE);

Expand Down Expand Up @@ -1676,7 +1677,7 @@ _TaskFreeVideoMemory(
= (gcsTASK_FREE_VIDEO_MEMORY_PTR) TaskHeader->task;

/* Free video memory. */
gcmkERR_BREAK(gckVIDMEM_Free(gcmUINT64_TO_PTR(task->node)));
gcmkERR_BREAK(gckVIDMEM_Free(Command->kernel->kernel, gcmUINT64_TO_PTR(task->node)));

/* Update the reference counter. */
TaskHeader->container->referenceCount -= 1;
Expand Down
2 changes: 1 addition & 1 deletion drivers/mxc/gpu-viv/hal/kernel/gc_hal_kernel_db.c
Expand Up @@ -1199,7 +1199,7 @@ gckKERNEL_DestroyProcessDB(
{
case gcvDB_VIDEO_MEMORY:
/* Free the video memory. */
status = gckVIDMEM_Free(gcmUINT64_TO_PTR(record->data));
status = gckVIDMEM_Free(Kernel, gcmUINT64_TO_PTR(record->data));

gcmkTRACE_ZONE(gcvLEVEL_WARNING, gcvZONE_DATABASE,
"DB: VIDEO_MEMORY 0x%x (status=%d)",
Expand Down
2 changes: 1 addition & 1 deletion drivers/mxc/gpu-viv/hal/kernel/gc_hal_kernel_event.c
Expand Up @@ -2280,7 +2280,7 @@ gckEVENT_Notify(

/* Free video memory. */
status =
gckVIDMEM_Free(node);
gckVIDMEM_Free(Event->kernel, node);

break;

Expand Down
5 changes: 3 additions & 2 deletions drivers/mxc/gpu-viv/hal/kernel/gc_hal_kernel_vg.c
Expand Up @@ -308,7 +308,8 @@ gckKERNEL_AllocateLinearMemory(
if(*Pool == gcvPOOL_SYSTEM)
Type |= gcvSURF_VG;
/* Allocate memory. */
status = gckVIDMEM_AllocateLinear(videoMemory,
status = gckVIDMEM_AllocateLinear(Kernel,
videoMemory,
Bytes,
Alignment,
Type,
Expand Down Expand Up @@ -599,7 +600,7 @@ gceSTATUS gckVGKERNEL_Dispatch(
#endif /* __QNXNTO__ */

/* Free video memory. */
gcmkERR_BREAK(gckVIDMEM_Free(
gcmkERR_BREAK(gckVIDMEM_Free(Kernel,
node
));

Expand Down

0 comments on commit 1b41d9c

Please sign in to comment.