Skip to content

Commit 0c32f0a

Browse files
Akhil P OommenmikeNG
authored andcommitted
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: Akhil P Oommen <quic_akhilpo@quicinc.com> Signed-off-by: Kaushal Sanadhya <quic_ksanadhy@quicinc.com>
1 parent a8872ef commit 0c32f0a

3 files changed

Lines changed: 17 additions & 13 deletions

File tree

drivers/gpu/msm/adreno.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Copyright (c) 2008-2018,2020, The Linux Foundation. All rights reserved.
2-
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
2+
* Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License version 2 and
@@ -35,9 +35,6 @@
3535
#define DEVICE_3D_NAME "kgsl-3d"
3636
#define DEVICE_3D0_NAME "kgsl-3d0"
3737

38-
/* Index to preemption scratch buffer to store KMD postamble */
39-
#define KMD_POSTAMBLE_IDX 100
40-
4138
/* ADRENO_DEVICE - Given a kgsl_device return the adreno device struct */
4239
#define ADRENO_DEVICE(device) \
4340
container_of(device, struct adreno_device, dev)

drivers/gpu/msm/adreno_a6xx_preempt.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Copyright (c) 2017-2018,2020, The Linux Foundation. All rights reserved.
2-
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
2+
* Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License version 2 and
@@ -552,8 +552,8 @@ unsigned int a6xx_preemption_pre_ibsubmit(
552552
* preemption
553553
*/
554554
if (!adreno_dev->perfcounter) {
555-
u64 kmd_postamble_addr =
556-
PREEMPT_SCRATCH_ADDR(adreno_dev, KMD_POSTAMBLE_IDX);
555+
u64 kmd_postamble_addr = SCRATCH_POSTAMBLE_ADDR
556+
(KGSL_DEVICE(adreno_dev));
557557

558558
*cmds++ = cp_type7_packet(CP_SET_AMBLE, 3);
559559
*cmds++ = lower_32_bits(kmd_postamble_addr);
@@ -779,14 +779,15 @@ int a6xx_preemption_init(struct adreno_device *adreno_dev)
779779
}
780780

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

792793
postamble[count++] = cp_type7_packet(CP_REG_RMW, 3);

drivers/gpu/msm/kgsl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright (c) 2008-2021, The Linux Foundation. All rights reserved.
2+
* Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
23
*
34
* This program is free software; you can redistribute it and/or modify
45
* it under the terms of the GNU General Public License version 2 and
@@ -83,6 +84,11 @@
8384
#define SCRATCH_RPTR_GPU_ADDR(dev, id) \
8485
((dev)->scratch.gpuaddr + SCRATCH_RPTR_OFFSET(id))
8586

87+
/* OFFSET to KMD postamble packets in scratch buffer */
88+
#define SCRATCH_POSTAMBLE_OFFSET (100 * sizeof(u64))
89+
#define SCRATCH_POSTAMBLE_ADDR(dev) \
90+
((dev)->scratch.gpuaddr + SCRATCH_POSTAMBLE_OFFSET)
91+
8692
/* Timestamp window used to detect rollovers (half of integer range) */
8793
#define KGSL_TIMESTAMP_WINDOW 0x80000000
8894

0 commit comments

Comments
 (0)