drm/amdgpu: introduce secure buffer object support (trusted memory zone)
Subsystems (4)
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 AMDGPU_CTX_ALLOC_FLAGS_SECURE to indicate the context 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 context interface 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 command submission under secure context status: ENABLED'
Thanks,
Ray
Alex Deucher (4):
drm/amdgpu: add UAPI for creating encrypted buffers drm/amdgpu: add UAPI for creating secure contexts (v2) drm/amdgpu: define the TMZ bit for the PTE drm/amdgpu: set TMZ bits in PTEs for secure bo (v2)
Huang Rui (10):
drm/amdgpu: add tmz feature parameter (v2)
drm/amdgpu: add amdgpu_tmz data structure
drm/amdgpu: add function to check tmz capability (v4) drm/ttm: add helper to get buffer object with ttm_mem_reg drm/amdgpu: revise the function to allocate secure context (v2) 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: set trusted mode while the job is under secure context
(v2)
drm/amdgpu: modify the method to use mem under buffer object for
amdgpu_ttm_tt_pte_flags
drivers/gpu/drm/amd/amdgpu/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 7 ++++- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 19 +++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 1 + 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 | 10 ++++++ 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_ttm.c | 23 +++++++++----- 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/drm/ttm/ttm_bo_driver.h | 13 ++++++++ include/uapi/drm/amdgpu_drm.h | 9 +++++- 25 files changed, 230 insertions(+), 34 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): 1568202584-14471-1-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org
PATCH 1/14 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 3/14 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 4/14 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 5/14 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 6/14 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 8/14 drm/amdgpu: revise the function to allocate secure context (v2)
In reply to a message not in the archiveThe is_secure flag will indicate the current conext is protected or not.
v2: while user mode asks to create a context, but if tmz is disabled, it should return failure.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 19 +++++++++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 1 + 2 files changed, 16 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +15 -4
@@ -72,7 +72,8 @@ static int amdgpu_ctx_priority_permit(struct drm_file *filp,static int amdgpu_ctx_init (struct amdgpu_device *adev,enum drm_sched_priority priority,struct drm_file *filp, -struct amdgpu_ctx *ctx) +struct amdgpu_ctx *ctx, +uint32_t flags) {unsigned num_entities =amdgpu_ctx_total_num_entities ();unsigned i, j, k;
@@ -121,6 +122,9 @@ static int amdgpu_ctx_init(struct amdgpu_device *adev, ctx->init_priority = priority; ctx->override_priority =DRM_SCHED_PRIORITY_UNSET ; +if (flags &AMDGPU_CTX_ALLOC_FLAGS_SECURE ) + ctx->is_secure = true; +for (i =0 ; i <AMDGPU_HW_IP_NUM ; ++i) {struct amdgpu_ring *rings[AMDGPU_MAX_RINGS ];struct drm_sched_rq *rqs[AMDGPU_MAX_RINGS ];
@@ -253,7 +257,7 @@ static int amdgpu_ctx_alloc(struct amdgpu_device *adev,struct amdgpu_fpriv *fpriv, struct drm_file *filp, enum drm_sched_priority priority, - uint32_t *id) + uint32_t *id, uint32_t flags) { struct amdgpu_ctx_mgr *mgr = &fpriv->ctx_mgr;struct amdgpu_ctx *ctx;
@@ -272,7 +276,7 @@ static int amdgpu_ctx_alloc(struct amdgpu_device *adev, } *id = (uint32_t )r; - r =amdgpu_ctx_init (adev, priority, filp, ctx); + r =amdgpu_ctx_init (adev, priority, filp, ctx, flags);if (r) {idr_remove (&mgr->ctx_handles, *id); *id =0 ;
@@ -407,6 +411,12 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,struct amdgpu_device *adev = dev->dev_private;struct amdgpu_fpriv *fpriv = filp->driver_priv; +if (!adev->tmz.enabled && + (args->in.flags &AMDGPU_CTX_ALLOC_FLAGS_SECURE )) { +DRM_ERROR ("Cannot allocate secure context while tmz is disabled\n" ); +return -EINVAL ; + } + r =0 ; id = args->in.ctx_id; priority =amdgpu_to_sched_priority (args->in.priority);
@@ -418,7 +428,8 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,switch (args->in.op) {case AMDGPU_CTX_OP_ALLOC_CTX : - r =amdgpu_ctx_alloc (adev, fpriv, filp, priority, &id); + r =amdgpu_ctx_alloc (adev, fpriv, filp, priority, + &id, args->in.flags); args->out.alloc.ctx_id = id;break ;case AMDGPU_CTX_OP_FREE_CTX :
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +1 -0
@@ -45,6 +45,7 @@ struct amdgpu_ctx {struct dma_fence **fences;struct amdgpu_ctx_entity *entities[AMDGPU_HW_IP_NUM ];bool preamble_presented; +bool is_secure;enum drm_sched_priority init_priority;enum drm_sched_priority override_priority;struct mutex lock;
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 10/14 drm/amdgpu: expand the emit tmz interface with trusted flag
In reply to a message not in the archiveThis 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 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 11/14 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 12/14 drm/amdgpu: set trusted mode while the job is under secure context (v2)
In reply to a message not in the archiveWhile user mode submit a command with secure context, we should set the command buffer with trusted mode.
v2: fix the null job pointer while in vmid 0 submission.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -0
@@ -1252,6 +1252,7 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p, p->ctx->preamble_presented = true; } + job->secure = p->ctx->is_secure; cs->out.handle = seq; job->uf_sequence = seq;
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 under secure context */ +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
PATCH 2/14 drm/amdgpu: add UAPI for creating secure contexts (v2)
In reply to Huang, RayFrom: Alex Deucher <[email protected]>
Add a flag for when allocating a context to flag it as secure. The kernel driver will use this flag to determine whether a rendering context is secure or not so that the engine can be transitioned between secure or unsecure or the work can be submitted to a secure queue depending on the IP.
v2: the flag will be used for security, so remove the comment (Ray)
--- include/uapi/drm/amdgpu_drm.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/uapi/drm/amdgpu_drm.h +3 -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 context as secure */ +#define AMDGPU_CTX_ALLOC_FLAGS_SECURE (1 << 0) +/* GPU reset status */ #define AMDGPU_CTX_NO_RESET 0/* this the context caused it */
@@ -241,7 +244,6 @@ union drm_amdgpu_bo_list {struct drm_amdgpu_ctx_in {/** AMDGPU_CTX_OP_* */ __u32 op; -/** For future use, no flags defined so far */ __u32 flags;__u32 ctx_id;/** AMDGPU_CTX_PRIORITY_* */
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 7/14 drm/ttm: add helper to get buffer object with ttm_mem_reg
In reply to Huang, RayThis patch is to add a helper to get corresponding buffer object with a pointer to a struct ttm_mem_reg.
--- include/drm/ttm/ttm_bo_driver.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/drm/ttm/ttm_bo_driver.h +13 -0
@@ -786,6 +786,19 @@ static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)reservation_object_unlock (bo->resv); } +/** +* ttm_mem_reg_to_bo +* +* @mem: A pointer to a struct ttm_mem_reg. +* +* Returns corresponding buffer object of the @mem. +*/ +static inline +struct ttm_buffer_object *ttm_mem_reg_to_bo (struct ttm_mem_reg *mem) +{ + return container_of(mem, struct ttm_buffer_object, mem); +} +/* * ttm_bo_util.c */
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 9/14 drm/amdgpu: add tmz bit in frame control packet
In reply to Huang, RayThis 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 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 13/14 drm/amdgpu: modify the method to use mem under buffer object for amdgpu_ttm_tt_pte_flags
In reply to Huang, Rayamdgpu_ttm_tt_pte_flags will be used for updating tmz bits while the bo is secure, so we need pass the ttm_mem_reg under a buffer object.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +10 -8
@@ -1117,8 +1117,8 @@ int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo) }else {/* allocate GART space */ - tmp = bo->mem; - tmp.mm_node =NULL ; + tmp = bo->mem;/* cache bo->mem */ + bo->mem.mm_node =NULL ; placement.num_placement =1 ; placement.placement = &placements; placement.num_busy_placement =1 ;
@@ -1128,23 +1128,25 @@ int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo) placements.flags = (bo->mem.placement & ~TTM_PL_MASK_MEM ) |TTM_PL_FLAG_TT ; - r =ttm_bo_mem_space (bo, &placement, &tmp, &ctx); -if (unlikely (r)) + r =ttm_bo_mem_space (bo, &placement, &bo->mem, &ctx); +if (unlikely (r)) { + bo->mem = tmp;return r; + }/* compute PTE flags for this buffer object */ - flags =amdgpu_ttm_tt_pte_flags (adev, bo->ttm, &tmp); + flags =amdgpu_ttm_tt_pte_flags (adev, bo->ttm, &bo->mem);/* Bind pages */ - gtt->offset = (u64 )tmp.start <<PAGE_SHIFT ; + gtt->offset = (u64 )bo->mem.start <<PAGE_SHIFT ; r =amdgpu_ttm_gart_bind (adev, bo, flags);if (unlikely (r)) { + bo->mem = tmp;ttm_bo_mem_put (bo, &tmp);return r; } -ttm_bo_mem_put (bo, &bo->mem); - bo->mem = tmp; +ttm_bo_mem_put (bo, &tmp); } bo->offset = (bo->mem.start << PAGE_SHIFT) +
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 14/14 drm/amdgpu: set TMZ bits in PTEs for secure bo (v2)
In reply to Huang, RayFrom: Alex Deucher <[email protected]>
If one bo is secure (created with AMDGPU_GEM_CREATE_ENCRYPTED), the TMZ bits of PTEs that belongs that bo should be set. Then psp is able to protect the pages of this bo to avoid the access from an "untrust" domain such as CPU.
v1: design and draft the skeletion of tmz bits setting on PTEs (Alex)
v2: return failure once create secure bo on no-tmz platform (Ray)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 12 +++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 10 ++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 5 +++++ 3 files changed, 26 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 +10 -0
@@ -224,6 +224,16 @@ static inline bool amdgpu_bo_explicit_sync(struct amdgpu_bo *bo)return bo->flags &AMDGPU_GEM_CREATE_EXPLICIT_SYNC ; } +/** +* amdgpu_bo_encrypted - return whether the bo is encrypted +*/ +static inline bool amdgpu_bo_encrypted (struct amdgpu_bo *bo) +{ +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); + +return adev->tmz.enabled && (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_ttm.c +5 -0
@@ -1434,6 +1434,8 @@ bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm)uint64_t amdgpu_ttm_tt_pde_flags (struct ttm_tt *ttm,struct ttm_mem_reg *mem) {uint64_t flags =0 ; +struct ttm_buffer_object *tbo =ttm_mem_reg_to_bo (mem); +struct amdgpu_bo *abo =ttm_to_amdgpu_bo (tbo);if (mem && mem->mem_type !=TTM_PL_SYSTEM ) flags |=AMDGPU_PTE_VALID ;
@@ -1444,6 +1446,9 @@ uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct ttm_mem_reg *mem)if (ttm->caching_state == tt_cached) flags |=AMDGPU_PTE_SNOOPED ; } +if (amdgpu_bo_encrypted (abo)) { + flags |=AMDGPU_PTE_TMZ ; + }return flags; }
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): 1568202584-14471-15-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 14/14] drm/amdgpu: set TMZ bits in PTEs for secure bo (v2)
Am 11.09.19 um 13:50 schrieb Huang, Ray:
Quoted 61 lines
From: Alex Deucher <[email protected]>
If one bo is secure (created with
AMDGPU_GEM_CREATE_ENCRYPTED), the TMZ bits of PTEs that belongs that bo should be set. Then psp is able to protect the pages of this bo to avoid the access from an "untrust" domain such as CPU.v1: design and draft the skeletion of tmz bits setting on PTEs (Alex)
v2: return failure once create secure bo on no-tmz platform (Ray)Signed-off-by Alex Deucher <[email protected]>Reviewed-by Huang Rui <[email protected]>Signed-off-by Huang Rui <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 12 +++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 10 ++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 5 +++++ 3 files changed, 26 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 +0
-0@@ -224,6 +224,16 @@ static inline bool amdgpu_bo_explicit_sync(struct amdgpu_bo *bo)return bo->flags &AMDGPU_GEM_CREATE_EXPLICIT_SYNC ;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h static inline bool amdgpu_bo_explicit_sync(struct amdgpu_bo *bo) · line 234
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +8
-0} +/** +* amdgpu_bo_encrypted - return whether the bo is encrypted +*/ +static inline bool amdgpu_bo_encrypted (struct amdgpu_bo *bo) +{ +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); + +return adev->tmz.enabled && (bo->flags &AMDGPU_GEM_CREATE_ENCRYPTED );
Checking the adev->tmz.enabled flags should be dropped here.
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +2
-0+} +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_ttm.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm) · line 1438
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2
-0@@ -1434,6 +1434,8 @@ bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm)uint64_t amdgpu_ttm_tt_pde_flags (struct ttm_tt *ttm,struct ttm_mem_reg *mem) {uint64_t flags =0 ; +struct ttm_buffer_object *tbo =ttm_mem_reg_to_bo (mem); +struct amdgpu_bo *abo =ttm_to_amdgpu_bo (tbo);
That's a clear NAK. The function is not necessarily called with &bo->mem, which is also the reason why this function doesn't gets the BO as parameter.
Christian.
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct ttm_mem_reg *mem) · line 1454
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3
-0if (mem && mem->mem_type !=TTM_PL_SYSTEM ) flags |=AMDGPU_PTE_VALID ;@@ -1444,6 +1446,9 @@ uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct ttm_mem_reg *mem)if (ttm->caching_state == tt_cached) flags |=AMDGPU_PTE_SNOOPED ; } +if (amdgpu_bo_encrypted (abo)) { + flags |=AMDGPU_PTE_TMZ ; + }return flags; }
_______________________________________________
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): 5704cdc8-754e-538e-9547-738ef81efa7c-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 14/14] drm/amdgpu: set TMZ bits in PTEs for secure bo (v2)
Quoted 64 lines · Christian
Am 11.09.19 um 13:50 schrieb Huang, Ray:
Quoted 63 lines
From: Alex Deucher <[email protected]>
If one bo is secure (created with
AMDGPU_GEM_CREATE_ENCRYPTED), the TMZ bits of PTEs that belongs that bo should be set. Then psp is able to protect the pages of this bo to avoid the access from an "untrust" domain such as CPU.v1: design and draft the skeletion of tmz bits setting on PTEs (Alex)
v2: return failure once create secure bo on no-tmz platform (Ray)Signed-off-by Alex Deucher <[email protected]>Reviewed-by Huang Rui <[email protected]>Signed-off-by Huang Rui <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 12 +++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 10 ++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 5 +++++ 3 files changed, 26 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 +0
-0@@ -224,6 +224,16 @@ static inline bool amdgpu_bo_explicit_sync(struct amdgpu_bo *bo)return bo->flags &AMDGPU_GEM_CREATE_EXPLICIT_SYNC ; }
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h static inline bool amdgpu_bo_explicit_sync(struct amdgpu_bo *bo) · line 234
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +8
-0+/** +* amdgpu_bo_encrypted - return whether the bo is encrypted +*/ +static inline bool amdgpu_bo_encrypted (struct amdgpu_bo *bo) +{ +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); + +return adev->tmz.enabled && (bo->flags &AMDGPU_GEM_CREATE_ENCRYPTED );Checking the
adev->tmz.enabledflags should be dropped here.
That's fine. BO should be validated while it is created.
But if the BO is created by vmid 0, is this checking needed?
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +2
-0+} +bool amdgpu_bo_is_amdgpu_bo (struct ttm_buffer_object *bo);void amdgpu_bo_placement_from_domain (struct amdgpu_bo *abo,u32 domain);
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm) · line 1438
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2
-0@@ -1434,6 +1434,8 @@ bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm)uint64_t amdgpu_ttm_tt_pde_flags (struct ttm_tt *ttm,struct ttm_mem_reg *mem) {uint64_t flags =0 ; +struct ttm_buffer_object *tbo =ttm_mem_reg_to_bo (mem); +struct amdgpu_bo *abo =ttm_to_amdgpu_bo (tbo);That's a clear NAK. The function is not necessarily called with
&bo->mem, which is also the reason why this function doesn't gets the BO as parameter.
Do you mean we can revise the below functions to use bo as the parameter instead?
uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct amdgpu_bo *bo) uint64_t amdgpu_ttm_tt_pte_flags(struct ttm_tt *ttm, struct amdgpu_bo *bo)
Thanks,
Ray
Quoted 13 lines
Christian.
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3
-0if (mem && mem->mem_type !=TTM_PL_SYSTEM ) flags |=AMDGPU_PTE_VALID ;@@ -1444,6 +1446,9 @@ uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct ttm_mem_reg *mem)if (ttm->caching_state == tt_cached) flags |=AMDGPU_PTE_SNOOPED ; } +if (amdgpu_bo_encrypted (abo)) { + flags |=AMDGPU_PTE_TMZ ; + }
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct ttm_mem_reg *mem) · line 1454
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0return flags; }
_______________________________________________
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): MN2PR12MB3309544896408F62494EC8B3ECB00-rweVpJHSKTpWdvXm18W95QdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org
Re: [PATCH 14/14] drm/amdgpu: set TMZ bits in PTEs for secure bo (v2)
Am 12.09.19 um 12:27 schrieb Huang, Ray:
Quoted 98 lines · Christian
Quoted 64 lines
Am 11.09.19 um 13:50 schrieb Huang, Ray:
Quoted 63 lines
From: Alex Deucher <[email protected]>
If one bo is secure (created with
AMDGPU_GEM_CREATE_ENCRYPTED), the TMZ bits of PTEs that belongs that bo should be set. Then psp is able to protect the pages of this bo to avoid the access from an "untrust" domain such as CPU.v1: design and draft the skeletion of tmz bits setting on PTEs (Alex)
v2: return failure once create secure bo on no-tmz platform (Ray)Signed-off-by Alex Deucher <[email protected]>Reviewed-by Huang Rui <[email protected]>Signed-off-by Huang Rui <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 12 +++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 10 ++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 5 +++++ 3 files changed, 26 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 +0
-0@@ -224,6 +224,16 @@ static inline bool amdgpu_bo_explicit_sync(struct amdgpu_bo *bo)return bo->flags &AMDGPU_GEM_CREATE_EXPLICIT_SYNC ; }Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h static inline bool amdgpu_bo_explicit_sync(struct amdgpu_bo *bo) · line 234
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +8
-0+/** +* amdgpu_bo_encrypted - return whether the bo is encrypted +*/ +static inline bool amdgpu_bo_encrypted (struct amdgpu_bo *bo) +{ +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); + +return adev->tmz.enabled && (bo->flags &AMDGPU_GEM_CREATE_ENCRYPTED );Checking the
adev->tmz.enabledflags should be dropped here.That's fine. BO should be validated while it is created.
But if the BO is created by vmid 0, is this checking needed?
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +2
-0+} +bool amdgpu_bo_is_amdgpu_bo (struct ttm_buffer_object *bo);void amdgpu_bo_placement_from_domain (struct amdgpu_bo *abo,u32 domain);Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm) · line 1438
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2
-0@@ -1434,6 +1434,8 @@ bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm)uint64_t amdgpu_ttm_tt_pde_flags (struct ttm_tt *ttm,struct ttm_mem_reg *mem) {uint64_t flags =0 ; +struct ttm_buffer_object *tbo =ttm_mem_reg_to_bo (mem); +struct amdgpu_bo *abo =ttm_to_amdgpu_bo (tbo);That's a clear NAK. The function is not necessarily called with
&bo->mem, which is also the reason why this function doesn't gets the BO as parameter.
Quoted 5 lines
Do you mean we can revise the below functions to use bo as the parameter instead?
uint64_tamdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct amdgpu_bo *bo)uint64_tamdgpu_ttm_tt_pte_flags(struct ttm_tt *ttm, struct amdgpu_bo *bo)
If that is possible then this would indeed be a solution for the problem.
Christian.
Quoted 17 lines
Thanks,
RayQuoted 13 lines
Christian.
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3
-0if (mem && mem->mem_type !=TTM_PL_SYSTEM ) flags |=AMDGPU_PTE_VALID ;@@ -1444,6 +1446,9 @@ uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct ttm_mem_reg *mem)if (ttm->caching_state == tt_cached) flags |=AMDGPU_PTE_SNOOPED ; } +if (amdgpu_bo_encrypted (abo)) { + flags |=AMDGPU_PTE_TMZ ; + }
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct ttm_mem_reg *mem) · line 1454
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0return flags; }
_______________________________________________
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): 26355f8a-d16b-e406-8cfc-b30742419121-5C7GfCeVMHo@public.gmane.org
RE: [PATCH 14/14] drm/amdgpu: set TMZ bits in PTEs for secure bo (v2)
Quoted 126 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, September 12, 2019 7:49 PM
To: Huang, Ray <[email protected]>
Cc: [email protected]; [email protected]; Deucher, Alexander <[email protected]>; Tuikov, Luben <[email protected]>; Liu, Aaron <[email protected]>
Subject: Re: [PATCH 14/14] drm/amdgpu: set TMZ bits in PTEs for secure bo (v2)Am 12.09.19 um 12:27 schrieb Huang, Ray:
Quoted 5 lines · Christian
Quoted 4 lines
Am 11.09.19 um 13:50 schrieb Huang, Ray:
Quoted 3 lines
From: Alex Deucher <[email protected]>
If one bo is secure (created with
AMDGPU_GEM_CREATE_ENCRYPTED),the
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
TMZ bits of PTEs that belongs that bo should be set. Then psp is able to protect the pages of this bo to avoid the access from an "untrust"
domain such as CPU.
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
v1: design and draft the skeletion of tmz bits setting on PTEs (Alex)
v2: return failure once create secure bo on no-tmz platform (Ray)Signed-off-by Alex Deucher <[email protected]>Reviewed-by Huang Rui <[email protected]>Signed-off-by Huang Rui <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 12 +++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 10 ++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 5 +++++ 3 files changed, 26 insertions(+), 1 deletion(-)Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct drm_device
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0@@ -222,7 +222,8 @@ int amdgpu_gem_create_ioctl(struct drm_device*dev, void *data,
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-1AMDGPU_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,Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct · line 234
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-0if (args->in.domains & ~AMDGPU_GEM_DOMAIN_MASK )return -EINVAL ; + if (!adev->tmz.enabled && (flags &
AMDGPU_GEM_CREATE_ENCRYPTED)) {Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct · line 235
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-0+ DRM_ERROR("Cannot allocate secure buffer while tmz isdisabled\n");
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct · line 241
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3
-0+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
Quoted 1 line
Quoted 1 line
Quoted 1 line
+257,10 @@ int amdgpu_gem_create_ioctl(struct
drm_device*dev,void *data,
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
Quoted 10 lines
resv = vm->root.base.bo->tbo.resv; }drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +4
-0+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);diff --git
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h static inline bool
Quoted 6 lines
a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.hb/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index 5a3c177..286e2e2 100644drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0
-0@@ -224,6 +224,16 @@ static inline bool
amdgpu_bo_explicit_sync(struct amdgpu_bo *bo)Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h static inline bool · line 233
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +7
-0return bo->flags &AMDGPU_GEM_CREATE_EXPLICIT_SYNC ; } +/** +* amdgpu_bo_encrypted - return whether the bo is encrypted */ +static inline bool amdgpu_bo_encrypted (struct amdgpu_bo *bo) { +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); + +return adev->tmz.enabled && (bo->flags & +AMDGPU_GEM_CREATE_ENCRYPTED );Checking the
adev->tmz.enabledflags should be dropped here.Quoted 8 lines
That's fine. BO should be validated while it is created.
But if the BO is created by vmid 0, is this checking needed?
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h static inline bool · line 237
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +2
-0+} +bool amdgpu_bo_is_amdgpu_bo (struct ttm_buffer_object *bo); void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo,u32
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c bool amdgpu_ttm_tt_is_readonly(struct
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0
-0domain);drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0@@ -1434,6 +1434,8 @@ bool amdgpu_ttm_tt_is_readonly(struct
ttm_tt*ttm)Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c bool amdgpu_ttm_tt_is_readonly(struct · line 1434
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct
ttm_mem_reg*mem)Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c bool amdgpu_ttm_tt_is_readonly(struct · line 1438
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2
-0{uint64_t flags =0 ; +struct ttm_buffer_object *tbo =ttm_mem_reg_to_bo (mem); +struct amdgpu_bo *abo =ttm_to_amdgpu_bo (tbo);That's a clear NAK. The function is not necessarily called with
&bo->mem, which is also the reason why this function doesn't gets the BO as parameter.
Quoted 9 lines
Quoted 6 lines
Do you mean we can revise the below functions to use bo as the parameter instead?
uint64_tamdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct amdgpu_bo *bo)uint64_tamdgpu_ttm_tt_pte_flags(struct ttm_tt *ttm, struct amdgpu_bo *bo)If that is possible then this would indeed be a solution for the problem.
Sorry to late response, I was revising the unit test for secure memory few days ago.
Most of cases can be updated to amdgpu_ttm_tt_pte_flags with amdgpu_bo as the parameter except one case in amdgpu_ttm_backend_bind(). It will be called by ttm_tt_bind() under amdgpu_move_vram_ram(). But ttm_mem_reg is new assigned.
How about using modify the bind callback in ttm_backend_func:
int (*bind) (struct ttm_buffer_object *bo, struct ttm_mem_reg *bo_mem);
Then we can update the following functions as:
uint64_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_buffer_object *tbo, struct ttm_mem_reg *mem); uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_buffer_object *tbo, struct ttm_mem_reg *mem);
It looks better than before.
Thanks,
Ray
Quoted 20 lines
Christian.
Quoted 10 lines
Thanks,
RayQuoted 6 lines
Christian.
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c uint64_t amdgpu_ttm_tt_pde_flags(struct
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0if (mem && mem->mem_type !=TTM_PL_SYSTEM ) flags |=AMDGPU_PTE_VALID ;@@ -1444,6 +1446,9 @@ uint64_t amdgpu_ttm_tt_pde_flags(struct
ttm_tt*ttm, structttm_mem_reg*mem)Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3
-0if (ttm->caching_state == tt_cached) flags |=AMDGPU_PTE_SNOOPED ; } +if (amdgpu_bo_encrypted (abo)) { + flags |=AMDGPU_PTE_TMZ ; + }
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c uint64_t amdgpu_ttm_tt_pde_flags(struct · line 1454
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0return flags; }
_______________________________________________
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): MN2PR12MB33099517C5365BD6274A1491EC840-rweVpJHSKTpWdvXm18W95QdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org
Re: [PATCH 14/14] drm/amdgpu: set TMZ bits in PTEs for secure bo (v2)
Am 24.09.19 um 13:48 schrieb Huang, Ray:
Quoted 133 lines
Quoted 125 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, September 12, 2019 7:49 PM
To: Huang, Ray <[email protected]>
Cc: [email protected]; [email protected]; Deucher, Alexander <[email protected]>; Tuikov, Luben <[email protected]>; Liu, Aaron <[email protected]>
Subject: Re: [PATCH 14/14] drm/amdgpu: set TMZ bits in PTEs for secure bo (v2)Am 12.09.19 um 12:27 schrieb Huang, Ray:
Quoted 5 lines · Christian
Quoted 4 lines
Am 11.09.19 um 13:50 schrieb Huang, Ray:
Quoted 3 lines
From: Alex Deucher <[email protected]>
If one bo is secure (created with
AMDGPU_GEM_CREATE_ENCRYPTED),the
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
TMZ bits of PTEs that belongs that bo should be set. Then psp is able to protect the pages of this bo to avoid the access from an "untrust"
domain such as CPU.
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
v1: design and draft the skeletion of tmz bits setting on PTEs (Alex)
v2: return failure once create secure bo on no-tmz platform (Ray)Signed-off-by Alex Deucher <[email protected]>Reviewed-by Huang Rui <[email protected]>Signed-off-by Huang Rui <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 12 +++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 10 ++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 5 +++++ 3 files changed, 26 insertions(+), 1 deletion(-)Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct drm_device
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0@@ -222,7 +222,8 @@ int amdgpu_gem_create_ioctl(struct drm_device*dev, void *data,
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-1AMDGPU_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,Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct · line 234
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-0if (args->in.domains & ~AMDGPU_GEM_DOMAIN_MASK )return -EINVAL ; + if (!adev->tmz.enabled && (flags &
AMDGPU_GEM_CREATE_ENCRYPTED)) {Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct · line 235
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-0+ DRM_ERROR("Cannot allocate secure buffer while tmz isdisabled\n");
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct · line 241
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3
-0+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
Quoted 1 line
Quoted 1 line
Quoted 1 line
+257,10 @@ int amdgpu_gem_create_ioctl(struct
drm_device*dev,void *data,
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
Quoted 10 lines
resv = vm->root.base.bo->tbo.resv; }drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +4
-0+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);diff --git
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h static inline bool
Quoted 6 lines
a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.hb/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index 5a3c177..286e2e2 100644drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0
-0@@ -224,6 +224,16 @@ static inline bool
amdgpu_bo_explicit_sync(struct amdgpu_bo *bo)Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h static inline bool · line 233
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +7
-0return bo->flags &AMDGPU_GEM_CREATE_EXPLICIT_SYNC ; } +/** +* amdgpu_bo_encrypted - return whether the bo is encrypted */ +static inline bool amdgpu_bo_encrypted (struct amdgpu_bo *bo) { +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); + +return adev->tmz.enabled && (bo->flags & +AMDGPU_GEM_CREATE_ENCRYPTED );Checking the
adev->tmz.enabledflags should be dropped here.Quoted 8 lines
That's fine. BO should be validated while it is created.
But if the BO is created by vmid 0, is this checking needed?
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h static inline bool · line 237
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +2
-0+} +bool amdgpu_bo_is_amdgpu_bo (struct ttm_buffer_object *bo); void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo,u32
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c bool amdgpu_ttm_tt_is_readonly(struct
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +0
-0domain);drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0@@ -1434,6 +1434,8 @@ bool amdgpu_ttm_tt_is_readonly(struct
ttm_tt*ttm)Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c bool amdgpu_ttm_tt_is_readonly(struct · line 1434
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct
ttm_mem_reg*mem)Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c bool amdgpu_ttm_tt_is_readonly(struct · line 1438
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2
-0{uint64_t flags =0 ; +struct ttm_buffer_object *tbo =ttm_mem_reg_to_bo (mem); +struct amdgpu_bo *abo =ttm_to_amdgpu_bo (tbo);That's a clear NAK. The function is not necessarily called with
&bo->mem, which is also the reason why this function doesn't gets the BO as parameter.Quoted 8 lines
Quoted 6 lines
Do you mean we can revise the below functions to use bo as the parameter instead?
uint64_tamdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct amdgpu_bo *bo)uint64_tamdgpu_ttm_tt_pte_flags(struct ttm_tt *ttm, struct amdgpu_bo *bo)If that is possible then this would indeed be a solution for the problem.
Quoted 8 lines
Sorry to late response, I was revising the unit test for secure memory few days ago.
Most of cases can be updated to
amdgpu_ttm_tt_pte_flagswithamdgpu_boas the parameter except one case inamdgpu_ttm_backend_bind(). It will be called byttm_tt_bind()underamdgpu_move_vram_ram(). Butttm_mem_regis new assigned.How about using modify the bind callback in
ttm_backend_func:int (*bind) (struct
ttm_buffer_object*bo, structttm_mem_reg*bo_mem);
That won't work correctly.
Binding and unbinding the ttm_mem_reg from the GART is separate to the BO. E.g. the BO can long be destroyed or it could be a ghost BO.
Quoted 7 lines
Then we can update the following functions as:
uint64_tamdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_buffer_object *tbo, struct ttm_mem_reg *mem);uint64_tamdgpu_ttm_tt_pde_flags(struct ttm_buffer_object *tbo, struct ttm_mem_reg *mem);It looks better than before.
The whole approach of adding the TMZ flag to amdgpu_ttm_tt_pte_flags() is completely broken by design. Rather add adding the flag to amdgpu_vm_bo_update() instead.
Regards,
Christian.
Quoted 22 lines
Thanks,
RayQuoted 18 lines
Christian.
Quoted 8 lines
Thanks,
RayQuoted 5 lines
Christian.
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c uint64_t amdgpu_ttm_tt_pde_flags(struct
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0if (mem && mem->mem_type !=TTM_PL_SYSTEM ) flags |=AMDGPU_PTE_VALID ;@@ -1444,6 +1446,9 @@ uint64_t amdgpu_ttm_tt_pde_flags(struct
ttm_tt*ttm, structttm_mem_reg*mem)Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3
-0if (ttm->caching_state == tt_cached) flags |=AMDGPU_PTE_SNOOPED ; } +if (amdgpu_bo_encrypted (abo)) { + flags |=AMDGPU_PTE_TMZ ; + }
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c uint64_t amdgpu_ttm_tt_pde_flags(struct · line 1454
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0return flags; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Koenig, Christian
maintainerPatches #1-#4, #8, #9 are Reviewed-by: Christian König <[email protected]>
Patches #10, #11 are Acked-by: Christian König <[email protected]>
Patches #7 and the resulting workaround in patch #13 are a clear NAK. The ttm_mem_reg can't be used like this to get back to the ttm_bo object.
Going to reply separately on patch #14 regarding this.
Regards,
Christian.
Am 11.09.19 um 13:50 schrieb Huang, Ray:
Quoted 72 lines
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_ENCRYPTEDto gem create ioctl to libdrm for the secure buffer allocation. And also provide theAMDGPU_CTX_ALLOC_FLAGS_SECUREto indicate the context 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 context interface 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 command submission under secure context status: ENABLED'Thanks,
RayAlex Deucher (4):
drm/amdgpu: add UAPI for creating encrypted buffers drm/amdgpu: add UAPI for creating secure contexts (v2) drm/amdgpu: define the TMZ bit for the PTE drm/amdgpu: set TMZ bits in PTEs for secure bo (v2)Huang Rui (10):
drm/amdgpu: add tmz feature parameter (v2)
drm/amdgpu: addamdgpu_tmzdata structure
drm/amdgpu: add function to check tmz capability (v4) drm/ttm: add helper to get buffer object withttm_mem_regdrm/amdgpu: revise the function to allocate secure context (v2) 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: set trusted mode while the job is under secure context(v2)drm/amdgpu: modify the method to use mem under buffer object for
amdgpu_ttm_tt_pte_flagsdrivers/gpu/drm/amd/amdgpu/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 7 ++++- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 19 +++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 1 + 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 | 10 ++++++ 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_ttm.c | 23 +++++++++----- 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/drm/ttm/ttm_bo_driver.h | 13 ++++++++ include/uapi/drm/amdgpu_drm.h | 9 +++++- 25 files changed, 230 insertions(+), 34 deletions(-)
Quoted 3 lines
create mode 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.ccreate mode 100644drivers/gpu/drm/amd/amdgpu/amdgpu_tmz.h
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel