Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 88bb532b authored by Kaushal Sanadhya's avatar Kaushal Sanadhya
Browse files

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: default avatarLynus Vaz <quic_lvaz@quicinc.com>
Signed-off-by: default avatarKaushal Sanadhya <quic_ksanadhy@quicinc.com>
parent 30a9d3b2
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2002,2007-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.
 */

#include <linux/slab.h>
@@ -492,6 +492,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);
+7 −1
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
 * Copyright (c) 2002,2007-2021, The Linux Foundation. All rights reserved.
 * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
 */

#include <asm/cacheflush.h>
@@ -595,6 +595,9 @@ static int kgsl_unlock_sgt(struct sg_table *sgt)

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);
@@ -695,6 +698,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,