drm/amdgpu: introduce secure buffer object support (trusted memory zone)
Subsystems (3)
v2 cover drm/amdgpu: introduce secure buffer object support (trusted memory zone)
Hi all,
These series of patches introduce a feature to support secure buffer object. The Trusted Memory Zone (TMZ) is a method to protect the contents being written to and read from memory. We use TMZ hardware memory protection scheme to implement the secure buffer object support.
TMZ is the page-level protection that hardware will detect the TMZ bit in the page table entry to set the current page is encrypted. With this hardware feature, we design a BO-level protection in kernel driver to provide a new flag AMDGPU_GEM_CREATE_ENCRYPTED to gem create ioctl to libdrm for the secure buffer allocation. And also provide the new AMDGPU_CS_FLAGS_SECURE to indicate the command submmission is trusted or not. If the BO is secure, then the data is encrypted, only the trusted IP blocks such as gfx, sdma, vcn are able to decrypt. CPU as the un-trusted IP are unable to read the secure buffer.
We will submit the new secure command later for libdrm, and create a new test suite to verify the security feature in the libdrm unit tests.
Suite id = 11: Name 'Security Tests status: ENABLED'
Test id 1: Name: 'allocate secure buffer test status: ENABLED' Test id 2: Name: 'graphics secure command submission status: ENABLED'
Changes from V1 -> V2:
- Change the UAPI from secure context to secure command submission for display server and client usage. (Thanks Luben)
- Remove ttm_mem_reg macro to get ttm_bo object.
- Move the amdgpu_bo_encrypted into amdgpu_vm_bo_update().
Thanks,
Ray
Alex Deucher (3):
drm/amdgpu: add UAPI for creating encrypted buffers drm/amdgpu: define the TMZ bit for the PTE drm/amdgpu: set TMZ bits in PTEs for secure BO (v4)
Huang Rui (7):
drm/amdgpu: add tmz feature parameter (v2) drm/amdgpu: add amdgpu_tmz data structure
drm/amdgpu: add function to check tmz capability (v4) drm/amdgpu: add tmz bit in frame control packet drm/amdgpu: expand the emit tmz interface with trusted flag drm/amdgpu: expand the context control interface with trust flag drm/amdgpu: job is secure iff CS is secure (v3)
Luben Tuikov (1):
drm/amdgpu: add UAPI to create secure commands (v3)
drivers/gpu/drm/amd/amdgpu/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 7 ++++- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 8 ++++- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 11 +++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 12 +++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 4 +-- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 11 +++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 9 +++--- drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.c | 49 ++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.h | 39 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 3 ++ drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 20 +++++++++--- drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c | 3 +- drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 3 +- drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 3 +- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 16 +++++++--- drivers/gpu/drm/amd/amdgpu/nvd.h | 1 + drivers/gpu/drm/amd/amdgpu/soc15d.h | 1 + include/uapi/drm/amdgpu_drm.h | 10 +++++- 22 files changed, 199 insertions(+), 23 deletions(-) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.c create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.h
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1569419090-5304-1-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org
PATCH v2 1/11 drm/amdgpu: add UAPI for creating encrypted buffers
From: Alex Deucher <[email protected]>
Add a flag to the GEM_CREATE ioctl to create encrypted buffers. Buffers with this flag set will be created with the TMZ bit set in the PTEs or engines accessing them. This is required in order to properly access the data from the engines.
--- include/uapi/drm/amdgpu_drm.h | 5 +++++ 1 file changed, 5 insertions(+)
include/uapi/drm/amdgpu_drm.h +5 -0
@@ -135,6 +135,11 @@ extern "C" {* releasing the memory */ #define AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE (1 << 9) +/* Flag that BO will be encrypted and that the TMZ bit should be +* set in the PTEs when mapping this buffer via GPUVM or +* accessing it with various hw blocks +*/ +#define AMDGPU_GEM_CREATE_ENCRYPTED (1 << 10)struct drm_amdgpu_gem_create_in {/** the requested memory size */
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v2 3/11 drm/amdgpu: define the TMZ bit for the PTE
In reply to a message not in the archiveFrom: Alex Deucher <[email protected]>
Define the TMZ (encryption) bit in the page table entry (PTE) for Raven and newer asics.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +3 -0
@@ -53,6 +53,9 @@ struct amdgpu_bo_list_entry;#define AMDGPU_PTE_SYSTEM (1ULL << 1)#define AMDGPU_PTE_SNOOPED (1ULL << 2) +/* RV+ */ +#define AMDGPU_PTE_TMZ (1ULL << 3) +/* VI only */ #define AMDGPU_PTE_EXECUTABLE (1ULL << 4)
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v2 4/11 drm/amdgpu: add tmz feature parameter (v2)
In reply to a message not in the archiveThis patch adds tmz parameter to enable/disable the feature in the amdgpu kernel module. Nomally, by default, it should be auto (rely on the hardware capability).
But right now, it need to set "off" to avoid breaking other developers' work because it's not totally completed.
Will set "auto" till the feature is stable and completely verified.
v2: add "auto" option for future use.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 11 +++++++++++ 2 files changed, 12 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -172,6 +172,7 @@ extern int amdgpu_force_asic_type;#ifdef CONFIG_HSA_AMD extern int sched_policy;#endif +extern int amdgpu_tmz;#ifdef CONFIG_DRM_AMDGPU_SI extern int amdgpu_si_support;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +11 -0
@@ -145,6 +145,7 @@ int amdgpu_discovery = -1;int amdgpu_mes =0 ;int amdgpu_noretry =1 ;int amdgpu_force_asic_type =-1 ; +int amdgpu_tmz =0 ;struct amdgpu_mgpu_info mgpu_info = { .mutex =__MUTEX_INITIALIZER (mgpu_info.mutex),
@@ -752,6 +753,16 @@ uint amdgpu_dm_abm_level = 0;MODULE_PARM_DESC (abmlevel,"ABM level (0 = off (default), 1-4 = backlight reduction level) " );module_param_named (abmlevel, amdgpu_dm_abm_level, uint,0444 ); +/** +* DOC: tmz (int) +* Trust Memory Zone (TMZ) is a method to protect the contents being written to +* and read from memory. +* +* The default value: 0 (off). TODO: change to auto till it is completed. +*/ +MODULE_PARM_DESC (tmz,"Enable TMZ feature (-1 = auto, 0 = off (default), 1 = on)" ); +module_param_named (tmz, amdgpu_tmz, int,0444 ); +static const struct pci_device_id pciidlist[] = { #ifdef CONFIG_DRM_AMDGPU_SI {0x1002, 0x6780, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v2 5/11 drm/amdgpu: add amdgpu_tmz data structure
In reply to a message not in the archiveThis patch to add amdgpu_tmz structure which stores all tmz related fields.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 6 +++++- drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.h | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.h
drivers/gpu/drm/amd/amdgpu/amdgpu.h +5 -1
@@ -89,6 +89,7 @@#include "amdgpu_mes.h" #include "amdgpu_umc.h" #include "amdgpu_mmhub.h" +#include "amdgpu_tmz.h" #define MAX_GPU_INSTANCE 16
@@ -916,6 +917,9 @@ struct amdgpu_device {bool enable_mes;struct amdgpu_mes mes; +/* tmz */ +struct amdgpu_tmz tmz; +struct amdgpu_ip_block ip_blocks[AMDGPU_MAX_IP_NUM ];int num_ip_blocks;struct mutex mn_lock;
@@ -927,7 +931,7 @@ struct amdgpu_device {atomic64_t gart_pin_size;/* soc15 register offset based on ip, instance and segment */ -uint32_t *reg_offset[MAX_HWIP ][HWIP_MAX_INSTANCE ]; +uint32_t *reg_offset[MAX_HWIP ][HWIP_MAX_INSTANCE ];const struct amdgpu_df_funcs *df_funcs;const struct amdgpu_mmhub_funcs *mmhub_funcs;
drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Copyright 2019 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +*/ + +#ifndef __AMDGPU_TMZ_H__ +#define __AMDGPU_TMZ_H__ + +#include "amdgpu.h" + +/* +* Trust memory zone stuff +*/ +struct amdgpu_tmz { +bool enabled; +}; + +#endif
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v2 6/11 drm/amdgpu: add function to check tmz capability (v4)
In reply to a message not in the archiveAdd a function to check tmz capability with kernel parameter and ASIC type.
v2: use a per device tmz variable instead of global amdgpu_tmz.
v3: refine the comments for the function. (Luben)
v4: add amdgpu_tmz.c/h for future use.
--- drivers/gpu/drm/amd/amdgpu/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.c | 49 ++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.h | 3 ++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.c
drivers/gpu/drm/amd/amdgpu/Makefile +1 -1
@@ -55,7 +55,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \ amdgpu_vf_error.o amdgpu_sched.o amdgpu_debugfs.o amdgpu_ids.o \ amdgpu_gmc.o amdgpu_mmhub.o amdgpu_xgmi.o amdgpu_csa.o amdgpu_ras.o amdgpu_vm_cpu.o \ amdgpu_vm_sdma.o amdgpu_pmu.o amdgpu_discovery.o amdgpu_ras_eeprom.o amdgpu_nbio.o \ - amdgpu_umc.o smu_v11_0_i2c.o + amdgpu_umc.o smu_v11_0_i2c.o amdgpu_tmz.o amdgpu-$(CONFIG_PERF_EVENTS) += amdgpu_pmu.o
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
@@ -63,6 +63,7 @@#include "amdgpu_xgmi.h" #include "amdgpu_ras.h" #include "amdgpu_pmu.h" +#include "amdgpu_tmz.h" #include <linux/suspend.h>
@@ -1032,6 +1033,8 @@ static int amdgpu_device_check_arguments(struct amdgpu_device *adev) adev->firmware.load_type =amdgpu_ucode_get_load_type (adev, amdgpu_fw_load_type); + adev->tmz.enabled =amdgpu_is_tmz (adev); +return ret; }
drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.c new file +49 -0
49 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.h +3 -0
@@ -33,4 +33,7 @@ struct amdgpu_tmz { bool enabled; }; + +extern bool amdgpu_is_tmz (struct amdgpu_device *adev); +#endif
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v2 7/11 drm/amdgpu: add tmz bit in frame control packet
In reply to a message not in the archiveThis patch adds tmz bit in frame control pm4 packet, and it will used in future.
--- drivers/gpu/drm/amd/amdgpu/nvd.h | 1 + drivers/gpu/drm/amd/amdgpu/soc15d.h | 1 + 2 files changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/nvd.h +1 -0
@@ -306,6 +306,7 @@#define PACKET3_GET_LOD_STATS 0x8E#define PACKET3_DRAW_MULTI_PREAMBLE 0x8F#define PACKET3_FRAME_CONTROL 0x90 +# define FRAME_TMZ (1 << 0)# define FRAME_CMD (x) ((x) << 28)/* * x=0: tmz_begin
drivers/gpu/drm/amd/amdgpu/soc15d.h +1 -0
@@ -286,6 +286,7 @@#define PACKET3_WAIT_ON_DE_COUNTER_DIFF 0x88#define PACKET3_SWITCH_BUFFER 0x8B#define PACKET3_FRAME_CONTROL 0x90 +# define FRAME_TMZ (1 << 0)# define FRAME_CMD (x) ((x) << 28)/* * x=0: tmz_begin
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v2 9/11 drm/amdgpu: expand the context control interface with trust flag
In reply to a message not in the archiveThis patch expands the context control function to support trusted flag while we want to set command buffer in trusted mode.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 5 +++-- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 4 +++- drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c | 3 ++- drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 3 ++- drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 3 ++- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 5 +++-- 7 files changed, 16 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +1 -1
@@ -210,7 +210,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,if (job && ring->funcs->emit_cntxcntl) { status |= job->preamble_status; status |= job->preemption_status; -amdgpu_ring_emit_cntxcntl (ring, status); +amdgpu_ring_emit_cntxcntl (ring, status, false); }for (i =0 ; i < num_ibs; ++i) {
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +3 -2
@@ -158,7 +158,8 @@ struct amdgpu_ring_funcs {void (*begin_use)(struct amdgpu_ring *ring);void (*end_use)(struct amdgpu_ring *ring);void (*emit_switch_buffer) (struct amdgpu_ring *ring); -void (*emit_cntxcntl) (struct amdgpu_ring *ring,uint32_t flags); +void (*emit_cntxcntl) (struct amdgpu_ring *ring,uint32_t flags, +bool trusted);void (*emit_rreg)(struct amdgpu_ring *ring,uint32_t reg);void (*emit_wreg)(struct amdgpu_ring *ring,uint32_t reg,uint32_t val); void (*emit_reg_wait)(struct amdgpu_ring *ring, uint32_t reg,
@@ -242,7 +243,7 @@ struct amdgpu_ring {#define amdgpu_ring_emit_gds_switch (r, v, db, ds, wb, ws, ab, as) (r)->funcs->emit_gds_switch((r), (v), (db), (ds), (wb), (ws), (ab), (as))#define amdgpu_ring_emit_hdp_flush (r) (r)->funcs->emit_hdp_flush((r))#define amdgpu_ring_emit_switch_buffer (r) (r)->funcs->emit_switch_buffer((r)) -#define amdgpu_ring_emit_cntxcntl (r, d) (r)->funcs->emit_cntxcntl((r), (d)) +#define amdgpu_ring_emit_cntxcntl (r, d, s) (r)->funcs->emit_cntxcntl((r), (d), (s))#define amdgpu_ring_emit_rreg (r, d) (r)->funcs->emit_rreg((r), (d))#define amdgpu_ring_emit_wreg (r, d, v) (r)->funcs->emit_wreg((r), (d), (v))#define amdgpu_ring_emit_reg_wait (r, d, v, m) (r)->funcs->emit_reg_wait((r), (d), (v), (m))
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +3 -1
@@ -4514,7 +4514,9 @@ static void gfx_v10_0_ring_emit_sb(struct amdgpu_ring *ring)amdgpu_ring_write (ring,0 ); } -static void gfx_v10_0_ring_emit_cntxcntl (struct amdgpu_ring *ring,uint32_t flags) +static void gfx_v10_0_ring_emit_cntxcntl (struct amdgpu_ring *ring, +uint32_t flags, +bool trusted) {uint32_t dw2 =0 ;
drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c +2 -1
@@ -2972,7 +2972,8 @@ static uint64_t gfx_v6_0_get_gpu_clock_counter(struct amdgpu_device *adev)return clock; } -static void gfx_v6_ring_emit_cntxcntl (struct amdgpu_ring *ring,uint32_t flags) +static void gfx_v6_ring_emit_cntxcntl (struct amdgpu_ring *ring,uint32_t flags, +bool trusted) {if (flags &AMDGPU_HAVE_CTX_SWITCH )gfx_v6_0_ring_emit_vgt_flush (ring);
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +2 -1
@@ -2309,7 +2309,8 @@ static void gfx_v7_0_ring_emit_ib_compute(struct amdgpu_ring *ring,amdgpu_ring_write (ring, control); } -static void gfx_v7_ring_emit_cntxcntl (struct amdgpu_ring *ring,uint32_t flags) +static void gfx_v7_ring_emit_cntxcntl (struct amdgpu_ring *ring,uint32_t flags, +bool trusted) {uint32_t dw2 =0 ;
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +2 -1
@@ -6393,7 +6393,8 @@ static void gfx_v8_ring_emit_sb(struct amdgpu_ring *ring)amdgpu_ring_write (ring,0 ); } -static void gfx_v8_ring_emit_cntxcntl (struct amdgpu_ring *ring,uint32_t flags) +static void gfx_v8_ring_emit_cntxcntl (struct amdgpu_ring *ring,uint32_t flags, +bool trusted) {uint32_t dw2 =0 ;
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +3 -2
@@ -5253,14 +5253,15 @@ static void gfx_v9_0_ring_emit_tmz(struct amdgpu_ring *ring, bool start, | FRAME_CMD(start ? 0 : 1)); } -static void gfx_v9_ring_emit_cntxcntl (struct amdgpu_ring *ring,uint32_t flags) +static void gfx_v9_ring_emit_cntxcntl (struct amdgpu_ring *ring,uint32_t flags, +bool trusted) {uint32_t dw2 =0 ;if (amdgpu_sriov_vf (ring->adev))gfx_v9_0_ring_emit_ce_meta (ring); -gfx_v9_0_ring_emit_tmz (ring, true, false); +gfx_v9_0_ring_emit_tmz (ring, true, trusted); dw2 |=0x80000000 ;/* set load_enable otherwise this package is just NOPs */ if (flags &AMDGPU_HAVE_CTX_SWITCH ) {
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v2 10/11 drm/amdgpu: job is secure iff CS is secure (v3)
In reply to a message not in the archiveMark a job as secure, if and only if the command submission flag has the secure flag set.
v2: fix the null job pointer while in vmid 0 submission.
v3: Context --> Command submission.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 8 +++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +7 -1
@@ -1252,8 +1252,14 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p, p->ctx->preamble_presented = true; } - cs->out.handle = seq; +/* The command submission (cs) is a union, so an assignment to +* 'out' is destructive to the cs (at least the first 8 +* bytes). For this reason, inquire about the flags before the +* assignment to 'out'. +*/ + job->secure = cs->in.flags &AMDGPU_CS_FLAGS_SECURE ; job->uf_sequence = seq; + cs->out.handle = seq;amdgpu_job_free_resources (job);
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +2 -2
@@ -210,7 +210,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,if (job && ring->funcs->emit_cntxcntl) { status |= job->preamble_status; status |= job->preemption_status; -amdgpu_ring_emit_cntxcntl (ring, status, false); +amdgpu_ring_emit_cntxcntl (ring, status, job->secure); }for (i =0 ; i < num_ibs; ++i) {
@@ -229,7 +229,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs, }if (ring->funcs->emit_tmz) -amdgpu_ring_emit_tmz (ring, false, false); +amdgpu_ring_emit_tmz (ring, false, job ? job->secure : false);#ifdef CONFIG_X86_64 if (!(adev->flags &AMD_IS_APU ))
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +2 -0
@@ -63,6 +63,8 @@ struct amdgpu_job {uint64_t uf_addr;uint64_t uf_sequence; +/* the job is due to a secure command submission */ +bool secure; }; int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1569419090-5304-11-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org
Re: [PATCH v2 10/11] drm/amdgpu: job is secure iff CS is secure (v3)
Am 25.09.19 um 15:45 schrieb Huang, Ray:
Quoted 22 lines
Mark a job as secure, if and only if the command submission flag has the secure flag set.
v2: fix the null job pointer while in vmid 0 submission.
v3: Context --> Command submission.Signed-off-by Huang Rui <[email protected]>Co-developed-by Luben Tuikov <[email protected]>Signed-off-by Luben Tuikov <[email protected]>Reviewed-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 8 +++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_submit(struct amdgpu_cs_parser *p, · line 1260
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +6
-1@@ -1252,8 +1252,14 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p, p->ctx->preamble_presented = true; } - cs->out.handle = seq; +/* The command submission (cs) is a union, so an assignment to +* 'out' is destructive to the cs (at least the first 8 +* bytes). For this reason, inquire about the flags before the +* assignment to 'out'. +*/ + job->secure = cs->in.flags &AMDGPU_CS_FLAGS_SECURE ;
NAK accessing cs->in.flags in the submission function is a no-go here.
You need to fill those things up during job creation, see amdgpu_cs_parser_init().
Regards,
Christian.
Quoted 32 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1
-0job->uf_sequence = seq; + cs->out.handle = seq;amdgpu_job_free_resources (job);drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +2
-2@@ -210,7 +210,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,if (job && ring->funcs->emit_cntxcntl) { status |= job->preamble_status; status |= job->preemption_status; -amdgpu_ring_emit_cntxcntl (ring, status, false); +amdgpu_ring_emit_cntxcntl (ring, status, job->secure); }for (i =0 ; i < num_ibs; ++i) {@@ -229,7 +229,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs, }if (ring->funcs->emit_tmz) -amdgpu_ring_emit_tmz (ring, false, false); +amdgpu_ring_emit_tmz (ring, false, job ? job->secure : false);#ifdef CONFIG_X86_64 if (!(adev->flags &AMD_IS_APU ))drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h struct amdgpu_job { · line 70
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +2
-0@@ -63,6 +63,8 @@ struct amdgpu_job {uint64_t uf_addr;uint64_t uf_sequence; +/* the job is due to a secure command submission */ +bool secure; }; int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v2 2/11 drm/amdgpu: add UAPI to create secure commands (v3)
In reply to Huang, RayFrom: Luben Tuikov <[email protected]>
Add a flag to the command submission IOCTL structure which when present indicates that this command submission should be treated as secure. The kernel driver uses this flag to determine whether the engine should be transitioned to secure or unsecure, or the work can be submitted to a secure queue depending on the IP.
v3: the flag is now at command submission IOCTL
--- include/uapi/drm/amdgpu_drm.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
include/uapi/drm/amdgpu_drm.h +4 -1
@@ -207,6 +207,9 @@ union drm_amdgpu_bo_list {#define AMDGPU_CTX_OP_QUERY_STATE 3#define AMDGPU_CTX_OP_QUERY_STATE2 4 +/* Flag the command submission as secure */ +#define AMDGPU_CS_FLAGS_SECURE (1 << 0) +/* GPU reset status */ #define AMDGPU_CTX_NO_RESET 0/* this the context caused it */
@@ -562,7 +565,7 @@ struct drm_amdgpu_cs_in {/** Handle of resource list associated with CS */ __u32 bo_list_handle;__u32 num_chunks; -__u32 _pad; +__u32 flags;/** this points to __u64 * which point to cs chunks */ __u64 chunks; };
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 8/11 drm/amdgpu: expand the emit tmz interface with trusted flag
In reply to Huang, RayThis patch expands the emit_tmz function to support trusted flag while we want to set command buffer in trusted mode.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 4 ++-- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 16 ++++++++++++---- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 13 ++++++++++--- 4 files changed, 25 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +1 -1
@@ -229,7 +229,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs, }if (ring->funcs->emit_tmz) -amdgpu_ring_emit_tmz (ring, false); +amdgpu_ring_emit_tmz (ring, false, false);#ifdef CONFIG_X86_64 if (!(adev->flags &AMD_IS_APU ))
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -2
@@ -166,7 +166,7 @@ struct amdgpu_ring_funcs {void (*emit_reg_write_reg_wait)(struct amdgpu_ring *ring,uint32_t reg0,uint32_t reg1,uint32_t ref,uint32_t mask); -void (*emit_tmz)(struct amdgpu_ring *ring,bool start); +void (*emit_tmz)(struct amdgpu_ring *ring,bool start,bool trusted);/* priority functions */ void (*set_priority) (struct amdgpu_ring *ring,enum drm_sched_priority priority);
@@ -247,7 +247,7 @@ struct amdgpu_ring {#define amdgpu_ring_emit_wreg (r, d, v) (r)->funcs->emit_wreg((r), (d), (v))#define amdgpu_ring_emit_reg_wait (r, d, v, m) (r)->funcs->emit_reg_wait((r), (d), (v), (m))#define amdgpu_ring_emit_reg_write_reg_wait (r, d0, d1, v, m) (r)->funcs->emit_reg_write_reg_wait((r), (d0), (d1), (v), (m)) -#define amdgpu_ring_emit_tmz (r, b) (r)->funcs->emit_tmz((r), (b)) +#define amdgpu_ring_emit_tmz (r, b, s) (r)->funcs->emit_tmz((r), (b), (s))#define amdgpu_ring_pad_ib (r, ib) ((r)->funcs->pad_ib((r), (ib)))#define amdgpu_ring_init_cond_exec (r) (r)->funcs->init_cond_exec((r))#define amdgpu_ring_patch_cond_exec (r,o) (r)->funcs->patch_cond_exec((r),(o))
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +12 -4
@@ -243,7 +243,8 @@ static int gfx_v10_0_rlc_backdoor_autoload_enable(struct amdgpu_device *adev);static int gfx_v10_0_wait_for_rlc_autoload_complete (struct amdgpu_device *adev);static void gfx_v10_0_ring_emit_ce_meta (struct amdgpu_ring *ring,bool resume);static void gfx_v10_0_ring_emit_de_meta (struct amdgpu_ring *ring,bool resume); -static void gfx_v10_0_ring_emit_tmz (struct amdgpu_ring *ring,bool start); +static void gfx_v10_0_ring_emit_tmz (struct amdgpu_ring *ring,bool start, +bool trusted);static void gfx10_kiq_set_resources (struct amdgpu_ring *kiq_ring,uint64_t queue_mask) {
@@ -4521,7 +4522,7 @@ static void gfx_v10_0_ring_emit_cntxcntl(struct amdgpu_ring *ring, uint32_t flaggfx_v10_0_ring_emit_ce_meta (ring, flags &AMDGPU_IB_PREEMPTED ? true : false); -gfx_v10_0_ring_emit_tmz (ring, true); +gfx_v10_0_ring_emit_tmz (ring, true, false); dw2 |=0x80000000 ;/* set load_enable otherwise this package is just NOPs */ if (flags &AMDGPU_HAVE_CTX_SWITCH ) {
@@ -4679,10 +4680,17 @@ static void gfx_v10_0_ring_emit_de_meta(struct amdgpu_ring *ring, bool resume) sizeof(de_payload) >> 2); } -static void gfx_v10_0_ring_emit_tmz (struct amdgpu_ring *ring,bool start) +static void gfx_v10_0_ring_emit_tmz (struct amdgpu_ring *ring,bool start, +bool trusted) {amdgpu_ring_write (ring,PACKET3 (PACKET3_FRAME_CONTROL ,0 )); -amdgpu_ring_write (ring,FRAME_CMD (start ?0 :1 ));/* frame_end */ +/* +* cmd = 0: frame begin +* cmd = 1: frame end +*/ +amdgpu_ring_write (ring, + ((ring->adev->tmz.enabled && trusted) ?FRAME_TMZ :0 ) + |FRAME_CMD (start ?0 :1 )); }static void gfx_v10_0_ring_emit_rreg (struct amdgpu_ring *ring,uint32_t reg)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +10 -3
@@ -5240,10 +5240,17 @@ static void gfx_v9_0_ring_emit_de_meta(struct amdgpu_ring *ring)amdgpu_ring_write_multiple (ring, (void *)&de_payload,sizeof (de_payload) >>2 ); } -static void gfx_v9_0_ring_emit_tmz (struct amdgpu_ring *ring,bool start) +static void gfx_v9_0_ring_emit_tmz (struct amdgpu_ring *ring,bool start, +bool trusted) {amdgpu_ring_write (ring,PACKET3 (PACKET3_FRAME_CONTROL ,0 )); -amdgpu_ring_write (ring,FRAME_CMD (start ?0 :1 ));/* frame_end */ +/* +* cmd = 0: frame begin +* cmd = 1: frame end +*/ +amdgpu_ring_write (ring, + ((ring->adev->tmz.enabled && trusted) ?FRAME_TMZ :0 ) + |FRAME_CMD (start ?0 :1 )); }static void gfx_v9_ring_emit_cntxcntl (struct amdgpu_ring *ring,uint32_t flags)
@@ -5253,7 +5260,7 @@ static void gfx_v9_ring_emit_cntxcntl(struct amdgpu_ring *ring, uint32_t flags)if (amdgpu_sriov_vf (ring->adev))gfx_v9_0_ring_emit_ce_meta (ring); -gfx_v9_0_ring_emit_tmz (ring, true); +gfx_v9_0_ring_emit_tmz (ring, true, false); dw2 |=0x80000000 ;/* set load_enable otherwise this package is just NOPs */ if (flags &AMDGPU_HAVE_CTX_SWITCH ) {
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 11/11 drm/amdgpu: set TMZ bits in PTEs for secure BO (v4)
In reply to Huang, RayFrom: Alex Deucher <[email protected]>
If a buffer object is secure, i.e. created withAMDGPU_GEM_CREATE_ENCRYPTED, then the TMZ bit of
the PTEs that belong the buffer object should be
set.
v1: design and draft the skeletion of TMZ bits setting on PTEs (Alex)
v2: return failure once create secure BO on non-TMZ platform (Ray)
v3: amdgpu_bo_encrypted() only checks the BO (Luben)
v4: move TMZ flag setting into amdgpu_vm_bo_update (Christian)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 12 +++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 11 +++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 +++++ 3 files changed, 27 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +11 -1
@@ -222,7 +222,8 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,AMDGPU_GEM_CREATE_CPU_GTT_USWC |AMDGPU_GEM_CREATE_VRAM_CLEARED |AMDGPU_GEM_CREATE_VM_ALWAYS_VALID | - AMDGPU_GEM_CREATE_EXPLICIT_SYNC)) +AMDGPU_GEM_CREATE_EXPLICIT_SYNC | + AMDGPU_GEM_CREATE_ENCRYPTED)) return -EINVAL;
@@ -230,6 +231,11 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,if (args->in.domains & ~AMDGPU_GEM_DOMAIN_MASK )return -EINVAL ; +if (!adev->tmz.enabled && (flags &AMDGPU_GEM_CREATE_ENCRYPTED )) { +DRM_ERROR ("Cannot allocate secure buffer while tmz is disabled\n" ); +return -EINVAL ; + } +/* create a gem object to contain this object in */ if (args->in.domains & (AMDGPU_GEM_DOMAIN_GDS |AMDGPU_GEM_DOMAIN_GWS |AMDGPU_GEM_DOMAIN_OA )) {
@@ -251,6 +257,10 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, resv = vm->root.base.bo->tbo.resv; } +if (flags &AMDGPU_GEM_CREATE_ENCRYPTED ) { +/* XXX: pad out alignment to meet TMZ requirements */ + } + r =amdgpu_gem_object_create (adev, size, args->in.alignment, (u32)(0xffffffff & args->in.domains), flags, ttm_bo_type_device, resv, &gobj);
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +11 -0
@@ -224,6 +224,17 @@ static inline bool amdgpu_bo_explicit_sync(struct amdgpu_bo *bo)return bo->flags &AMDGPU_GEM_CREATE_EXPLICIT_SYNC ; } +/** +* amdgpu_bo_encrypted - test if the BO is encrypted +* @bo: pointer to a buffer object +* +* Return true if the buffer object is encrypted, false otherwise. +*/ +static inline bool amdgpu_bo_encrypted (struct amdgpu_bo *bo) +{ +return bo->flags &AMDGPU_GEM_CREATE_ENCRYPTED ; +} +bool amdgpu_bo_is_amdgpu_bo (struct ttm_buffer_object *bo);void amdgpu_bo_placement_from_domain (struct amdgpu_bo *abo,u32 domain);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5 -0
@@ -1688,6 +1688,11 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,if (bo) { flags =amdgpu_ttm_tt_pte_flags (adev, bo->tbo.ttm, mem); + +if (amdgpu_bo_encrypted (bo)) { + flags |=AMDGPU_PTE_TMZ ; + } + bo_adev =amdgpu_ttm_adev (bo->tbo.bdev); }else { flags =0x0 ;
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
A message that is not in the archive (sent off-list or not yet received): 1569419090-5304-12-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org
Re: [PATCH v2 11/11] drm/amdgpu: set TMZ bits in PTEs for secure BO (v4)
Am 25.09.19 um 15:45 schrieb Huang, Ray:
Quoted 87 lines
From: Alex Deucher <[email protected]>
If a buffer object is secure, i.e. created with
AMDGPU_GEM_CREATE_ENCRYPTED, then the TMZ bit of
the PTEs that belong the buffer object should be
set.v1: design and draft the skeletion of TMZ bits setting on PTEs (Alex)
v2: return failure once create secure BO on non-TMZ platform (Ray)
v3:amdgpu_bo_encrypted()only checks the BO (Luben)
v4: move TMZ flag setting intoamdgpu_vm_bo_update(Christian)Signed-off-by Alex Deucher <[email protected]>Reviewed-by Huang Rui <[email protected]>Signed-off-by Huang Rui <[email protected]>Signed-off-by Luben Tuikov <[email protected]>Reviewed-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 12 +++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 11 +++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 +++++ 3 files changed, 27 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +11
-1@@ -222,7 +222,8 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,AMDGPU_GEM_CREATE_CPU_GTT_USWC |AMDGPU_GEM_CREATE_VRAM_CLEARED |AMDGPU_GEM_CREATE_VM_ALWAYS_VALID | - AMDGPU_GEM_CREATE_EXPLICIT_SYNC)) +AMDGPU_GEM_CREATE_EXPLICIT_SYNC | + AMDGPU_GEM_CREATE_ENCRYPTED)) return -EINVAL;@@ -230,6 +231,11 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,if (args->in.domains & ~AMDGPU_GEM_DOMAIN_MASK )return -EINVAL ; +if (!adev->tmz.enabled && (flags &AMDGPU_GEM_CREATE_ENCRYPTED )) { +DRM_ERROR ("Cannot allocate secure buffer while tmz is disabled\n" ); +return -EINVAL ; + } +/* create a gem object to contain this object in */ if (args->in.domains & (AMDGPU_GEM_DOMAIN_GDS |AMDGPU_GEM_DOMAIN_GWS |AMDGPU_GEM_DOMAIN_OA )) {@@ -251,6 +257,10 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, resv = vm->root.base.bo->tbo.resv; } +if (flags &AMDGPU_GEM_CREATE_ENCRYPTED ) { +/* XXX: pad out alignment to meet TMZ requirements */ + } + r =amdgpu_gem_object_create (adev, size, args->in.alignment, (u32)(0xffffffff & args->in.domains), flags, ttm_bo_type_device, resv, &gobj);drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +11
-0@@ -224,6 +224,17 @@ static inline bool amdgpu_bo_explicit_sync(struct amdgpu_bo *bo)return bo->flags &AMDGPU_GEM_CREATE_EXPLICIT_SYNC ; } +/** +* amdgpu_bo_encrypted - test if the BO is encrypted +* @bo: pointer to a buffer object +* +* Return true if the buffer object is encrypted, false otherwise. +*/ +static inline bool amdgpu_bo_encrypted (struct amdgpu_bo *bo) +{ +return bo->flags &AMDGPU_GEM_CREATE_ENCRYPTED ; +} +bool amdgpu_bo_is_amdgpu_bo (struct ttm_buffer_object *bo);void amdgpu_bo_placement_from_domain (struct amdgpu_bo *abo,u32 domain);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_bo_update(struct amdgpu_device *adev, · line 1695
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0@@ -1688,6 +1688,11 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,if (bo) { flags =amdgpu_ttm_tt_pte_flags (adev, bo->tbo.ttm, mem); + +if (amdgpu_bo_encrypted (bo)) { + flags |=AMDGPU_PTE_TMZ ; + } +
You can drop the {} here, apart from that the patch is Reviewed-by:
Christian König <[email protected]>.
From the design it would be indeed nicer to have that inamdgpu_ttm_tt_pte_flags(), but we would need to make sure that this is not called any more from binding a tt.
Regards,
Christian.
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_bo_update(struct amdgpu_device *adev, · line 1698
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0bo_adev =amdgpu_ttm_adev (bo->tbo.bdev); }else { flags =0x0 ;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 507b6359-897a-20a1-2fff-28634858f464-5C7GfCeVMHo@public.gmane.org
Re: [PATCH v2 11/11] drm/amdgpu: set TMZ bits in PTEs for secure BO (v4)
Quoted 101 lines · Christian
Am 25.09.19 um 15:45 schrieb Huang, Ray:
Quoted 87 lines
From: Alex Deucher <[email protected]>
If a buffer object is secure, i.e. created with
AMDGPU_GEM_CREATE_ENCRYPTED, then the TMZ bit of
the PTEs that belong the buffer object should be
set.v1: design and draft the skeletion of TMZ bits setting on PTEs (Alex)
v2: return failure once create secure BO on non-TMZ platform (Ray)
v3:amdgpu_bo_encrypted()only checks the BO (Luben)
v4: move TMZ flag setting intoamdgpu_vm_bo_update(Christian)Signed-off-by Alex Deucher <[email protected]>Reviewed-by Huang Rui <[email protected]>Signed-off-by Huang Rui <[email protected]>Signed-off-by Luben Tuikov <[email protected]>Reviewed-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 12 +++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 11 +++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 +++++ 3 files changed, 27 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +11
-1@@ -222,7 +222,8 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,AMDGPU_GEM_CREATE_CPU_GTT_USWC |AMDGPU_GEM_CREATE_VRAM_CLEARED |AMDGPU_GEM_CREATE_VM_ALWAYS_VALID | - AMDGPU_GEM_CREATE_EXPLICIT_SYNC)) +AMDGPU_GEM_CREATE_EXPLICIT_SYNC | + AMDGPU_GEM_CREATE_ENCRYPTED)) return -EINVAL;@@ -230,6 +231,11 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,if (args->in.domains & ~AMDGPU_GEM_DOMAIN_MASK )return -EINVAL ; +if (!adev->tmz.enabled && (flags &AMDGPU_GEM_CREATE_ENCRYPTED )) { +DRM_ERROR ("Cannot allocate secure buffer while tmz is disabled\n" ); +return -EINVAL ; + } +/* create a gem object to contain this object in */ if (args->in.domains & (AMDGPU_GEM_DOMAIN_GDS |AMDGPU_GEM_DOMAIN_GWS |AMDGPU_GEM_DOMAIN_OA )) {@@ -251,6 +257,10 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, resv = vm->root.base.bo->tbo.resv; } +if (flags &AMDGPU_GEM_CREATE_ENCRYPTED ) { +/* XXX: pad out alignment to meet TMZ requirements */ + } + r =amdgpu_gem_object_create (adev, size, args->in.alignment, (u32)(0xffffffff & args->in.domains), flags, ttm_bo_type_device, resv, &gobj);drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +11
-0@@ -224,6 +224,17 @@ static inline bool amdgpu_bo_explicit_sync(struct amdgpu_bo *bo)return bo->flags &AMDGPU_GEM_CREATE_EXPLICIT_SYNC ; } +/** +* amdgpu_bo_encrypted - test if the BO is encrypted +* @bo: pointer to a buffer object +* +* Return true if the buffer object is encrypted, false otherwise. +*/ +static inline bool amdgpu_bo_encrypted (struct amdgpu_bo *bo) +{ +return bo->flags &AMDGPU_GEM_CREATE_ENCRYPTED ; +} +bool amdgpu_bo_is_amdgpu_bo (struct ttm_buffer_object *bo);void amdgpu_bo_placement_from_domain (struct amdgpu_bo *abo,u32 domain);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_bo_update(struct amdgpu_device *adev, · line 1695
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0@@ -1688,6 +1688,11 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,if (bo) { flags =amdgpu_ttm_tt_pte_flags (adev, bo->tbo.ttm, mem); + +if (amdgpu_bo_encrypted (bo)) { + flags |=AMDGPU_PTE_TMZ ; + } +You can drop the {} here, apart from that the patch is Reviewed-by:
Christian König <[email protected]>.
Quoted 3 lines
From the design it would be indeed nicer to have that in
amdgpu_ttm_tt_pte_flags(), but we would need to make sure that this is not called any more from binding a tt.
Don't we need that for things like evictions of tmz buffers? That needs special handling in general, which I guess we can address at that time.
Alex
Quoted 4 lines
Regards,
Christian.
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_bo_update(struct amdgpu_device *adev, · line 1698
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0bo_adev =amdgpu_ttm_adev (bo->tbo.bdev); }else { flags =0x0 ;_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH v2 11/11] drm/amdgpu: set TMZ bits in PTEs for secure BO (v4)
Am 25.09.19 um 18:01 schrieb Alex Deucher:
Quoted 101 lines
Quoted 99 lines · Christian
Am 25.09.19 um 15:45 schrieb Huang, Ray:
Quoted 87 lines
From: Alex Deucher <[email protected]>
If a buffer object is secure, i.e. created with
AMDGPU_GEM_CREATE_ENCRYPTED, then the TMZ bit of
the PTEs that belong the buffer object should be
set.v1: design and draft the skeletion of TMZ bits setting on PTEs (Alex)
v2: return failure once create secure BO on non-TMZ platform (Ray)
v3:amdgpu_bo_encrypted()only checks the BO (Luben)
v4: move TMZ flag setting intoamdgpu_vm_bo_update(Christian)Signed-off-by Alex Deucher <[email protected]>Reviewed-by Huang Rui <[email protected]>Signed-off-by Huang Rui <[email protected]>Signed-off-by Luben Tuikov <[email protected]>Reviewed-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 12 +++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 11 +++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 +++++ 3 files changed, 27 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +11
-1@@ -222,7 +222,8 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,AMDGPU_GEM_CREATE_CPU_GTT_USWC |AMDGPU_GEM_CREATE_VRAM_CLEARED |AMDGPU_GEM_CREATE_VM_ALWAYS_VALID | - AMDGPU_GEM_CREATE_EXPLICIT_SYNC)) +AMDGPU_GEM_CREATE_EXPLICIT_SYNC | + AMDGPU_GEM_CREATE_ENCRYPTED)) return -EINVAL;@@ -230,6 +231,11 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,if (args->in.domains & ~AMDGPU_GEM_DOMAIN_MASK )return -EINVAL ; +if (!adev->tmz.enabled && (flags &AMDGPU_GEM_CREATE_ENCRYPTED )) { +DRM_ERROR ("Cannot allocate secure buffer while tmz is disabled\n" ); +return -EINVAL ; + } +/* create a gem object to contain this object in */ if (args->in.domains & (AMDGPU_GEM_DOMAIN_GDS |AMDGPU_GEM_DOMAIN_GWS |AMDGPU_GEM_DOMAIN_OA )) {@@ -251,6 +257,10 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, resv = vm->root.base.bo->tbo.resv; } +if (flags &AMDGPU_GEM_CREATE_ENCRYPTED ) { +/* XXX: pad out alignment to meet TMZ requirements */ + } + r =amdgpu_gem_object_create (adev, size, args->in.alignment, (u32)(0xffffffff & args->in.domains), flags, ttm_bo_type_device, resv, &gobj);drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +11
-0@@ -224,6 +224,17 @@ static inline bool amdgpu_bo_explicit_sync(struct amdgpu_bo *bo)return bo->flags &AMDGPU_GEM_CREATE_EXPLICIT_SYNC ; } +/** +* amdgpu_bo_encrypted - test if the BO is encrypted +* @bo: pointer to a buffer object +* +* Return true if the buffer object is encrypted, false otherwise. +*/ +static inline bool amdgpu_bo_encrypted (struct amdgpu_bo *bo) +{ +return bo->flags &AMDGPU_GEM_CREATE_ENCRYPTED ; +} +bool amdgpu_bo_is_amdgpu_bo (struct ttm_buffer_object *bo);void amdgpu_bo_placement_from_domain (struct amdgpu_bo *abo,u32 domain);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_bo_update(struct amdgpu_device *adev, · line 1695
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0@@ -1688,6 +1688,11 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,if (bo) { flags =amdgpu_ttm_tt_pte_flags (adev, bo->tbo.ttm, mem); + +if (amdgpu_bo_encrypted (bo)) { + flags |=AMDGPU_PTE_TMZ ; + } +You can drop the {} here, apart from that the patch is Reviewed-by:
Christian König <[email protected]>.
Quoted 6 lines
Quoted 3 lines
From the design it would be indeed nicer to have that in
amdgpu_ttm_tt_pte_flags(), but we would need to make sure that this is not called any more from binding a tt.Don't we need that for things like evictions of tmz buffers? That needs special handling in general, which I guess we can address at that time.
Yeah, exactly. The problem is that we sometimes doesn't use bo->mem, but rather a separate memory descriptor to get the PTE infos.
I think we could remove the call in amdgpu_ttm_backend_bind() where this is relevant, because we now manage GART separately.
But that's a larger change and probably not something for this patch set.
Going to put it on my TODO list.
Christian.
Quoted 9 lines
Alex
Quoted 6 lines
Regards,
Christian.Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0bo_adev =amdgpu_ttm_adev (bo->tbo.bdev); }else { flags =0x0 ;
Quoted 8 lines
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel