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

Commit 408e4f41 authored by Bharath's avatar Bharath
Browse files

Merge branch 'int/13/fp3' into lineage-20

* int/13/fp3:
  msm: kgsl: Keep postamble packets in a privileged buffer
  msm: kgsl: Make sure that pool pages don't have any extra references
  msm: kgsl: Use dma_buf_get() to get dma_buf structure
  ANDROID: usb: f_accessory: Check buffer size when initialised via composite

Change-Id: I0f2867eb112438b098ae89e94fab932078df3cfa
parents 09c4a685 8571a761
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
/* Copyright (c) 2008-2018,2020, 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
@@ -35,9 +35,6 @@
#define DEVICE_3D_NAME "kgsl-3d"
#define DEVICE_3D0_NAME "kgsl-3d0"

/* Index to preemption scratch buffer to store KMD postamble */
#define KMD_POSTAMBLE_IDX 100

/* ADRENO_DEVICE - Given a kgsl_device return the adreno device struct */
#define ADRENO_DEVICE(device) \
		container_of(device, struct adreno_device, dev)
+10 −9
Original line number Diff line number Diff line
/* Copyright (c) 2017-2018,2020, 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
@@ -557,8 +557,8 @@ unsigned int a6xx_preemption_pre_ibsubmit(
		 * preemption
		 */
		if (!adreno_dev->perfcounter) {
			u64 kmd_postamble_addr =
			PREEMPT_SCRATCH_ADDR(adreno_dev, KMD_POSTAMBLE_IDX);
			u64 kmd_postamble_addr = SCRATCH_POSTAMBLE_ADDR
						(KGSL_DEVICE(adreno_dev));

			*cmds++ = cp_type7_packet(CP_SET_AMBLE, 3);
			*cmds++ = lower_32_bits(kmd_postamble_addr);
@@ -784,14 +784,15 @@ int a6xx_preemption_init(struct adreno_device *adreno_dev)
	}

	/*
	 * First 8 dwords of the preemption scratch buffer is used to store the
	 * address for CP to save/restore VPC data. Reserve 11 dwords in the
	 * preemption scratch buffer from index KMD_POSTAMBLE_IDX for KMD
	 * postamble pm4 packets
	 * First 28 dwords of the device scratch buffer are used to store
	 * shadow rb data. Reserve 11 dwords in the device scratch buffer
	 * from SCRATCH_POSTAMBLE_OFFSET for KMD postamble pm4 packets.
	 * This should be in *device->scratch* so that userspace cannot
	 * access it.
	 */
	if (!adreno_dev->perfcounter) {
		u32 *postamble = preempt->scratch.hostptr +
					(KMD_POSTAMBLE_IDX * sizeof(u64));
		u32 *postamble = device->scratch.hostptr +
				SCRATCH_POSTAMBLE_OFFSET;
		u32 count = 0;

		postamble[count++] = cp_type7_packet(CP_REG_RMW, 3);
+33 −8
Original line number Diff line number Diff line
/* Copyright (c) 2008-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
@@ -2243,6 +2243,15 @@ static int kgsl_setup_anon_useraddr(struct kgsl_pagetable *pagetable,
}

#ifdef CONFIG_DMA_SHARED_BUFFER
static int match_file(const void *p, struct file *file, unsigned int fd)
{
	/*
	 * We must return fd + 1 because iterate_fd stops searching on
	 * non-zero return, but 0 is a valid fd.
	 */
	return (p == file) ? (fd + 1) : 0;
}

static void _setup_cache_mode(struct kgsl_mem_entry *entry,
		struct vm_area_struct *vma)
{
@@ -2280,6 +2289,8 @@ static int kgsl_setup_dmabuf_useraddr(struct kgsl_device *device,
	vma = find_vma(current->mm, hostptr);

	if (vma && vma->vm_file) {
		int fd;

		ret = check_vma_flags(vma, entry->memdesc.flags);
		if (ret) {
			up_read(&current->mm->mmap_sem);
@@ -2295,13 +2306,27 @@ static int kgsl_setup_dmabuf_useraddr(struct kgsl_device *device,
			return -EFAULT;
		}

		/* Look for the fd that matches this vma file */
		fd = iterate_fd(current->files, 0, match_file, vma->vm_file);
		if (fd) {
			dmabuf = dma_buf_get(fd - 1);
			if (IS_ERR(dmabuf)) {
				up_read(&current->mm->mmap_sem);
				return PTR_ERR(dmabuf);
			}
			/*
		 * Take a refcount because dma_buf_put() decrements the
		 * refcount
			 * It is possible that the fd obtained from iterate_fd
			 * was closed before passing the fd to dma_buf_get().
			 * Hence dmabuf returned by dma_buf_get() could be
			 * different from vma->vm_file->private_data. Return
			 * failure if this happens.
			 */
		get_file(vma->vm_file);

		dmabuf = vma->vm_file->private_data;
			if (dmabuf != vma->vm_file->private_data) {
				dma_buf_put(dmabuf);
				up_read(&current->mm->mmap_sem);
				return -EBADF;
			}
		}
	}

	if (IS_ERR_OR_NULL(dmabuf)) {
+6 −0
Original line number Diff line number Diff line
/* Copyright (c) 2008-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
@@ -83,6 +84,11 @@
#define SCRATCH_RPTR_GPU_ADDR(dev, id) \
	((dev)->scratch.gpuaddr + SCRATCH_RPTR_OFFSET(id))

/* OFFSET to KMD postamble packets in scratch buffer */
#define SCRATCH_POSTAMBLE_OFFSET (100 * sizeof(u64))
#define SCRATCH_POSTAMBLE_ADDR(dev) \
	((dev)->scratch.gpuaddr + SCRATCH_POSTAMBLE_OFFSET)

/* Timestamp window used to detect rollovers (half of integer range) */
#define KGSL_TIMESTAMP_WINDOW 0x80000000

+10 −0
Original line number Diff line number Diff line
/* Copyright (c) 2016-2017, 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
@@ -83,6 +84,15 @@ _kgsl_pool_zero_page(struct page *p, unsigned int pool_order)
static void
_kgsl_pool_add_page(struct kgsl_page_pool *pool, struct page *p)
{
	/*
	 * Sanity check to make sure we don't re-pool a page that
	 * somebody else has a reference to.
	 */
	if (WARN_ON_ONCE(unlikely(page_count(p) > 1))) {
		__free_pages(p, pool->pool_order);
		return;
	}

	_kgsl_pool_zero_page(p, pool->pool_order);

	spin_lock(&pool->list_lock);
Loading