Checksum Region with new CRTC properties
Subsystems (4)
v2 cover Checksum Region with new CRTC properties
Dear DRM development community,
We'd like to introduce the implementation of the new crtc properties.
First of all, please let me introduce the problem we try to address. With the popularity of electric vehicles, the car vendors have increasing requirement for ensuring the integrity of the critical content on the display. For example, tell-tales are icons to indicate malfunction or operation on a car system. For safty concern, car vendors always want to make sure these icons are not tampered and can be correctly displayed on the instrument cluster.
To address this problem, since modern display control hardware is able to calculate the CRC checksum of the display content, we are thinking of a feature to let userspace specify a region on display, and we can utilize the hardware to calculate the CRC checksum as frames scanned out, and finally, provide the checksum for userspace for validation purpose. In this case, since the icons themselves are often fixed over static backgrounds, the CRC of the pixels in the region can be known in advance. So one of the usage of the region and corresponding CRC result is that as users know the CRC checksum of the tell-tales in advance, at runtime they can retrieve the CRC value from kernel for validation as frames are scanned out.
We implement this feature and call it checksum region. To let userspace set a region and retrieve the corresponding CRC value, we provide 2 new properties, CHECKSUM_REGION and CHECKSUM_CRC. Both of them are blob properties under CRTC, and the detailed struct of the two properties are listed below. One for userspace to set the region to kernel, and the other for userspace to retrieve CRC values from kernel. Upon userspace submitting the 4 coordinate values with checksum_region_enable true, kernel instructs DC hardware to calculate the CRC value accordingly as frames scanned out. The result CRC value of RGB colors are then stored in CHECKSUM_CRC property, with a reference frame count for userspace to know which frame the CRCs are calculated at.
/**
* struct drm_checksum_region - The enablement and region of checksum_region
* @x_start: Horizontal starting coordinate of the region.
* @y_start: Vertical starting coordinate of the region.
* @x_end: Horizontal ending coordinate of the region.
* @y_end: Vertical ending coordinate of the region.
* @checksum_region_enable: To enable or disable checksum_region. *
* Userspace uses this structure to configure the region and enablement for
* checksum_region. Userspace should not submit a region out of the displayable
* region because there is nothing to display and need protection. */
struct drm_checksum_region {
__u32 x_start;
__u32 y_start;
__u32 x_end;
__u32 y_end;
__u8 checksum_region_enable;
__u8 pad[7];
};/**
* struct drm_checksum_crc - The CRC value of the corresponding checksum region.
* @crc_r: CRC value of red color.
* @crc_g: CRC value of green color.
* @crc_b: CRC value of blue color.
* @frame_count: a referenced frame count to indicate which frame the CRC values
* are generated at.
*
* Userspace uses this structure to retrieve the CRC values of the current
* checksum region. @frame_count will be reset once a new region is updated or
* it reaches a maximum value. Currently these CRC values are designed to
* be validated with pre-saved CRC values, so userspace doesn't need to concern
* about the algorithm used to compute the CRC.
*/
struct drm_checksum_crc {
__u32 crc_r;
__u32 crc_g;
__u32 crc_b;
__u32 frame_count;
};To better introduce the usage of this feature, we also have a paired Weston application as an reference app to use secure display via the properties. Please check the Weston application and see how the application set the region and validate the content from the CRC here: https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/1236
This application can draw patterns on the display, and allow users to set the region and submit it to kernel via properties. With kernel keeping calculating the CRC, this example application takes the first CRC as source CRC, and keeps retrieving the new CRCs at each frame later. By comparing source CRC with the following CRC value, the application can validate if the display content got changed down the road.
Finally, let me briefly introduce the patches. There are 3 patches in this patch series. The first patch is the main patch that contains change to drm, including the new CRTC properties, the property creation function and a update_checksum_region_crc() CRTC callback.
1. drm: Introduce CRTC checksum region and CRC properties
The remaining 2 patches are only related to the processing of region and CRC data in our driver, also listed here for your reference.
2. drm/amd/display: Create checksum_region properties and handle new region update
3. drm/amd/display: Implement the retrieval of checksum_region's CRC data
Thanks for the reading and hope to get your feedback soon!
v2:
- Change the name of secure display to checksum region.
- Move the new properties, their creation function and their state to drm layer.
- Improve comments on the new properties's usage and limitation.
- Add a new CRTC callback update_checksum_region_crc() for updating the CRC checksum to the crc blob.
- Squash patches from 7 to 3.
Alan Liu (3):
drm: Introduce CRTC checksum region and CRC properties drm/amd/display: Create checksum_region properties and handle new
region update
drm/amd/display: Implement the retrieval of checksum_region's CRC data
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 44 +++++++ .../drm/amd/display/amdgpu_dm/amdgpu_dm_crc.c | 112 ++++++++++++++++-- .../drm/amd/display/amdgpu_dm/amdgpu_dm_crc.h | 14 +++ .../amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 52 ++++++++ drivers/gpu/drm/drm_atomic_state_helper.c | 7 ++ drivers/gpu/drm/drm_atomic_uapi.c | 21 +++- drivers/gpu/drm/drm_crtc.c | 44 +++++++ include/drm/drm_crtc.h | 43 +++++++ include/uapi/drm/drm_mode.h | 42 +++++++ 9 files changed, 368 insertions(+), 11 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/3 drm: Introduce CRTC checksum region and CRC properties
Introduce per-CRTC properties: CHECKSUM_REGION and CHECKSUM_CRC. Userspace can configure a region by setting the region property and retrieve the CRC values from the CRC property to validate the content of the region.
Apon userspace submits the 4 coordinate values with checksum_region_enable true, kernel instructs DC hardware to calculate the CRC value accordingly as frames scanned out. The result CRC value of RGB colors are then stored in CHECKSUM_CRC property, with a reference frame count for userspace to know which frame the CRCs are calculated at.
Driver can set up these properties for a CRTC by calling drm_crtc_create_checksum_region_properties() and hook its own implementation on new CRTC function update_chechsum_region_crc() to update the values of the CRC property for the incoming userspace request.
--- drivers/gpu/drm/drm_atomic_state_helper.c | 7 ++++ drivers/gpu/drm/drm_atomic_uapi.c | 21 ++++++++++- drivers/gpu/drm/drm_crtc.c | 44 +++++++++++++++++++++++ include/drm/drm_crtc.h | 43 ++++++++++++++++++++++ include/uapi/drm/drm_mode.h | 42 ++++++++++++++++++++++ 5 files changed, 156 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic_state_helper.c +7 -0
@@ -143,6 +143,11 @@ void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc,drm_property_blob_get (state->ctm);if (state->gamma_lut)drm_property_blob_get (state->gamma_lut); +if (state->checksum_region.region_blob) +drm_property_blob_get (state->checksum_region.region_blob); +if (state->checksum_region.crc_blob) +drm_property_blob_get (state->checksum_region.crc_blob); + state->mode_changed = false; state->active_changed = false; state->planes_changed = false;
@@ -215,6 +220,8 @@ void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state)drm_property_blob_put (state->degamma_lut);drm_property_blob_put (state->ctm);drm_property_blob_put (state->gamma_lut); +drm_property_blob_put (state->checksum_region.region_blob); +drm_property_blob_put (state->checksum_region.crc_blob); }EXPORT_SYMBOL (__drm_atomic_helper_crtc_destroy_state);
drivers/gpu/drm/drm_atomic_uapi.c +20 -1
@@ -450,6 +450,17 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc,set_out_fence_for_crtc (state->state, crtc, fence_ptr); }else if (property == crtc->scaling_filter_property) { state->scaling_filter = val; + }else if (property == crtc->checksum_region_property) { + ret =drm_atomic_replace_property_blob_from_id (dev, + &state->checksum_region.region_blob, + val, +-1 ,sizeof (struct drm_checksum_region ), + &replaced); + state->checksum_region.region_changed |= replaced; +return ret; + }else if (property == crtc->checksum_crc_property) { +/* don't let user set CRC data */ +return -EPERM ; }else if (crtc->funcs->atomic_set_property) {return crtc->funcs->atomic_set_property (crtc, state, property, val); }else {
@@ -487,7 +498,15 @@ drm_atomic_crtc_get_property(struct drm_crtc *crtc, *val =0 ; else if (property == crtc->scaling_filter_property) *val = state->scaling_filter; - else if (crtc->funcs->atomic_get_property) + else if (property == crtc->checksum_region_property) + *val = (state->checksum_region.region_blob) + ? state->checksum_region.region_blob->base.id :0 ; + else if (property == crtc->checksum_crc_property) { +if (crtc->funcs->update_checksum_region_crc) + crtc->funcs->update_checksum_region_crc (crtc); + *val = (state->checksum_region.crc_blob) + ? state->checksum_region.crc_blob->base.id :0 ; + } else if (crtc->funcs->atomic_get_property) return crtc->funcs->atomic_get_property(crtc, state, property, val); else return -EINVAL;
drivers/gpu/drm/drm_crtc.c +44 -0
47 lines not on this page · raw message
include/drm/drm_crtc.h +43 -0
65 lines not on this page · raw message
include/uapi/drm/drm_mode.h +42 -0
48 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 2/3 drm/amd/display: Create checksum_region properties and handle new region update
In reply to Alan LiuThis commit creates checksum_region properties at CRTC initialization, and update the new region during the atomic atomic. A new function amdgpu_dm_crtc_set_secure_display_crc_source() is implemented to control the state of CRC engine of DC hardware.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 38 +++++++++++++ .../drm/amd/display/amdgpu_dm/amdgpu_dm_crc.c | 57 +++++++++++++++++++ .../drm/amd/display/amdgpu_dm/amdgpu_dm_crc.h | 3 + .../amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 5 ++ 4 files changed, 103 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +38 -0
@@ -8870,6 +8870,44 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state) } }#endif + +#ifdef CONFIG_DRM_AMD_SECURE_DISPLAY +if (new_crtc_state->active && new_crtc_state->checksum_region.region_changed) { +struct drm_checksum_region *region_data = + (struct drm_checksum_region *)new_crtc_state->checksum_region.region_blob->data; + +if (region_data->checksum_region_enable) { +if (!amdgpu_dm_crc_window_is_activated (crtc)) { +/* Enable secure display: set crc source to "crtc" */ +amdgpu_dm_crtc_set_secure_display_crc_source (crtc,"crtc" ); + +/* wait 1 more frame for CRC engine to start */ + acrtc->dm_irq_params.window_param.skip_frame_cnt =1 ; + +spin_lock_irqsave (&adev_to_drm (adev)->event_lock, flags); + acrtc->dm_irq_params.window_param.activated = true; +spin_unlock_irqrestore (&adev_to_drm (adev)->event_lock, flags); + } + +/* Update ROI: copy ROI from crtc_state to dm_irq_params */ +spin_lock_irqsave (&adev_to_drm (adev)->event_lock, flags); + acrtc->dm_irq_params.window_param.x_start = region_data->x_start; + acrtc->dm_irq_params.window_param.y_start = region_data->y_start; + acrtc->dm_irq_params.window_param.x_end = region_data->x_end; + acrtc->dm_irq_params.window_param.y_end = region_data->y_end; + acrtc->dm_irq_params.window_param.update_win = true; +spin_unlock_irqrestore (&adev_to_drm (adev)->event_lock, flags); + + }else { +if (amdgpu_dm_crc_window_is_activated (crtc)) { +/* Disable secure display: set crc source to "none" */ +amdgpu_dm_crtc_set_secure_display_crc_source (crtc,"none" ); + } + } + + new_crtc_state->checksum_region.region_changed = false; + } +#endif }for_each_new_crtc_in_state (state, crtc, new_crtc_state, j)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crc.c +57 -0
63 lines not on this page · raw message
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crc.h +3 -0
@@ -97,10 +97,13 @@ bool amdgpu_dm_crc_window_is_activated(struct drm_crtc *crtc);void amdgpu_dm_crtc_handle_crc_window_irq (struct drm_crtc *crtc);struct secure_display_context *amdgpu_dm_crtc_secure_display_create_contexts (struct amdgpu_device *adev); +int amdgpu_dm_crtc_set_secure_display_crc_source (struct drm_crtc *crtc, +const char *src_name);#else #define amdgpu_dm_crc_window_is_activated (x)#define amdgpu_dm_crtc_handle_crc_window_irq (x)#define amdgpu_dm_crtc_secure_display_create_contexts (x) +#define amdgpu_dm_crtc_set_secure_display_crc_source (x)#endif #endif /* AMD_DAL_DEV_AMDGPU_DM_AMDGPU_DM_CRC_H_ */
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +5 -0
@@ -461,6 +461,11 @@ int amdgpu_dm_crtc_init(struct amdgpu_display_manager *dm, dm->adev->mode_info.crtcs[crtc_index] = acrtc; +#ifdef CONFIG_DRM_AMD_SECURE_DISPLAY +if (drm_crtc_create_checksum_region_properties (&acrtc->base)) +DRM_ERROR ("amdgpu: failed to create checksum region properties.\n" ); +#endif +/* Don't enable DRM CRTC degamma property for DCE since it doesn't * support programmable degamma anywhere. */
Signature · 1 line
2.34.1
PATCH v2 3/3 drm/amd/display: Implement the retrieval of checksum_region's CRC data
In reply to Alan LiuRetrieve and store checksum_region's CRC data from the DC hardware in vline0 irq handler. A new function amdgpu_dm_crtc_update_checksum_region_crc() is implemented and hooked to CRTC callback for updating the latest CRC values to the checksum CRC blob.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 8 ++- .../drm/amd/display/amdgpu_dm/amdgpu_dm_crc.c | 55 +++++++++++++++---- .../drm/amd/display/amdgpu_dm/amdgpu_dm_crc.h | 11 ++++ .../amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 47 ++++++++++++++++ 4 files changed, 110 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +7 -1
@@ -8877,7 +8877,12 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state) (struct drm_checksum_region *)new_crtc_state->checksum_region.region_blob->data;if (region_data->checksum_region_enable) { +struct secure_display_context *secure_display_ctx = + &dm->secure_display_ctxs[acrtc->crtc_id]; +if (!amdgpu_dm_crc_window_is_activated (crtc)) { +init_completion (&secure_display_ctx->crc.completion); +/* Enable secure display: set crc source to "crtc" */ amdgpu_dm_crtc_set_secure_display_crc_source (crtc,"crtc" );
@@ -8887,7 +8892,8 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state)spin_lock_irqsave (&adev_to_drm (adev)->event_lock, flags); acrtc->dm_irq_params.window_param.activated = true;spin_unlock_irqrestore (&adev_to_drm (adev)->event_lock, flags); - } + }else +reinit_completion (&secure_display_ctx->crc.completion);/* Update ROI: copy ROI from crtc_state to dm_irq_params */ spin_lock_irqsave (&adev_to_drm (adev)->event_lock, flags);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crc.c +45 -10
94 lines not on this page · raw message
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crc.h +11 -0
@@ -40,6 +40,15 @@ enum amdgpu_dm_pipe_crc_source { }; #ifdef CONFIG_DRM_AMD_SECURE_DISPLAY +struct crc_data { + uint32_t crc_R; + uint32_t crc_G; + uint32_t crc_B; + uint32_t frame_count; + spinlock_t lock; + struct completion completion; +}; + struct crc_window_param { uint16_t x_start; uint16_t y_start;
@@ -64,6 +73,8 @@ struct secure_display_context {/* Region of Interest (ROI) */ struct rect rect; + + struct crc_data crc; };#endif
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +47 -0
59 lines not on this page · raw message
Signature · 1 line
2.34.1
[AMD Official Use Only - General]
Dear DRM development community,
I also developed an IGT for testing this checksum_region feature. Please check it at: https://patchwork.freedesktop.org/series/120017/
Thank you and welcome any feedback.
Best Regards,
Alan
-----Original Message-----
From: Alan Liu <[email protected]>
Sent: Sunday, June 18, 2023 6:39 PM
To: [email protected]
Cc: Wentland, Harry <[email protected]>; Gong, Lili (Sophia) <[email protected]>; Lin, Wayne <[email protected]>; Liu, HaoPing (Alan) <[email protected]>; Liu, HaoPing (Alan) <[email protected]>
Subject: [PATCH v2 0/3] Checksum Region with new CRTC properties
Dear DRM development community,
We'd like to introduce the implementation of the new crtc properties.
First of all, please let me introduce the problem we try to address. With the popularity of electric vehicles, the car vendors have increasing requirement for ensuring the integrity of the critical content on the display. For example, tell-tales are icons to indicate malfunction or operation on a car system. For safty concern, car vendors always want to make sure these icons are not tampered and can be correctly displayed on the instrument cluster.
To address this problem, since modern display control hardware is able to calculate the CRC checksum of the display content, we are thinking of a feature to let userspace specify a region on display, and we can utilize the hardware to calculate the CRC checksum as frames scanned out, and finally, provide the checksum for userspace for validation purpose. In this case, since the icons themselves are often fixed over static backgrounds, the CRC of the pixels in the region can be known in advance. So one of the usage of the region and corresponding CRC result is that as users know the CRC checksum of the tell-tales in advance, at runtime they can retrieve the CRC value from kernel for validation as frames are scanned out.
We implement this feature and call it checksum region. To let userspace set a region and retrieve the corresponding CRC value, we provide 2 new properties, CHECKSUM_REGION and CHECKSUM_CRC. Both of them are blob properties under CRTC, and the detailed struct of the two properties are listed below. One for userspace to set the region to kernel, and the other for userspace to retrieve CRC values from kernel. Upon userspace submitting the 4 coordinate values with checksum_region_enable true, kernel instructs DC hardware to calculate the CRC value accordingly as frames scanned out. The result CRC value of RGB colors are then stored in CHECKSUM_CRC property, with a reference frame count for userspace to know which frame the CRCs are calculated at.
/**
* struct drm_checksum_region - The enablement and region of checksum_region
* @x_start: Horizontal starting coordinate of the region.
* @y_start: Vertical starting coordinate of the region.
* @x_end: Horizontal ending coordinate of the region.
* @y_end: Vertical ending coordinate of the region.
* @checksum_region_enable: To enable or disable checksum_region. *
* Userspace uses this structure to configure the region and enablement for
* checksum_region. Userspace should not submit a region out of the displayable
* region because there is nothing to display and need protection. */
struct drm_checksum_region {
__u32 x_start;
__u32 y_start;
__u32 x_end;
__u32 y_end;
__u8 checksum_region_enable;
__u8 pad[7];
};/**
* struct drm_checksum_crc - The CRC value of the corresponding checksum region.
* @crc_r: CRC value of red color.
* @crc_g: CRC value of green color.
* @crc_b: CRC value of blue color.
* @frame_count: a referenced frame count to indicate which frame the CRC values
* are generated at.
*
* Userspace uses this structure to retrieve the CRC values of the current
* checksum region. @frame_count will be reset once a new region is updated or
* it reaches a maximum value. Currently these CRC values are designed to
* be validated with pre-saved CRC values, so userspace doesn't need to concern
* about the algorithm used to compute the CRC.
*/
struct drm_checksum_crc {
__u32 crc_r;
__u32 crc_g;
__u32 crc_b;
__u32 frame_count;
};To better introduce the usage of this feature, we also have a paired Weston application as an reference app to use secure display via the properties. Please check the Weston application and see how the application set the region and validate the content from the CRC here: https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/1236
This application can draw patterns on the display, and allow users to set the region and submit it to kernel via properties. With kernel keeping calculating the CRC, this example application takes the first CRC as source CRC, and keeps retrieving the new CRCs at each frame later. By comparing source CRC with the following CRC value, the application can validate if the display content got changed down the road.
Finally, let me briefly introduce the patches. There are 3 patches in this patch series. The first patch is the main patch that contains change to drm, including the new CRTC properties, the property creation function and a update_checksum_region_crc() CRTC callback.
1. drm: Introduce CRTC checksum region and CRC properties
The remaining 2 patches are only related to the processing of region and CRC data in our driver, also listed here for your reference.
2. drm/amd/display: Create checksum_region properties and handle new region update
3. drm/amd/display: Implement the retrieval of checksum_region's CRC data
Thanks for the reading and hope to get your feedback soon!
v2:
- Change the name of secure display to checksum region.
- Move the new properties, their creation function and their state to drm layer.
- Improve comments on the new properties's usage and limitation.
- Add a new CRTC callback update_checksum_region_crc() for updating the CRC checksum to the crc blob.
- Squash patches from 7 to 3.
Alan Liu (3):
drm: Introduce CRTC checksum region and CRC properties drm/amd/display: Create checksum_region properties and handle new
region update
drm/amd/display: Implement the retrieval of checksum_region's CRC data
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 44 +++++++ .../drm/amd/display/amdgpu_dm/amdgpu_dm_crc.c | 112 ++++++++++++++++-- .../drm/amd/display/amdgpu_dm/amdgpu_dm_crc.h | 14 +++ .../amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 52 ++++++++ drivers/gpu/drm/drm_atomic_state_helper.c | 7 ++ drivers/gpu/drm/drm_atomic_uapi.c | 21 +++- drivers/gpu/drm/drm_crtc.c | 44 +++++++ include/drm/drm_crtc.h | 43 +++++++ include/uapi/drm/drm_mode.h | 42 +++++++ 9 files changed, 368 insertions(+), 11 deletions(-)
--
2.34.1