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

Commit 8d25da1b authored by Akhil P Oommen's avatar Akhil P Oommen Committed by Gerrit - the friendly Code Review server
Browse files

msm: kgsl: Keep postamble packets in a privileged buffer



Postamble packets are executed in privileged mode by gpu. So we should keep
them in a privileged scratch buffer to block userspace access. For
targets with APRIV feature support, we can mark the preemption scratch
buffer as privileged too to avoid similar issues in future.

Change-Id: Ifda360dda251083f38dfde80ce1b5dc83daae902
Signed-off-by: default avatarAkhil P Oommen <quic_akhilpo@quicinc.com>
Signed-off-by: default avatarKaushal Sanadhya <quic_ksanadhy@quicinc.com>
parent 04f1df34
Loading
Loading
Loading
Loading
+1 −4
Original line number Original line Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-only */
/* SPDX-License-Identifier: GPL-2.0-only */
/*
/*
 * Copyright (c) 2008-2021, The Linux Foundation. All rights reserved.
 * 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.
 */
 */
#ifndef __ADRENO_H
#ifndef __ADRENO_H
#define __ADRENO_H
#define __ADRENO_H
@@ -16,9 +16,6 @@
#define DEVICE_3D_NAME "kgsl-3d"
#define DEVICE_3D_NAME "kgsl-3d"
#define DEVICE_3D0_NAME "kgsl-3d0"
#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 */
/* ADRENO_DEVICE - Given a kgsl_device return the adreno device struct */
#define ADRENO_DEVICE(device) \
#define ADRENO_DEVICE(device) \
		container_of(device, struct adreno_device, dev)
		container_of(device, struct adreno_device, dev)
+14 −11
Original line number Original line Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
// SPDX-License-Identifier: GPL-2.0-only
/*
/*
 * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
 * Copyright (c) 2017-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.
 */
 */


#include "adreno.h"
#include "adreno.h"
@@ -558,8 +558,8 @@ unsigned int a6xx_preemption_pre_ibsubmit(
		 * preemption
		 * preemption
		 */
		 */
		if (!adreno_dev->perfcounter) {
		if (!adreno_dev->perfcounter) {
			u64 kmd_postamble_addr =
			u64 kmd_postamble_addr = SCRATCH_POSTAMBLE_ADDR
			PREEMPT_SCRATCH_ADDR(adreno_dev, KMD_POSTAMBLE_IDX);
						(KGSL_DEVICE(adreno_dev));


			*cmds++ = cp_type7_packet(CP_SET_AMBLE, 3);
			*cmds++ = cp_type7_packet(CP_SET_AMBLE, 3);
			*cmds++ = lower_32_bits(kmd_postamble_addr);
			*cmds++ = lower_32_bits(kmd_postamble_addr);
@@ -763,6 +763,8 @@ void a6xx_preemption_close(struct adreno_device *adreno_dev)


int a6xx_preemption_init(struct adreno_device *adreno_dev)
int a6xx_preemption_init(struct adreno_device *adreno_dev)
{
{
	u32 flags = ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ?
			KGSL_MEMDESC_PRIVILEGED : 0;
	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
	struct adreno_preemption *preempt = &adreno_dev->preempt;
	struct adreno_preemption *preempt = &adreno_dev->preempt;
	struct adreno_ringbuffer *rb;
	struct adreno_ringbuffer *rb;
@@ -777,8 +779,8 @@ int a6xx_preemption_init(struct adreno_device *adreno_dev)


	timer_setup(&preempt->timer, _a6xx_preemption_timer, 0);
	timer_setup(&preempt->timer, _a6xx_preemption_timer, 0);


	ret = kgsl_allocate_global(device, &preempt->scratch, PAGE_SIZE, 0, 0,
	ret = kgsl_allocate_global(device, &preempt->scratch, PAGE_SIZE, 0,
			"preemption_scratch");
			flags, "preemption_scratch");


	/* Allocate mem for storing preemption switch record */
	/* Allocate mem for storing preemption switch record */
	FOR_EACH_RINGBUFFER(adreno_dev, rb, i) {
	FOR_EACH_RINGBUFFER(adreno_dev, rb, i) {
@@ -788,14 +790,15 @@ int a6xx_preemption_init(struct adreno_device *adreno_dev)
	}
	}


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


		postamble[count++] = cp_type7_packet(CP_REG_RMW, 3);
		postamble[count++] = cp_type7_packet(CP_REG_RMW, 3);
+6 −0
Original line number Original line Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-only */
/* SPDX-License-Identifier: GPL-2.0-only */
/*
/*
 * Copyright (c) 2008-2021, The Linux Foundation. All rights reserved.
 * Copyright (c) 2008-2021, The Linux Foundation. All rights reserved.
 * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
 */
 */
#ifndef __KGSL_H
#ifndef __KGSL_H
#define __KGSL_H
#define __KGSL_H
@@ -69,6 +70,11 @@
#define SCRATCH_RPTR_GPU_ADDR(dev, id) \
#define SCRATCH_RPTR_GPU_ADDR(dev, id) \
	((dev)->scratch.gpuaddr + SCRATCH_RPTR_OFFSET(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) */
/* Timestamp window used to detect rollovers (half of integer range) */
#define KGSL_TIMESTAMP_WINDOW 0x80000000
#define KGSL_TIMESTAMP_WINDOW 0x80000000