msm: kgsl: Do not free sharedmem if it cannot be unmapped

If sharedmem cannot be unmapped from the mmu, it can still be accessed
by the GPU. Therefore it is not safe to free the backing memory. In the
case that unmap fails, do not free it or return it to the system.

Change-Id: Iad3e86d043f129a4d71cf862865d9033d4a315e3
Signed-off-by: Lynus Vaz <quic_lvaz@quicinc.com>
Signed-off-by: Kaushal Sanadhya <quic_ksanadhy@quicinc.com>
This commit is contained in:
Kaushal Sanadhya
2023-11-29 23:01:37 +05:30
committed by ExactExampl
parent c0b15c73fb
commit 4e4459d151
2 changed files with 10 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
/* Copyright (c) 2002,2007-2017,2021, The Linux Foundation. All rights reserved.
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
* Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
@@ -505,6 +505,8 @@ kgsl_mmu_unmap(struct kgsl_pagetable *pagetable,
size = kgsl_memdesc_footprint(memdesc);
ret = pagetable->pt_ops->mmu_unmap(pagetable, memdesc);
if (ret)
return ret;
atomic_dec(&pagetable->stats.entries);
atomic_long_sub(size, &pagetable->stats.mapped);

View File

@@ -1,4 +1,5 @@
/* Copyright (c) 2002,2007-2018,2020-2021, The Linux Foundation. All rights reserved.
* Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
@@ -480,6 +481,9 @@ done:
static void kgsl_page_alloc_free(struct kgsl_memdesc *memdesc)
{
if (memdesc->priv & KGSL_MEMDESC_MAPPED)
return;
kgsl_page_alloc_unmap_kernel(memdesc);
/* we certainly do not expect the hostptr to still be mapped */
BUG_ON(memdesc->hostptr);
@@ -583,6 +587,9 @@ static void kgsl_cma_coherent_free(struct kgsl_memdesc *memdesc)
{
unsigned long attrs = 0;
if (memdesc->priv & KGSL_MEMDESC_MAPPED)
return;
if (memdesc->hostptr) {
if (memdesc->priv & KGSL_MEMDESC_SECURE) {
atomic_long_sub(memdesc->size,