From 5ffb9e5b7a80805f6e6c504cdd1d70d6411b51ab Mon Sep 17 00:00:00 2001 From: Jordan Crouse Date: Wed, 11 Sep 2019 08:32:15 -0600 Subject: [PATCH] msm: kgsl: Make the "scratch" global buffer use a random GPU address Select a random global GPU address for the "scratch" buffer that is used by the ringbuffer for various tasks. Change-Id: Ic0dedbaddda71dbf9cb2adab3c6c33a24d6a604c Signed-off-by: Jordan Crouse Signed-off-by: Harshitha Sai Neelati --- drivers/gpu/msm/adreno_ringbuffer.c | 2 +- drivers/gpu/msm/kgsl.h | 4 +++- drivers/gpu/msm/kgsl_iommu.c | 25 +++++++++++++++++++++---- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/msm/adreno_ringbuffer.c b/drivers/gpu/msm/adreno_ringbuffer.c index 8a3028c7b670..3a3777823013 100644 --- a/drivers/gpu/msm/adreno_ringbuffer.c +++ b/drivers/gpu/msm/adreno_ringbuffer.c @@ -277,7 +277,7 @@ int adreno_ringbuffer_probe(struct adreno_device *adreno_dev, bool nopreempt) if (!adreno_is_a3xx(adreno_dev)) { status = kgsl_allocate_global(device, &device->scratch, - PAGE_SIZE, 0, 0, "scratch"); + PAGE_SIZE, 0, KGSL_MEMDESC_RANDOM, "scratch"); if (status != 0) return status; } diff --git a/drivers/gpu/msm/kgsl.h b/drivers/gpu/msm/kgsl.h index a486d9a86f9d..6b8ef82d340f 100644 --- a/drivers/gpu/msm/kgsl.h +++ b/drivers/gpu/msm/kgsl.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2008-2016, 2018, The Linux Foundation. All rights reserved. +/* Copyright (c) 2008-2016,2018-2019, The Linux Foundation. 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 @@ -189,6 +189,8 @@ struct kgsl_memdesc_ops { #define KGSL_MEMDESC_TZ_LOCKED BIT(7) /* The memdesc is allocated through contiguous memory */ #define KGSL_MEMDESC_CONTIG BIT(8) +/* For global buffers, randomly assign an address from the region */ +#define KGSL_MEMDESC_RANDOM BIT(9) /** * struct kgsl_memdesc - GPU memory object descriptor diff --git a/drivers/gpu/msm/kgsl_iommu.c b/drivers/gpu/msm/kgsl_iommu.c index 30f7c9543e38..ffab5423d694 100644 --- a/drivers/gpu/msm/kgsl_iommu.c +++ b/drivers/gpu/msm/kgsl_iommu.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -198,7 +199,7 @@ static void kgsl_iommu_remove_global(struct kgsl_mmu *mmu, static void kgsl_iommu_add_global(struct kgsl_mmu *mmu, struct kgsl_memdesc *memdesc, const char *name) { - int bit; + u32 bit, start = 0; u64 size = kgsl_memdesc_footprint(memdesc); if (memdesc->gpuaddr != 0) @@ -207,10 +208,26 @@ static void kgsl_iommu_add_global(struct kgsl_mmu *mmu, if (WARN_ON(global_pt_count >= GLOBAL_PT_ENTRIES)) return; - bit = bitmap_find_next_zero_area(global_map, GLOBAL_MAP_PAGES, - 0, size >> PAGE_SHIFT, 0); + if (WARN_ON(size > KGSL_IOMMU_GLOBAL_MEM_SIZE)) + return; - if (WARN_ON(bit >= GLOBAL_MAP_PAGES)) + if (memdesc->priv & KGSL_MEMDESC_RANDOM) { + u32 range = GLOBAL_MAP_PAGES - (size >> PAGE_SHIFT); + + start = get_random_int() % range; + } + + while (start >= 0) { + bit = bitmap_find_next_zero_area(global_map, GLOBAL_MAP_PAGES, + start, size >> PAGE_SHIFT, 0); + + if (bit < GLOBAL_MAP_PAGES) + break; + + start--; + } + + if (WARN_ON(start < 0)) return; memdesc->gpuaddr =