Several GuC related patches
Subsystems (3)
cover Several GuC related patches
From: Alex Dai <[email protected]>
The first two had been submitted to upstream. They are collected here as a summry of latest GuC changes.
drm/i915/guc: Fix a bug in GuC status check
drm/i915/guc: Add GuC css header parser
The others are fixes for RC6 or suspend/resume problems when GuC submission is enabled. And last, enable GuC command submission.
Alex Dai (4):
drm/i915/guc: Fix a bug in GuC status check drm/i915/guc: Add GuC css header parser
drm/i915/guc: Add host2guc notification for suspend and resume drm/i915/guc: Media domain bit needed when notify GuC rc6 state
Sagar Arun Kamble (1):
drm/i915/guc: Don't send flips to GuC
Dave Gordon (1):
drm/i915/guc: Enable GuC submission, where supported
Documentation/DocBook/drm.tmpl | 24 +++++- drivers/gpu/drm/i915/i915_drv.c | 1 + drivers/gpu/drm/i915/i915_gem.c | 1 + drivers/gpu/drm/i915/i915_guc_reg.h | 1 + drivers/gpu/drm/i915/i915_guc_submission.c | 53 +++++++++++- drivers/gpu/drm/i915/i915_params.c | 4 +- drivers/gpu/drm/i915/intel_guc.h | 4 +- drivers/gpu/drm/i915/intel_guc_fwif.h | 44 ++++++++++ drivers/gpu/drm/i915/intel_guc_loader.c | 124 +++++++++++++++++++---------- 9 files changed, 208 insertions(+), 48 deletions(-)
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 1/6 drm/i915/guc: Fix a bug in GuC status check
From: Alex Dai <[email protected]>
Bit 16 of GuC status indicates resuming from RC6. The LAPIC_DONE status is a reliable readiness flag only when resuming from RC6. This fix a racing issue that allocation of doorbell fails whilst GuC init is not finished.
--- drivers/gpu/drm/i915/i915_guc_reg.h | 1 + drivers/gpu/drm/i915/intel_guc_loader.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_guc_reg.h +1 -0
@@ -37,6 +37,7 @@#define GS_UKERNEL_READY (0xF0 << GS_UKERNEL_SHIFT)#define GS_MIA_SHIFT 16#define GS_MIA_MASK (0x07 << GS_MIA_SHIFT) +#define GS_MIA_CORE_STATE (1 << GS_MIA_SHIFT)#define SOFT_SCRATCH (n) (0xc180 + ((n) * 4))
drivers/gpu/drm/i915/intel_guc_loader.c +3 -2
@@ -209,9 +209,10 @@ static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, u32 *status) {u32 val =I915_READ (GUC_STATUS ); +u32 uk_val = val &GS_UKERNEL_MASK ; *status = val; -return ((val &GS_UKERNEL_MASK ) ==GS_UKERNEL_READY || - (val &GS_UKERNEL_MASK ) ==GS_UKERNEL_LAPIC_DONE ); +return (uk_val ==GS_UKERNEL_READY || + ((val &GS_MIA_CORE_STATE ) && uk_val ==GS_UKERNEL_LAPIC_DONE )); }/*
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/6 drm/i915/guc: Add GuC css header parser
In reply to [email protected]From: Alex Dai <[email protected]>
By using information from GuC css header, we can eliminate some hard code w.r.t size of some components of firmware.
v1: 1) guc_css_header is defined as __packed now
2) Add and correct GuC related topics in kernel/Doc
--- Documentation/DocBook/drm.tmpl | 24 +++++++- drivers/gpu/drm/i915/intel_guc.h | 2 +- drivers/gpu/drm/i915/intel_guc_fwif.h | 36 +++++++++++ drivers/gpu/drm/i915/intel_guc_loader.c | 105 +++++++++++++++++++++----------- 4 files changed, 130 insertions(+), 37 deletions(-)
Documentation/DocBook/drm.tmpl +22 -2
@@ -4155,14 +4155,34 @@ int num_ioctls;</synopsis> <title>GuC-based Command Submission</title> <sect2> <title>GuC</title> -!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC-specific firmware loader +!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC !Idrivers/gpu/drm/i915/intel_guc_loader.c </sect2> <sect2> <title>GuC Client</title> -!Pdrivers/gpu/drm/i915/i915_guc_submission.c GuC-based command submissison +!Pdrivers/gpu/drm/i915/i915_guc_submission.c GuC Client !Idrivers/gpu/drm/i915/i915_guc_submission.c </sect2> + <sect2> + <title>GuC Firmware Layout</title> + <para>The GuC firmware layout looks like this:</para> +<programlisting><![CDATA[ + +-------------------------------+ + | guc_css_header | + | contains major/minor version | + +-------------------------------+ + | uCode | + +-------------------------------+ + | RSA signature | + +-------------------------------+ + | modulus key | + +-------------------------------+ + | exponent val | + +-------------------------------+ +]]></programlisting> +!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC Firmware Layout +!Idrivers/gpu/drm/i915/intel_guc_loader.c + </sect2> </sect1> <sect1>
drivers/gpu/drm/i915/intel_guc.h +1 -1
@@ -71,6 +71,7 @@ struct intel_guc_fw {struct drm_i915_gem_object * guc_fw_obj;enum intel_guc_fw_status guc_fw_fetch_status;enum intel_guc_fw_status guc_fw_load_status; +struct guc_css_header guc_fw_header;uint16_t guc_fw_major_wanted;uint16_t guc_fw_minor_wanted;
@@ -80,7 +81,6 @@ struct intel_guc_fw {struct intel_guc {struct intel_guc_fw guc_fw; -uint32_t log_flags;struct drm_i915_gem_object *log_obj;
drivers/gpu/drm/i915/intel_guc_fwif.h +36 -0
@@ -122,6 +122,42 @@#define GUC_CTL_MAX_DWORDS (GUC_CTL_RSRVD + 1) +struct guc_css_header { +uint32_t module_type; +uint32_t header_len;/* header length plus size of all other keys */ +uint32_t header_version; +uint32_t module_id; +uint32_t module_vendor; +union { +struct { +uint8_t day; +uint8_t month; +uint16_t year; + }; +uint32_t date; + }; +uint32_t size;/* uCode size plus header_len */ +uint32_t key_size; +uint32_t modulus_size; +uint32_t exponent_size; +union { +struct { +uint8_t hour; +uint8_t min; +uint16_t sec; + }; +uint32_t time; + }; + +char username[8 ]; +char buildnumber[12 ]; +uint32_t device_id; +uint32_t guc_sw_version; +uint32_t prod_preprod_fw; +uint32_t reserved[12 ]; +uint32_t header_info; +} __packed; +struct guc_doorbell_info {u32 db_status;u32 cookie;
drivers/gpu/drm/i915/intel_guc_loader.c +71 -34
150 lines not on this page · raw message
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 2/6] drm/i915/guc: Add GuC css header parser
Quoted 41 lines · On Thu, Sep 10, 2015 at 04:56:08PM -0700, [email protected] wrote:
From: Alex Dai <[email protected]>
By using information from GuC css header, we can eliminate some hard code w.r.t size of some components of firmware.
v1: 1)
guc_css_headeris defined as__packednow
2) Add and correct GuC related topics in kernel/DocSigned-off-by Alex Dai <[email protected]>--- Documentation/DocBook/drm.tmpl | 24 +++++++- drivers/gpu/drm/i915/intel_guc.h | 2 +- drivers/gpu/drm/i915/intel_guc_fwif.h | 36 +++++++++++ drivers/gpu/drm/i915/intel_guc_loader.c | 105 +++++++++++++++++++++----------- 4 files changed, 130 insertions(+), 37 deletions(-)Documentation/DocBook/drm.tmpl +9
-2@@ -4155,14 +4155,34 @@ int num_ioctls;</synopsis> <title>GuC-based Command Submission</title> <sect2> <title>GuC</title> -!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC-specific firmware loader +!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC !Idrivers/gpu/drm/i915/intel_guc_loader.c </sect2> <sect2> <title>GuC Client</title> -!Pdrivers/gpu/drm/i915/i915_guc_submission.c GuC-based command submissison +!Pdrivers/gpu/drm/i915/i915_guc_submission.c GuC Client !Idrivers/gpu/drm/i915/i915_guc_submission.c </sect2> + <sect2> + <title>GuC Firmware Layout</title> + <para>The GuC firmware layout looks like this:</para> +<programlisting><![CDATA[ + +-------------------------------+ + | guc_css_header | + | contains major/minor version |
Documentation/DocBook/drm.tmpl int num_ioctls;</synopsis> · line 4182
Quoted 10 lines
Documentation/DocBook/drm.tmpl +10
-0+ +-------------------------------+ + | uCode | + +-------------------------------+ + | RSA signature | + +-------------------------------+ + | modulus key | + +-------------------------------+ + | exponent val | + +-------------------------------+ +]]></programlisting>
Nope, this can be done as DOC: sections directly with latest -nightly.
DOC: sections now support markdown, so you only have do indent it either 4 spaces (for fixed-with layout) or drop the lines in between for table layout (iirc, you might want to check that).
Needs pandoc installed though, otherwise you can't see the new pretty. But if you have pandoc just run
$ make htmldocs
and double-check that it all looks good.
Thanks, Daniel
Quoted 239 lines
Documentation/DocBook/drm.tmpl +3
-0+!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC Firmware Layout +!Idrivers/gpu/drm/i915/intel_guc_loader.c + </sect2> </sect1> <sect1>drivers/gpu/drm/i915/intel_guc.h +1
-1@@ -71,6 +71,7 @@ struct intel_guc_fw {struct drm_i915_gem_object * guc_fw_obj;enum intel_guc_fw_status guc_fw_fetch_status;enum intel_guc_fw_status guc_fw_load_status; +struct guc_css_header guc_fw_header;uint16_t guc_fw_major_wanted;uint16_t guc_fw_minor_wanted;@@ -80,7 +81,6 @@ struct intel_guc_fw {struct intel_guc {struct intel_guc_fw guc_fw; -uint32_t log_flags;struct drm_i915_gem_object *log_obj;drivers/gpu/drm/i915/intel_guc_fwif.h +36
-0@@ -122,6 +122,42 @@#define GUC_CTL_MAX_DWORDS (GUC_CTL_RSRVD + 1) +struct guc_css_header { +uint32_t module_type; +uint32_t header_len;/* header length plus size of all other keys */ +uint32_t header_version; +uint32_t module_id; +uint32_t module_vendor; +union { +struct { +uint8_t day; +uint8_t month; +uint16_t year; + }; +uint32_t date; + }; +uint32_t size;/* uCode size plus header_len */ +uint32_t key_size; +uint32_t modulus_size; +uint32_t exponent_size; +union { +struct { +uint8_t hour; +uint8_t min; +uint16_t sec; + }; +uint32_t time; + }; + +char username[8 ]; +char buildnumber[12 ]; +uint32_t device_id; +uint32_t guc_sw_version; +uint32_t prod_preprod_fw; +uint32_t reserved[12 ]; +uint32_t header_info; +} __packed; +struct guc_doorbell_info {u32 db_status;u32 cookie;drivers/gpu/drm/i915/intel_guc_loader.c +71
-34@@ -215,18 +215,27 @@ static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, ((val & GS_MIA_CORE_STATE) && uk_val == GS_UKERNEL_LAPIC_DONE)); } -/* -* Transfer the firmware image to RAM for execution by the microcontroller. +/** +* DOC: GuC Firmware Layout * -* GuC Firmware layout: -* +-------------------------------+ ---- -* | CSS header | 128B -* | contains major/minor version | -* +-------------------------------+ ---- -* | uCode | -* +-------------------------------+ ---- -* | RSA signature | 256B -* +-------------------------------+ ---- ++-------------------------------+ +| guc_css_header | +| contains major/minor version | ++-------------------------------+ +| uCode | ++-------------------------------+ +| RSA signature | ++-------------------------------+ +| modulus key | ++-------------------------------+ +| exponent val | ++-------------------------------+ +* +* The firmware may or may not have modulus key and exponent data. The header, +* uCode and RSA signature are must-have components that will be used by driver. +* Size of each components (in dwords) can be found in header. In the case that +* modulus and exponent are not present in fw, the size value still appears in +* header. * * Architecturally, the DMA engine is bidirectional, and can potentially even * transfer between GTT locations. This functionality is left out of the API @@ -236,30 +245,42 @@ static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,* DMA engine in one operation, whereas the RSA signature is loaded via MMIO. */ -#define UOS_CSS_HEADER_OFFSET 0 -#define UOS_VER_MINOR_OFFSET 0x44 -#define UOS_VER_MAJOR_OFFSET 0x46 -#define UOS_CSS_HEADER_SIZE 0x80 -#define UOS_RSA_SIG_SIZE 0x100 - +/* +* Transfer the firmware image to RAM for execution by the microcontroller. +*/ static int guc_ucode_xfer_dma (struct drm_i915_private *dev_priv) {struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw; +struct guc_css_header *header = &guc_fw->guc_fw_header;struct drm_i915_gem_object *fw_obj = guc_fw->guc_fw_obj;unsigned long offset;struct sg_table *sg = fw_obj->pages; -u32 status, ucode_size, rsa[UOS_RSA_SIG_SIZE /sizeof (u32)]; +u32 status, header_size, rsa_size, ucode_size, *rsa;int i, ret =0 ; -/* uCode size, also is where RSA signature starts */ - offset = ucode_size = guc_fw->guc_fw_size -UOS_RSA_SIG_SIZE ; -I915_WRITE (DMA_COPY_SIZE , ucode_size); +/* The header plus uCode will be copied to WOPCM via DMA, excluding any +* other components */ + header_size = (header->header_len - header->key_size - + header->modulus_size - header->exponent_size) *sizeof (u32); + ucode_size = (header->size - header->header_len) *sizeof (u32); + +I915_WRITE (DMA_COPY_SIZE , header_size + ucode_size); + +/* where RSA signature starts */ + offset = header_size + ucode_size; + + rsa_size = header->key_size *sizeof (u32); + rsa =kmalloc (rsa_size,GFP_KERNEL ); +if (!rsa) +return -ENOMEM ;/* Copy RSA signature from the fw image to HW for verification */ -sg_pcopy_to_buffer (sg->sgl, sg->nents, rsa,UOS_RSA_SIG_SIZE , offset); -for (i =0 ; i <UOS_RSA_SIG_SIZE /sizeof (u32); i++) +sg_pcopy_to_buffer (sg->sgl, sg->nents, rsa, rsa_size, offset); +for (i =0 ; i < rsa_size /sizeof (u32); i++)I915_WRITE (UOS_RSA_SCRATCH_0 + i *sizeof (u32), rsa[i]); +kfree (rsa); +/* Set the source address for the new blob */ offset =i915_gem_obj_ggtt_offset (fw_obj);I915_WRITE (DMA_ADDR_0_LOW ,lower_32_bits (offset));@@ -458,10 +479,8 @@ static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw) {struct drm_i915_gem_object *obj;const struct firmware *fw; -const u8 *css_header; -const size_t minsize =UOS_CSS_HEADER_SIZE +UOS_RSA_SIG_SIZE ; -const size_t maxsize =GUC_WOPCM_SIZE_VALUE +UOS_RSA_SIG_SIZE - -0x8000 ;/* 32k reserved (8K stack + 24k context) */ +struct guc_css_header *css_header = &guc_fw->guc_fw_header; +size_t size;int err; DRM_DEBUG_DRIVER("before requesting firmware: GuC fw fetch status %s\n",@@ -475,12 +494,31 @@ static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)DRM_DEBUG_DRIVER ("fetch GuC fw from %s succeeded, fw %p\n" , guc_fw->guc_fw_path, fw); -DRM_DEBUG_DRIVER ("firmware file size %zu (minimum %zu, maximum %zu)\n" , - fw->size, minsize, maxsize); -/* Check the size of the blob befoe examining buffer contents */ -if (fw->size < minsize || fw->size > maxsize) +/* Check the size of the blob before examining buffer contents */ +if (fw->size <sizeof (struct guc_css_header )) { +DRM_ERROR ("Firmware header is missing\n" ); + goto fail; + } + +memcpy (css_header, fw->data,sizeof (struct guc_css_header )); + +/* At least, it should have header, uCode and RSA. Size of all three. */ + size = (css_header->size - css_header->modulus_size - + css_header->exponent_size) *sizeof (u32); +if (fw->size < size) { +DRM_ERROR ("Missing firmware components\n" ); goto fail; + } + +/* Header and uCode will be loaded to WOPCM. Size of the two. */ + size -= css_header->key_size *sizeof (u32); + +/* Top 32k of WOPCM is reserved (8K stack + 24k RC6 context). */ +if (size >GUC_WOPCM_SIZE_VALUE -0x8000 ) { +DRM_ERROR ("Firmware is too large to fit in WOPCM\n" ); + goto fail; + }/* * The GuC firmware image has the version number embedded at a well-known @@ -488,9 +526,8 @@ static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)* TWO bytes each (i.e. u16), although all pointers and offsets are defined * in terms of bytes (u8). */ - css_header = fw->data +UOS_CSS_HEADER_OFFSET ; - guc_fw->guc_fw_major_found = *(u16 *)(css_header +UOS_VER_MAJOR_OFFSET ); - guc_fw->guc_fw_minor_found = *(u16 *)(css_header +UOS_VER_MINOR_OFFSET ); + guc_fw->guc_fw_major_found = css_header->guc_sw_version >>16 ; + guc_fw->guc_fw_minor_found = css_header->guc_sw_version &0xFFFF ;if (guc_fw->guc_fw_major_found != guc_fw->guc_fw_major_wanted || guc_fw->guc_fw_minor_found < guc_fw->guc_fw_minor_wanted) {Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 3/6 drm/i915/guc: Add host2guc notification for suspend and resume
In reply to [email protected]From: Alex Dai <[email protected]>
Add host2guc interfaces to nofigy GuC power state changes when enter or resume from power saving state.
--- drivers/gpu/drm/i915/i915_drv.c | 1 + drivers/gpu/drm/i915/i915_gem.c | 1 + drivers/gpu/drm/i915/i915_guc_submission.c | 50 ++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/intel_guc.h | 2 ++ drivers/gpu/drm/i915/intel_guc_fwif.h | 8 +++++ drivers/gpu/drm/i915/intel_guc_loader.c | 4 ++- 6 files changed, 65 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.c +1 -0
@@ -735,6 +735,7 @@ static int i915_drm_resume(struct drm_device *dev)DRM_ERROR ("failed to re-initialize GPU, declaring wedged!\n" );atomic_set_mask (I915_WEDGED , &dev_priv->gpu_error.reset_counter); } +intel_guc_resume (dev);mutex_unlock (&dev->struct_mutex);intel_modeset_init_hw (dev);
drivers/gpu/drm/i915/i915_gem.c +1 -0
@@ -4462,6 +4462,7 @@ i915_gem_suspend(struct drm_device *dev)i915_gem_retire_requests (dev);i915_gem_stop_ringbuffers (dev); +intel_guc_suspend (dev);mutex_unlock (&dev->struct_mutex);cancel_delayed_work_sync (&dev_priv->gpu_error.hangcheck_work);
drivers/gpu/drm/i915/i915_guc_submission.c +50 -0
53 lines not on this page · raw message
drivers/gpu/drm/i915/intel_guc.h +2 -0
@@ -110,6 +110,8 @@ extern void intel_guc_ucode_init(struct drm_device *dev);extern int intel_guc_ucode_load (struct drm_device *dev);extern void intel_guc_ucode_fini (struct drm_device *dev);extern const char *intel_guc_fw_status_repr (enum intel_guc_fw_status status); +extern int intel_guc_suspend (struct drm_device *dev); +extern int intel_guc_resume (struct drm_device *dev);/* i915_guc_submission.c */ int i915_guc_submission_init (struct drm_device *dev);
drivers/gpu/drm/i915/intel_guc_fwif.h +8 -0
@@ -254,12 +254,20 @@ struct guc_context_desc {u64 desc_private; } __packed; +#define GUC_POWER_UNSPECIFIED 0 +#define GUC_POWER_D0 1 +#define GUC_POWER_D1 2 +#define GUC_POWER_D2 3 +#define GUC_POWER_D3 4 +/* This Action will be programmed in C180 - SOFT_SCRATCH_O_REG */ enum host2guc_action {HOST2GUC_ACTION_DEFAULT =0x0 ,HOST2GUC_ACTION_SAMPLE_FORCEWAKE =0x6 ,HOST2GUC_ACTION_ALLOCATE_DOORBELL =0x10 ,HOST2GUC_ACTION_DEALLOCATE_DOORBELL =0x20 , +HOST2GUC_ACTION_ENTER_S_STATE =0x501 , +HOST2GUC_ACTION_EXIT_S_STATE =0x502 ,HOST2GUC_ACTION_SLPC_REQUEST =0x3003 ,HOST2GUC_ACTION_LIMIT };
drivers/gpu/drm/i915/intel_guc_loader.c +3 -1
@@ -407,7 +407,6 @@ int intel_guc_ucode_load(struct drm_device *dev) intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));direct_interrupts_to_host (dev_priv); -i915_guc_submission_disable (dev);if (guc_fw->guc_fw_fetch_status ==GUC_FIRMWARE_NONE )return 0 ;
@@ -457,6 +456,9 @@ int intel_guc_ucode_load(struct drm_device *dev) intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));if (i915.enable_guc_submission) { +/* The execbuf_client will be recreated. Release it first. */ +i915_guc_submission_disable (dev); + err =i915_guc_submission_enable (dev);if (err) goto fail;
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 3/15 drm/i915/guc: Add host2guc notification for suspend and resume
From: Alex Dai <[email protected]>
Add host2guc interfaces to nofigy GuC power state changes when enter or resume from power saving state.
v1: Change to a more flexible way when fill host to GuC scratch data in order to remove hard coding.
--- drivers/gpu/drm/i915/i915_drv.c | 1 + drivers/gpu/drm/i915/i915_gem.c | 1 + drivers/gpu/drm/i915/i915_guc_submission.c | 50 ++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/intel_guc.h | 2 ++ drivers/gpu/drm/i915/intel_guc_fwif.h | 8 +++++ drivers/gpu/drm/i915/intel_guc_loader.c | 4 ++- 6 files changed, 65 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.c +1 -0
@@ -735,6 +735,7 @@ static int i915_drm_resume(struct drm_device *dev)DRM_ERROR ("failed to re-initialize GPU, declaring wedged!\n" );atomic_set_mask (I915_WEDGED , &dev_priv->gpu_error.reset_counter); } +intel_guc_resume (dev);mutex_unlock (&dev->struct_mutex);intel_modeset_init_hw (dev);
drivers/gpu/drm/i915/i915_gem.c +1 -0
@@ -4458,6 +4458,7 @@ i915_gem_suspend(struct drm_device *dev)i915_gem_retire_requests (dev);i915_gem_stop_ringbuffers (dev); +intel_guc_suspend (dev);mutex_unlock (&dev->struct_mutex);cancel_delayed_work_sync (&dev_priv->gpu_error.hangcheck_work);
drivers/gpu/drm/i915/i915_guc_submission.c +50 -0
53 lines not on this page · raw message
drivers/gpu/drm/i915/intel_guc.h +2 -0
@@ -110,6 +110,8 @@ extern void intel_guc_ucode_init(struct drm_device *dev);extern int intel_guc_ucode_load (struct drm_device *dev);extern void intel_guc_ucode_fini (struct drm_device *dev);extern const char *intel_guc_fw_status_repr (enum intel_guc_fw_status status); +extern int intel_guc_suspend (struct drm_device *dev); +extern int intel_guc_resume (struct drm_device *dev);/* i915_guc_submission.c */ int i915_guc_submission_init (struct drm_device *dev);
drivers/gpu/drm/i915/intel_guc_fwif.h +8 -0
@@ -254,12 +254,20 @@ struct guc_context_desc {u64 desc_private; } __packed; +#define GUC_POWER_UNSPECIFIED 0 +#define GUC_POWER_D0 1 +#define GUC_POWER_D1 2 +#define GUC_POWER_D2 3 +#define GUC_POWER_D3 4 +/* This Action will be programmed in C180 - SOFT_SCRATCH_O_REG */ enum host2guc_action {HOST2GUC_ACTION_DEFAULT =0x0 ,HOST2GUC_ACTION_SAMPLE_FORCEWAKE =0x6 ,HOST2GUC_ACTION_ALLOCATE_DOORBELL =0x10 ,HOST2GUC_ACTION_DEALLOCATE_DOORBELL =0x20 , +HOST2GUC_ACTION_ENTER_S_STATE =0x501 , +HOST2GUC_ACTION_EXIT_S_STATE =0x502 ,HOST2GUC_ACTION_SLPC_REQUEST =0x3003 ,HOST2GUC_ACTION_LIMIT };
drivers/gpu/drm/i915/intel_guc_loader.c +3 -1
@@ -416,7 +416,6 @@ int intel_guc_ucode_load(struct drm_device *dev) intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));direct_interrupts_to_host (dev_priv); -i915_guc_submission_disable (dev);if (guc_fw->guc_fw_fetch_status ==GUC_FIRMWARE_NONE )return 0 ;
@@ -466,6 +465,9 @@ int intel_guc_ucode_load(struct drm_device *dev) intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));if (i915.enable_guc_submission) { +/* The execbuf_client will be recreated. Release it first. */ +i915_guc_submission_disable (dev); + err =i915_guc_submission_enable (dev);if (err) goto fail;
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 4/6 drm/i915/guc: Don't send flips to GuC
In reply to [email protected]From: Sagar Arun Kamble <[email protected]>
Due to flip interrupts GuC stays awake always and GT does not enter RC6. Do not route those interrupts to GuC for now.
--- drivers/gpu/drm/i915/intel_guc_loader.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/intel_guc_loader.c +5 -5
@@ -110,11 +110,11 @@ static void direct_interrupts_to_guc(struct drm_i915_private *dev_priv)for_each_ring (ring, dev_priv, i)I915_WRITE (RING_MODE_GEN7 (ring), irqs); -/* tell DE to send (all) flip_done to GuC */ - irqs =DERRMR_PIPEA_PRI_FLIP_DONE |DERRMR_PIPEA_SPR_FLIP_DONE | -DERRMR_PIPEB_PRI_FLIP_DONE |DERRMR_PIPEB_SPR_FLIP_DONE | -DERRMR_PIPEC_PRI_FLIP_DONE |DERRMR_PIPEC_SPR_FLIP_DONE ; -/* Unmasked bits will cause GuC response message to be sent */ +/* +* RC6 does not work if flips are directed to GuC as it is keeping +* GuC Awake +*/ + irqs =0 ;I915_WRITE (DE_GUCRMR , ~irqs);/* route USER_INTERRUPT to Host, all others are sent to GuC. */
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v2 1/1 drm/i915: Direct all DE interrupts to host.
Due to flip interrupts routed to GuC, GuC stays awake always and GT does not enter RC6. GuC firmware should re-direct to GuC those interrupts that it can handle.
v2: Commit message change and routing all interrupts to host. (Tom)
--- drivers/gpu/drm/i915/intel_guc_loader.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/intel_guc_loader.c +2 -6
@@ -110,12 +110,8 @@ static void direct_interrupts_to_guc(struct drm_i915_private *dev_priv)for_each_ring (ring, dev_priv, i)I915_WRITE (RING_MODE_GEN7 (ring), irqs); -/* tell DE to send (all) flip_done to GuC */ - irqs =DERRMR_PIPEA_PRI_FLIP_DONE |DERRMR_PIPEA_SPR_FLIP_DONE | -DERRMR_PIPEB_PRI_FLIP_DONE |DERRMR_PIPEB_SPR_FLIP_DONE | -DERRMR_PIPEC_PRI_FLIP_DONE |DERRMR_PIPEC_SPR_FLIP_DONE ; -/* Unmasked bits will cause GuC response message to be sent */ -I915_WRITE (DE_GUCRMR , ~irqs); +/* tell DE to send nothing to GuC */ +I915_WRITE (DE_GUCRMR , ~0 );/* route USER_INTERRUPT to Host, all others are sent to GuC. */ irqs = GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v2 1/1] drm/i915: Direct all DE interrupts to host.
Quoted 19 lines · Sagar A
Due to flip interrupts routed to GuC, GuC stays awake always and GT does not enter RC6. GuC firmware should re-direct to GuC those interrupts that it can handle.
v2: Commit message change and routing all interrupts to host. (Tom)
Cc Alex Dai <[email protected]>Cc Tom O'Rourke <Tom.O'[email protected]>Cc Akash Goel <[email protected]>Signed-off-by Sagar Arun Kamble <[email protected]>--- drivers/gpu/drm/i915/intel_guc_loader.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)drivers/gpu/drm/i915/intel_guc_loader.c +0
-0@@ -110,12 +110,8 @@ static void direct_interrupts_to_guc(struct drm_i915_private *dev_priv)for_each_ring (ring, dev_priv, i)
drivers/gpu/drm/i915/intel_guc_loader.c static void direct_interrupts_to_guc(struct drm_i915_private *dev_priv) · line 114
Quoted 10 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-6I915_WRITE (RING_MODE_GEN7 (ring), irqs); -/* tell DE to send (all) flip_done to GuC */ - irqs =DERRMR_PIPEA_PRI_FLIP_DONE |DERRMR_PIPEA_SPR_FLIP_DONE | -DERRMR_PIPEB_PRI_FLIP_DONE |DERRMR_PIPEB_SPR_FLIP_DONE | -DERRMR_PIPEC_PRI_FLIP_DONE |DERRMR_PIPEC_SPR_FLIP_DONE ; -/* Unmasked bits will cause GuC response message to be sent */ -I915_WRITE (DE_GUCRMR , ~irqs); +/* tell DE to send nothing to GuC */ +I915_WRITE (DE_GUCRMR , ~0 );
[TOR:] Should the host driver be writing these bits in DE_GUCRMR at all? An alternative approach would let GuC set/clear these bits based on whether or not GuC wants to handle the resulting interrupts; the host driver should not touch these bits since the host driver does not know what GuC wants to do (or may have already done with DE_GUCRMR register).
Thanks,
Tom
Quoted 6 lines
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0/* route USER_INTERRUPT to Host, all others are sent to GuC. */ irqs = GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |Signature · 1 line
1.9.1
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 5/6 drm/i915/guc: Media domain bit needed when notify GuC rc6 state
In reply to [email protected]From: Alex Dai <[email protected]>
GuC expects two bits for Render and Media domain separately when driver sends data via host2guc SAMPLE_FORCEWAKE. Bit 0 is for Render and bit 1 is for Media domain.
--- drivers/gpu/drm/i915/i915_guc_submission.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_guc_submission.c +2 -1
@@ -158,7 +158,8 @@ static int host2guc_sample_forcewake(struct intel_guc *guc,u32 data[2 ]; data[0 ] =HOST2GUC_ACTION_SAMPLE_FORCEWAKE ; - data[1 ] = (intel_enable_rc6 (dev_priv->dev)) ?1 :0 ; +/* bit 0 and 1 are for Render and Media domain separately */ + data[1 ] = (intel_enable_rc6 (dev_priv->dev)) ?3 :0 ;return host2guc_action (guc, data,2 ); }
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 5/6] drm/i915/guc: Media domain bit needed when notify GuC rc6 state
Quoted 16 lines · On Thu, Sep 10, 2015 at 04:56:11PM -0700, [email protected] wrote:
From: Alex Dai <[email protected]>
GuC expects two bits for Render and Media domain separately when driver sends data via host2guc
SAMPLE_FORCEWAKE. Bit 0 is for Render and bit 1 is for Media domain.Signed-off-by Alex Dai <[email protected]>--- drivers/gpu/drm/i915/i915_guc_submission.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/i915_guc_submission.c +0
-0
drivers/gpu/drm/i915/i915_guc_submission.c static int host2guc_sample_forcewake(struct intel_guc *guc, · line 162
Quoted 6 lines
drivers/gpu/drm/i915/i915_guc_submission.c +2
-1@@ -158,7 +158,8 @@ static int host2guc_sample_forcewake(struct intel_guc *guc,u32 data[2 ]; data[0 ] =HOST2GUC_ACTION_SAMPLE_FORCEWAKE ; - data[1 ] = (intel_enable_rc6 (dev_priv->dev)) ?1 :0 ; +/* bit 0 and 1 are for Render and Media domain separately */ + data[1 ] = (intel_enable_rc6 (dev_priv->dev)) ?3 :0 ;
Please don't have magic values, please add proper defines for 3 (best to do 2 separate defines and | them together).
drivers/gpu/drm/i915/i915_guc_submission.c static int host2guc_sample_forcewake(struct intel_guc *guc, · line 164
Quoted 2 lines
drivers/gpu/drm/i915/i915_guc_submission.c +0
-0return host2guc_action (guc, data,2 );
Just aside: More magic values? Maybe replace with ARRAY_SIZE(date) to make it self-explanatory.
Thanks, Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 5/15 drm/i915/guc: Media domain bit needed when notify GuC rc6 state
In reply to [email protected]From: Alex Dai <[email protected]>
GuC expects two bits for Render and Media domain separately when driver sends data via host2guc SAMPLE_FORCEWAKE. Bit 0 is for Render and bit 1 is for Media domain.
v1: Add parameters definition to avoid magic value
--- drivers/gpu/drm/i915/i915_guc_submission.c | 6 ++++-- drivers/gpu/drm/i915/intel_guc_fwif.h | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_guc_submission.c +4 -2
@@ -158,9 +158,11 @@ static int host2guc_sample_forcewake(struct intel_guc *guc,u32 data[2 ]; data[0 ] =HOST2GUC_ACTION_SAMPLE_FORCEWAKE ; - data[1 ] = (intel_enable_rc6 (dev_priv->dev)) ?1 :0 ; +/* bit 0 and 1 are for Render and Media domain separately */ + data[1 ] = (intel_enable_rc6 (dev_priv->dev)) ? +GUC_FORCEWAKE_RENDER |GUC_FORCEWAKE_MEDIA :0 ; -return host2guc_action (guc, data,2 ); +return host2guc_action (guc, data,ARRAY_SIZE (data)); }/*
drivers/gpu/drm/i915/intel_guc_fwif.h +3 -0
@@ -260,6 +260,9 @@ struct guc_context_desc {#define GUC_POWER_D2 3#define GUC_POWER_D3 4 +#define GUC_FORCEWAKE_RENDER (1 << 0) +#define GUC_FORCEWAKE_MEDIA (1 << 1) +/* This Action will be programmed in C180 - SOFT_SCRATCH_O_REG */ enum host2guc_action {HOST2GUC_ACTION_DEFAULT =0x0 ,
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 6/6 drm/i915/guc: Enable GuC submission, where supported
In reply to [email protected]From: Dave Gordon <[email protected]>
This is to enable command submission via GuC.
--- drivers/gpu/drm/i915/i915_params.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_params.c +2 -2
@@ -53,7 +53,7 @@ struct i915_params i915 __read_mostly = { .verbose_state_checks = 1, .nuclear_pageflip = 0, .edp_vswing = 0, - .enable_guc_submission = false, + .enable_guc_submission = true, .guc_log_level = -1, };
@@ -190,7 +190,7 @@ MODULE_PARM_DESC(edp_vswing, "2=default swing(400mV))");module_param_named_unsafe (enable_guc_submission, i915.enable_guc_submission, bool,0400 ); -MODULE_PARM_DESC (enable_guc_submission,"Enable GuC submission (default:false)" ); +MODULE_PARM_DESC (enable_guc_submission,"Enable GuC submission (default:true)" );module_param_named (guc_log_level, i915.guc_log_level, int,0400 ); MODULE_PARM_DESC(guc_log_level,
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
v2 cover Several GuC related patches
In reply to [email protected]From: Alex Dai <[email protected]>
Collection of some latest fixes for GuC.
v2: This version changes the way how driver handle DE_GUCRMR (0x44054) in patch "Don't send flips to GuC". Now driver does not program it and leave it to GuC firmware or HW default value.
Alex Dai (4):
drm/i915/guc: Fix a bug in GuC status check drm/i915/guc: Add GuC css header parser
drm/i915/guc: Add host2guc notification for suspend and resume drm/i915/guc: Media domain bit needed when notify GuC rc6 state
Dave Gordon (1):
drm/i915/guc: Enable GuC submission, where supported
Sagar Arun Kamble (1):
drm/i915/guc: Don't send flips to GuC
Documentation/DocBook/drm.tmpl | 9 ++- drivers/gpu/drm/i915/i915_drv.c | 1 + drivers/gpu/drm/i915/i915_gem.c | 1 + drivers/gpu/drm/i915/i915_guc_reg.h | 1 + drivers/gpu/drm/i915/i915_guc_submission.c | 56 ++++++++++++- drivers/gpu/drm/i915/i915_params.c | 4 +- drivers/gpu/drm/i915/intel_guc.h | 4 +- drivers/gpu/drm/i915/intel_guc_fwif.h | 47 +++++++++++ drivers/gpu/drm/i915/intel_guc_loader.c | 126 ++++++++++++++++++----------- 9 files changed, 195 insertions(+), 54 deletions(-)
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v2 1/6 drm/i915/guc: Fix a bug in GuC status check
From: Alex Dai <[email protected]>
Bit 16 of GuC status indicates resuming from RC6. The LAPIC_DONE status is a reliable readiness flag only when resuming from RC6. This fix a racing issue that allocation of doorbell fails whilst GuC init is not finished.
--- drivers/gpu/drm/i915/i915_guc_reg.h | 1 + drivers/gpu/drm/i915/intel_guc_loader.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_guc_reg.h +1 -0
@@ -37,6 +37,7 @@#define GS_UKERNEL_READY (0xF0 << GS_UKERNEL_SHIFT)#define GS_MIA_SHIFT 16#define GS_MIA_MASK (0x07 << GS_MIA_SHIFT) +#define GS_MIA_CORE_STATE (1 << GS_MIA_SHIFT)#define SOFT_SCRATCH (n) (0xc180 + ((n) * 4))
drivers/gpu/drm/i915/intel_guc_loader.c +3 -2
@@ -209,9 +209,10 @@ static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, u32 *status) {u32 val =I915_READ (GUC_STATUS ); +u32 uk_val = val &GS_UKERNEL_MASK ; *status = val; -return ((val &GS_UKERNEL_MASK ) ==GS_UKERNEL_READY || - (val &GS_UKERNEL_MASK ) ==GS_UKERNEL_LAPIC_DONE ); +return (uk_val ==GS_UKERNEL_READY || + ((val &GS_MIA_CORE_STATE ) && uk_val ==GS_UKERNEL_LAPIC_DONE )); }/*
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v2 1/6] drm/i915/guc: Fix a bug in GuC status check
Quoted 32 lines · On 9/23/2015 2:18 AM, [email protected] wrote:
From: Alex Dai <[email protected]>
Bit 16 of GuC status indicates resuming from RC6. The
LAPIC_DONEstatus is a reliable readiness flag only when resuming from RC6. This fix a racing issue that allocation of doorbell fails whilst GuC init is not finished.Signed-off-by Alex Dai <[email protected]>--- drivers/gpu/drm/i915/i915_guc_reg.h | 1 + drivers/gpu/drm/i915/intel_guc_loader.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/i915_guc_reg.h +1
-0@@ -37,6 +37,7 @@#define GS_UKERNEL_READY (0xF0 << GS_UKERNEL_SHIFT)#define GS_MIA_SHIFT 16#define GS_MIA_MASK (0x07 << GS_MIA_SHIFT) +#define GS_MIA_CORE_STATE (1 << GS_MIA_SHIFT)#define SOFT_SCRATCH (n) (0xc180 + ((n) * 4))drivers/gpu/drm/i915/intel_guc_loader.c +0
-0@@ -209,9 +209,10 @@ static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, u32 *status) {
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, · line 218
Quoted 10 lines
drivers/gpu/drm/i915/intel_guc_loader.c +3
-2u32 val =I915_READ (GUC_STATUS ); +u32 uk_val = val &GS_UKERNEL_MASK ; *status = val; -return ((val &GS_UKERNEL_MASK ) ==GS_UKERNEL_READY || - (val &GS_UKERNEL_MASK ) ==GS_UKERNEL_LAPIC_DONE ); +return (uk_val ==GS_UKERNEL_READY || + ((val &GS_MIA_CORE_STATE ) && uk_val ==GS_UKERNEL_LAPIC_DONE )); }/*
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Daniel Vetter
AppliedRe: [PATCH v2 1/6] drm/i915/guc: Fix a bug in GuC status check
Quoted 11 lines · Sagar A
Reviewed-by Sagar Arun Kamble <[email protected]>Quoted 8 lines · On 9/23/2015 2:18 AM, [email protected] wrote:
From: Alex Dai <[email protected]>
Bit 16 of GuC status indicates resuming from RC6. The
LAPIC_DONEstatus is a reliable readiness flag only when resuming from RC6. This fix a racing issue that allocation of doorbell fails whilst GuC init is not finished.Signed-off-by Alex Dai <[email protected]>
Queued for -next, thanks for the patch.
-Daniel
Quoted 36 lines
Quoted 21 lines
--- drivers/gpu/drm/i915/i915_guc_reg.h | 1 + drivers/gpu/drm/i915/intel_guc_loader.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/i915_guc_reg.h +1
-0@@ -37,6 +37,7 @@#define GS_UKERNEL_READY (0xF0 << GS_UKERNEL_SHIFT)#define GS_MIA_SHIFT 16#define GS_MIA_MASK (0x07 << GS_MIA_SHIFT) +#define GS_MIA_CORE_STATE (1 << GS_MIA_SHIFT)#define SOFT_SCRATCH (n) (0xc180 + ((n) * 4))drivers/gpu/drm/i915/intel_guc_loader.c +0
-0@@ -209,9 +209,10 @@ static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, u32 *status)drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, · line 217
Quoted 10 lines
drivers/gpu/drm/i915/intel_guc_loader.c +3
-2{u32 val =I915_READ (GUC_STATUS ); +u32 uk_val = val &GS_UKERNEL_MASK ; *status = val; -return ((val &GS_UKERNEL_MASK ) ==GS_UKERNEL_READY || - (val &GS_UKERNEL_MASK ) ==GS_UKERNEL_LAPIC_DONE ); +return (uk_val ==GS_UKERNEL_READY || + ((val &GS_MIA_CORE_STATE ) && uk_val ==GS_UKERNEL_LAPIC_DONE )); }/* _______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v2 2/6 drm/i915/guc: Add GuC css header parser
In reply to [email protected]From: Alex Dai <[email protected]>
By using information from GuC css header, we can eliminate some hard code w.r.t size of some components of firmware.
v2: Add indent into DOC to make fixed-width format rather than change the tmpl.
v1: 1) guc_css_header is defined as __packed now
2) Add and correct GuC related topics in kernel/Doc
--- Documentation/DocBook/drm.tmpl | 9 ++- drivers/gpu/drm/i915/intel_guc.h | 2 +- drivers/gpu/drm/i915/intel_guc_fwif.h | 36 +++++++++++ drivers/gpu/drm/i915/intel_guc_loader.c | 107 ++++++++++++++++++++++---------- 4 files changed, 117 insertions(+), 37 deletions(-)
Documentation/DocBook/drm.tmpl +7 -2
@@ -4155,14 +4155,19 @@ int num_ioctls;</synopsis> <title>GuC-based Command Submission</title> <sect2> <title>GuC</title> -!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC-specific firmware loader +!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC !Idrivers/gpu/drm/i915/intel_guc_loader.c </sect2> <sect2> <title>GuC Client</title> -!Pdrivers/gpu/drm/i915/i915_guc_submission.c GuC-based command submissison +!Pdrivers/gpu/drm/i915/i915_guc_submission.c GuC Client !Idrivers/gpu/drm/i915/i915_guc_submission.c </sect2> + <sect2> + <title>GuC Firmware Layout</title> +!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC Firmware Layout +!Idrivers/gpu/drm/i915/intel_guc_loader.c + </sect2> </sect1> <sect1>
drivers/gpu/drm/i915/intel_guc.h +1 -1
@@ -71,6 +71,7 @@ struct intel_guc_fw {struct drm_i915_gem_object * guc_fw_obj;enum intel_guc_fw_status guc_fw_fetch_status;enum intel_guc_fw_status guc_fw_load_status; +struct guc_css_header guc_fw_header;uint16_t guc_fw_major_wanted;uint16_t guc_fw_minor_wanted;
@@ -80,7 +81,6 @@ struct intel_guc_fw {struct intel_guc {struct intel_guc_fw guc_fw; -uint32_t log_flags;struct drm_i915_gem_object *log_obj;
drivers/gpu/drm/i915/intel_guc_fwif.h +36 -0
@@ -122,6 +122,42 @@#define GUC_CTL_MAX_DWORDS (GUC_CTL_RSRVD + 1) +struct guc_css_header { +uint32_t module_type; +uint32_t header_len;/* header length plus size of all other keys */ +uint32_t header_version; +uint32_t module_id; +uint32_t module_vendor; +union { +struct { +uint8_t day; +uint8_t month; +uint16_t year; + }; +uint32_t date; + }; +uint32_t size;/* uCode size plus header_len */ +uint32_t key_size; +uint32_t modulus_size; +uint32_t exponent_size; +union { +struct { +uint8_t hour; +uint8_t min; +uint16_t sec; + }; +uint32_t time; + }; + +char username[8 ]; +char buildnumber[12 ]; +uint32_t device_id; +uint32_t guc_sw_version; +uint32_t prod_preprod_fw; +uint32_t reserved[12 ]; +uint32_t header_info; +} __packed; +struct guc_doorbell_info {u32 db_status;u32 cookie;
drivers/gpu/drm/i915/intel_guc_loader.c +73 -34
152 lines not on this page · raw message
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v2 2/6] drm/i915/guc: Add GuC css header parser
Quoted 144 lines · On 22/09/15 21:48, [email protected] wrote:
From: Alex Dai <[email protected]>
By using information from GuC css header, we can eliminate some hard code w.r.t size of some components of firmware.
v2: Add indent into DOC to make fixed-width format rather than change the tmpl.
v1: 1)
guc_css_headeris defined as__packednow
2) Add and correct GuC related topics in kernel/DocSigned-off-by Alex Dai <[email protected]>--- Documentation/DocBook/drm.tmpl | 9 ++- drivers/gpu/drm/i915/intel_guc.h | 2 +- drivers/gpu/drm/i915/intel_guc_fwif.h | 36 +++++++++++ drivers/gpu/drm/i915/intel_guc_loader.c | 107 ++++++++++++++++++++++---------- 4 files changed, 117 insertions(+), 37 deletions(-)Documentation/DocBook/drm.tmpl +7
-2@@ -4155,14 +4155,19 @@ int num_ioctls;</synopsis> <title>GuC-based Command Submission</title> <sect2> <title>GuC</title> -!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC-specific firmware loader +!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC !Idrivers/gpu/drm/i915/intel_guc_loader.c </sect2> <sect2> <title>GuC Client</title> -!Pdrivers/gpu/drm/i915/i915_guc_submission.c GuC-based command submissison +!Pdrivers/gpu/drm/i915/i915_guc_submission.c GuC Client !Idrivers/gpu/drm/i915/i915_guc_submission.c </sect2> + <sect2> + <title>GuC Firmware Layout</title> +!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC Firmware Layout +!Idrivers/gpu/drm/i915/intel_guc_loader.c + </sect2> </sect1> <sect1>drivers/gpu/drm/i915/intel_guc.h +1
-1@@ -71,6 +71,7 @@ struct intel_guc_fw {struct drm_i915_gem_object * guc_fw_obj;enum intel_guc_fw_status guc_fw_fetch_status;enum intel_guc_fw_status guc_fw_load_status; +struct guc_css_header guc_fw_header;uint16_t guc_fw_major_wanted;uint16_t guc_fw_minor_wanted;@@ -80,7 +81,6 @@ struct intel_guc_fw {struct intel_guc {struct intel_guc_fw guc_fw; -uint32_t log_flags;struct drm_i915_gem_object *log_obj;drivers/gpu/drm/i915/intel_guc_fwif.h +36
-0@@ -122,6 +122,42 @@#define GUC_CTL_MAX_DWORDS (GUC_CTL_RSRVD + 1) +struct guc_css_header { +uint32_t module_type; +uint32_t header_len;/* header length plus size of all other keys */ +uint32_t header_version; +uint32_t module_id; +uint32_t module_vendor; +union { +struct { +uint8_t day; +uint8_t month; +uint16_t year; + }; +uint32_t date; + }; +uint32_t size;/* uCode size plus header_len */ +uint32_t key_size; +uint32_t modulus_size; +uint32_t exponent_size; +union { +struct { +uint8_t hour; +uint8_t min; +uint16_t sec; + }; +uint32_t time; + }; + +char username[8 ]; +char buildnumber[12 ]; +uint32_t device_id; +uint32_t guc_sw_version; +uint32_t prod_preprod_fw; +uint32_t reserved[12 ]; +uint32_t header_info; +} __packed; +struct guc_doorbell_info {u32 db_status;u32 cookie;drivers/gpu/drm/i915/intel_guc_loader.c +12
-11@@ -215,18 +215,29 @@ static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, ((val & GS_MIA_CORE_STATE) && uk_val == GS_UKERNEL_LAPIC_DONE)); } -/* -* Transfer the firmware image to RAM for execution by the microcontroller. +/** +* DOC: GuC Firmware Layout * -* GuC Firmware layout: -* +-------------------------------+ ---- -* | CSS header | 128B -* | contains major/minor version | -* +-------------------------------+ ---- -* | uCode | -* +-------------------------------+ ---- -* | RSA signature | 256B -* +-------------------------------+ ---- +* The GuC firmware layout looks like this: +* +* +-------------------------------+ +* | guc_css_header | +* | contains major/minor version | +* +-------------------------------+ +* | uCode | +* +-------------------------------+ +* | RSA signature | +* +-------------------------------+
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, · line 240
Quoted 10 lines
drivers/gpu/drm/i915/intel_guc_loader.c +10
-0+* | modulus key | +* +-------------------------------+ +* | exponent val | +* +-------------------------------+ +* +* The firmware may or may not have modulus key and exponent data. The header, +* uCode and RSA signature are must-have components that will be used by driver. +* Size of each components (in dwords) can be found in header. In the case that +* modulus and exponent are not present in fw, the size value still appears in +* header.
I think this picture & commentary belongs just ahead of the structure definition in intel_guc_fwif.h, rather than with the code here. Also, perhaps we nede a bit more explanation of the '*size' fields, since they have been defined in such a counter-intuitive way :( I suggest:
* All the 'sizes' in the CSS header are expressed as numbers of
* "dwords", and therefore have to be multiplied by sizeof (u32) to
* get actual sizes (in the normal sense of byte counts).
*
* The 'size' field is the total size of the data in the picture
* above, and should match the size of the file as provided by the
* loader; the file is invalid if this size field is greater than
* the actual filesize.
*
* The 'header_len' field contains the total size of the non-uCode
* sections of the file (i.e. the sum of the sizes of the CSS header,
* the RSA signature, the modulus key and the exponent). Thus, to find
* the size of the uCode we subtract this total from 'size', but to
* find the size of the CSS header (which also defines the start of
* the uCode), we subtract the other three sizes from this total. The
* size of the CSS header thus calculated should match sizeof(struct
* guc_css_header) (or exceed it; allowing it to be larger permits
* future expansion of the CSS header or insertion of extra sections
* here). The file is invalid if this calculated size is less than
* sizeof(struct guc_css_header).
*
* The size of the RSA signature must not exceed that expected by the
* hardware. The file is invalid if the value of this field is more
* than the size of the signature area in the GuC register space,
* currently 0x100 bytes.
*
* Due to the requirements of the DMA engine, the total size of the
* sections that are DMA'd into the GuC's memory (CSS header plus
* uCode) must be a multiple of the cache line size. The file is
* invalid if this requirement is not met.
The rest of this comment can stay with the code ...
Quoted 16 lines
drivers/gpu/drm/i915/intel_guc_loader.c +3
-6* * Architecturally, the DMA engine is bidirectional, and can potentially even * transfer between GTT locations. This functionality is left out of the API @@ -236,30 +247,42 @@ static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,* DMA engine in one operation, whereas the RSA signature is loaded via MMIO. */ -#define UOS_CSS_HEADER_OFFSET 0 -#define UOS_VER_MINOR_OFFSET 0x44 -#define UOS_VER_MAJOR_OFFSET 0x46 -#define UOS_CSS_HEADER_SIZE 0x80 -#define UOS_RSA_SIG_SIZE 0x100 - +/* +* Transfer the firmware image to RAM for execution by the microcontroller. +*/
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, · line 261
Quoted 10 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-1static int guc_ucode_xfer_dma (struct drm_i915_private *dev_priv) {struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw; +struct guc_css_header *header = &guc_fw->guc_fw_header;struct drm_i915_gem_object *fw_obj = guc_fw->guc_fw_obj;unsigned long offset;struct sg_table *sg = fw_obj->pages; -u32 status, ucode_size, rsa[UOS_RSA_SIG_SIZE /sizeof (u32)]; +u32 status, header_size, rsa_size, ucode_size, *rsa;int i, ret =0 ;
I don't like doing the complicated size-based calculations in the DMA routine; I'd rather the important values (RSA start/size, CSS+uCode start/size) were precalculated during loading and saved in the struct intel_guc_fw or a member thereof so that this code already has the exact numbers it needs without any further computation.
Quoted 83 lines
drivers/gpu/drm/i915/intel_guc_loader.c +44
-13-/* uCode size, also is where RSA signature starts */ - offset = ucode_size = guc_fw->guc_fw_size -UOS_RSA_SIG_SIZE ; -I915_WRITE (DMA_COPY_SIZE , ucode_size); +/* The header plus uCode will be copied to WOPCM via DMA, excluding any +* other components */ + header_size = (header->header_len - header->key_size - + header->modulus_size - header->exponent_size) *sizeof (u32); + ucode_size = (header->size - header->header_len) *sizeof (u32); + +I915_WRITE (DMA_COPY_SIZE , header_size + ucode_size); + +/* where RSA signature starts */ + offset = header_size + ucode_size; + + rsa_size = header->key_size *sizeof (u32); + rsa =kmalloc (rsa_size,GFP_KERNEL ); +if (!rsa) +return -ENOMEM ;/* Copy RSA signature from the fw image to HW for verification */ -sg_pcopy_to_buffer (sg->sgl, sg->nents, rsa,UOS_RSA_SIG_SIZE , offset); -for (i =0 ; i <UOS_RSA_SIG_SIZE /sizeof (u32); i++) +sg_pcopy_to_buffer (sg->sgl, sg->nents, rsa, rsa_size, offset); +for (i =0 ; i < rsa_size /sizeof (u32); i++)I915_WRITE (UOS_RSA_SCRATCH_0 + i *sizeof (u32), rsa[i]); +kfree (rsa); +/* Set the source address for the new blob */ offset =i915_gem_obj_ggtt_offset (fw_obj);I915_WRITE (DMA_ADDR_0_LOW ,lower_32_bits (offset));@@ -465,10 +488,8 @@ static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw) {struct drm_i915_gem_object *obj;const struct firmware *fw; -const u8 *css_header; -const size_t minsize =UOS_CSS_HEADER_SIZE +UOS_RSA_SIG_SIZE ; -const size_t maxsize =GUC_WOPCM_SIZE_VALUE +UOS_RSA_SIG_SIZE - -0x8000 ;/* 32k reserved (8K stack + 24k context) */ +struct guc_css_header *css_header = &guc_fw->guc_fw_header; +size_t size;int err; DRM_DEBUG_DRIVER("before requesting firmware: GuC fw fetch status %s\n",@@ -482,12 +503,31 @@ static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)DRM_DEBUG_DRIVER ("fetch GuC fw from %s succeeded, fw %p\n" , guc_fw->guc_fw_path, fw); -DRM_DEBUG_DRIVER ("firmware file size %zu (minimum %zu, maximum %zu)\n" , - fw->size, minsize, maxsize); -/* Check the size of the blob befoe examining buffer contents */ -if (fw->size < minsize || fw->size > maxsize) +/* Check the size of the blob before examining buffer contents */ +if (fw->size <sizeof (struct guc_css_header )) { +DRM_ERROR ("Firmware header is missing\n" ); + goto fail; + } + +memcpy (css_header, fw->data,sizeof (struct guc_css_header )); + +/* At least, it should have header, uCode and RSA. Size of all three. */ + size = (css_header->size - css_header->modulus_size - + css_header->exponent_size) *sizeof (u32); +if (fw->size < size) { +DRM_ERROR ("Missing firmware components\n" ); goto fail; + } + +/* Header and uCode will be loaded to WOPCM. Size of the two. */ + size -= css_header->key_size *sizeof (u32); + +/* Top 32k of WOPCM is reserved (8K stack + 24k RC6 context). */ +if (size >GUC_WOPCM_SIZE_VALUE -0x8000 ) { +DRM_ERROR ("Firmware is too large to fit in WOPCM\n" ); + goto fail; + }/* * The GuC firmware image has the version number embedded at a well-known @@ -495,9 +535,8 @@ static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)* TWO bytes each (i.e. u16), although all pointers and offsets are defined
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw) · line 542
Quoted 10 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-3* in terms of bytes (u8). */ - css_header = fw->data +UOS_CSS_HEADER_OFFSET ; - guc_fw->guc_fw_major_found = *(u16 *)(css_header +UOS_VER_MAJOR_OFFSET ); - guc_fw->guc_fw_minor_found = *(u16 *)(css_header +UOS_VER_MINOR_OFFSET ); + guc_fw->guc_fw_major_found = css_header->guc_sw_version >>16 ; + guc_fw->guc_fw_minor_found = css_header->guc_sw_version &0xFFFF ;if (guc_fw->guc_fw_major_found != guc_fw->guc_fw_major_wanted || guc_fw->guc_fw_minor_found < guc_fw->guc_fw_minor_wanted) {
We need to validate each of the sizes read from the binary blob before using them in calculations, and we then also need to validate the results of the calculations, to prevent anyone spoofing the loader into writing where it shouldn't.
In particular, we need to check:
fw->size >= sizeof(struct guc_css_header) css_header->size (*4) <= fw->size css_header->header_len <= css_header->size => (uCode_size = css_header->size - css_header_len) >= 0 css_header->key_size (*4) <= HW_SIG_SIZE (0x100) css_header->key_size <= css_header->header_len css_header->modulus_size <= css_header->header_len css_header->exponent_size <= css_header->header_len css_header->header_len >= css_header->key_size + css_header->modulus_size + css_header->exponent_size; => (css_header_size = css_header->header_len - css_header->key_size - css_header->modulus_size - css_header->exponent_size) >= 0 css_header_size + uCode_size == 0 mod cachelinesize
(Since all these sizes are unsigned, we can't (and don't need to) check for negative results from the subtractions, but we can check that each value that's defined as including the sum of other values is actually large enough so that the subtractions give meaningful results).
Some of these checks are already there, but I think we should complete all of them to catch any other invalid combinations of values. And then save the computed start/size values so the DMA code can just retrieve the precalculated values.
.Dave.
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v2 2/6] drm/i915/guc: Add GuC css header parser
Quoted 150 lines · Dave Gordon
Quoted 149 lines · On 22/09/15 21:48, [email protected] wrote:
From: Alex Dai <[email protected]>
By using information from GuC css header, we can eliminate some hard code w.r.t size of some components of firmware.
v2: Add indent into DOC to make fixed-width format rather than change the tmpl.
v1: 1)
guc_css_headeris defined as__packednow
2) Add and correct GuC related topics in kernel/DocSigned-off-by Alex Dai <[email protected]>--- Documentation/DocBook/drm.tmpl | 9 ++- drivers/gpu/drm/i915/intel_guc.h | 2 +- drivers/gpu/drm/i915/intel_guc_fwif.h | 36 +++++++++++ drivers/gpu/drm/i915/intel_guc_loader.c | 107 ++++++++++++++++++++++---------- 4 files changed, 117 insertions(+), 37 deletions(-)Documentation/DocBook/drm.tmpl +7
-2@@ -4155,14 +4155,19 @@ int num_ioctls;</synopsis> <title>GuC-based Command Submission</title> <sect2> <title>GuC</title> -!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC-specific firmware loader +!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC !Idrivers/gpu/drm/i915/intel_guc_loader.c </sect2> <sect2> <title>GuC Client</title> -!Pdrivers/gpu/drm/i915/i915_guc_submission.c GuC-based command submissison +!Pdrivers/gpu/drm/i915/i915_guc_submission.c GuC Client !Idrivers/gpu/drm/i915/i915_guc_submission.c </sect2> + <sect2> + <title>GuC Firmware Layout</title> +!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC Firmware Layout +!Idrivers/gpu/drm/i915/intel_guc_loader.c + </sect2> </sect1> <sect1>drivers/gpu/drm/i915/intel_guc.h +1
-1@@ -71,6 +71,7 @@ struct intel_guc_fw {struct drm_i915_gem_object * guc_fw_obj;enum intel_guc_fw_status guc_fw_fetch_status;enum intel_guc_fw_status guc_fw_load_status; +struct guc_css_header guc_fw_header;uint16_t guc_fw_major_wanted;uint16_t guc_fw_minor_wanted;@@ -80,7 +81,6 @@ struct intel_guc_fw {struct intel_guc {struct intel_guc_fw guc_fw; -uint32_t log_flags;struct drm_i915_gem_object *log_obj;drivers/gpu/drm/i915/intel_guc_fwif.h +36
-0@@ -122,6 +122,42 @@#define GUC_CTL_MAX_DWORDS (GUC_CTL_RSRVD + 1) +struct guc_css_header { +uint32_t module_type; +uint32_t header_len;/* header length plus size of all other keys */ +uint32_t header_version; +uint32_t module_id; +uint32_t module_vendor; +union { +struct { +uint8_t day; +uint8_t month; +uint16_t year; + }; +uint32_t date; + }; +uint32_t size;/* uCode size plus header_len */ +uint32_t key_size; +uint32_t modulus_size; +uint32_t exponent_size; +union { +struct { +uint8_t hour; +uint8_t min; +uint16_t sec; + }; +uint32_t time; + }; + +char username[8 ]; +char buildnumber[12 ]; +uint32_t device_id; +uint32_t guc_sw_version; +uint32_t prod_preprod_fw; +uint32_t reserved[12 ]; +uint32_t header_info; +} __packed; +struct guc_doorbell_info {u32 db_status;u32 cookie;drivers/gpu/drm/i915/intel_guc_loader.c +17
-11@@ -215,18 +215,29 @@ static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, ((val & GS_MIA_CORE_STATE) && uk_val == GS_UKERNEL_LAPIC_DONE)); } -/* -* Transfer the firmware image to RAM for execution by the microcontroller. +/** +* DOC: GuC Firmware Layout * -* GuC Firmware layout: -* +-------------------------------+ ---- -* | CSS header | 128B -* | contains major/minor version | -* +-------------------------------+ ---- -* | uCode | -* +-------------------------------+ ---- -* | RSA signature | 256B -* +-------------------------------+ ---- +* The GuC firmware layout looks like this: +* +* +-------------------------------+ +* | guc_css_header | +* | contains major/minor version | +* +-------------------------------+ +* | uCode | +* +-------------------------------+ +* | RSA signature | +* +-------------------------------+ +* | modulus key | +* +-------------------------------+ +* | exponent val | +* +-------------------------------+ +*
Quoted 8 lines
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, · line 240
Quoted 5 lines
drivers/gpu/drm/i915/intel_guc_loader.c +5
-0+* The firmware may or may not have modulus key and exponent data. The header, +* uCode and RSA signature are must-have components that will be used by driver. +* Size of each components (in dwords) can be found in header. In the case that +* modulus and exponent are not present in fw, the size value still appears in +* header. I think this picture & commentary belongs just ahead of the structure definition in
intel_guc_fwif.h, rather than with the code here. Also,
Yes, this can be moved to intel_guc_fwif.h right before css_header structure definition.
Quoted 7 lines
perhaps we nede a bit more explanation of the '*size' fields, since they have been defined in such a counter-intuitive way :( I suggest:
* All the 'sizes' in the CSS header are expressed as numbers of
* "dwords", and therefore have to be multiplied by sizeof (u32) to
* get actual sizes (in the normal sense of byte counts). *
In comments, I clearly mention that all size of these guc components are in dwords. In next version, I can add surfix _dword to avoid confuse.
Quoted 4 lines
* The 'size' field is the total size of the data in the picture
* above, and should match the size of the file as provided by the
* loader; the file is invalid if this size field is greater than
* the actual filesize.
This is not right assumption. And, that will change some expectation below related to size checking. I should have make my comments more clear. But
"The firmware may or may not have modulus key and exponent data ... In the case that modulus and exponent are not present in fw, the size value still appears in header."
We have discussed this with firmware team. Since the 'size' (actually the header) is used to generate RSA key, we can't change it after signing. So, we have information of modulus etc. but driver doesn't need them to load firmware. Likely they are not part of the release bin file. So the 'size' may be larger than the bin file size. Currently, fw check is based on the following rules (maybe I need add these to the comment too):
1. Header, uCode and RSA are must-have components.
2. All firmware components, if they present, are in the sequence illustrated in the layout table.
3. Size info of each component can be found in header, in dwords.
4. Modulus and exponent key are not required by driver. They may not appear in fw but their size info are recorded in header anyway.
Quoted 14 lines
*
* The 'header_len' field contains the total size of the non-uCode
* sections of the file (i.e. the sum of the sizes of the CSS header,
* the RSA signature, the modulus key and the exponent). Thus, to find
* the size of the uCode we subtract this total from 'size', but to
* find the size of the CSS header (which also defines the start of
* the uCode), we subtract the other three sizes from this total. The
* size of the CSS header thus calculated should match sizeof(struct
*guc_css_header) (or exceed it; allowing it to be larger permits
* future expansion of the CSS header or insertion of extra sections
* here). The file is invalid if this calculated size is less than
*sizeof(struct guc_css_header).
*
* The size of the RSA signature must not exceed that expected by the
Quoted 9 lines
* hardware. The file is invalid if the value of this field is more
* than the size of the signature area in the GuC register space,
* currently0x100bytes.
*
* Due to the requirements of the DMA engine, the total size of the
* sections that are DMA'd into the GuC's memory (CSS header plus
* uCode) must be a multiple of the cache line size. The file is
* invalid if this requirement is not met.
All suggestions above are valid at some points. However, be note that, the firmware size checking I put into code is actually to protect driver - just make sure we don't have a bug check due to memory access violation. No matter how much protection you put into driver, you still can't reject the case by driver if someone modifies one byte of uCode. So, as long as we have the bits of header, uCode and RSA, we will load it. HW will fail it anyway if anything goes wrong.
Quoted 26 lines
The rest of this comment can stay with the code ...
Quoted 24 lines
drivers/gpu/drm/i915/intel_guc_loader.c +4
-7* * Architecturally, the DMA engine is bidirectional, and can potentially even * transfer between GTT locations. This functionality is left out of the API @@ -236,30 +247,42 @@ static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,* DMA engine in one operation, whereas the RSA signature is loaded via MMIO. */ -#define UOS_CSS_HEADER_OFFSET 0 -#define UOS_VER_MINOR_OFFSET 0x44 -#define UOS_VER_MAJOR_OFFSET 0x46 -#define UOS_CSS_HEADER_SIZE 0x80 -#define UOS_RSA_SIG_SIZE 0x100 - +/* +* Transfer the firmware image to RAM for execution by the microcontroller. +*/ static int guc_ucode_xfer_dma (struct drm_i915_private *dev_priv) {struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw; +struct guc_css_header *header = &guc_fw->guc_fw_header;struct drm_i915_gem_object *fw_obj = guc_fw->guc_fw_obj;unsigned long offset;struct sg_table *sg = fw_obj->pages; -u32 status, ucode_size, rsa[UOS_RSA_SIG_SIZE /sizeof (u32)];
Quoted 8 lines
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, · line 261
Quoted 2 lines
drivers/gpu/drm/i915/intel_guc_loader.c +1
-0+u32 status, header_size, rsa_size, ucode_size, *rsa;int i, ret =0 ;I don't like doing the complicated size-based calculations in the DMA routine; I'd rather the important values (RSA start/size, CSS+uCode start/size) were precalculated during loading and saved in the struct
intel_guc_fwor a member thereof so that this code already has the exact numbers it needs without any further computation.
This is a good point.
Quoted 123 lines
Quoted 83 lines
drivers/gpu/drm/i915/intel_guc_loader.c +44
-13-/* uCode size, also is where RSA signature starts */ - offset = ucode_size = guc_fw->guc_fw_size -UOS_RSA_SIG_SIZE ; -I915_WRITE (DMA_COPY_SIZE , ucode_size); +/* The header plus uCode will be copied to WOPCM via DMA, excluding any +* other components */ + header_size = (header->header_len - header->key_size - + header->modulus_size - header->exponent_size) *sizeof (u32); + ucode_size = (header->size - header->header_len) *sizeof (u32); + +I915_WRITE (DMA_COPY_SIZE , header_size + ucode_size); + +/* where RSA signature starts */ + offset = header_size + ucode_size; + + rsa_size = header->key_size *sizeof (u32); + rsa =kmalloc (rsa_size,GFP_KERNEL ); +if (!rsa) +return -ENOMEM ;/* Copy RSA signature from the fw image to HW for verification */ -sg_pcopy_to_buffer (sg->sgl, sg->nents, rsa,UOS_RSA_SIG_SIZE , offset); -for (i =0 ; i <UOS_RSA_SIG_SIZE /sizeof (u32); i++) +sg_pcopy_to_buffer (sg->sgl, sg->nents, rsa, rsa_size, offset); +for (i =0 ; i < rsa_size /sizeof (u32); i++)I915_WRITE (UOS_RSA_SCRATCH_0 + i *sizeof (u32), rsa[i]); +kfree (rsa); +/* Set the source address for the new blob */ offset =i915_gem_obj_ggtt_offset (fw_obj);I915_WRITE (DMA_ADDR_0_LOW ,lower_32_bits (offset));@@ -465,10 +488,8 @@ static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw) {struct drm_i915_gem_object *obj;const struct firmware *fw; -const u8 *css_header; -const size_t minsize =UOS_CSS_HEADER_SIZE +UOS_RSA_SIG_SIZE ; -const size_t maxsize =GUC_WOPCM_SIZE_VALUE +UOS_RSA_SIG_SIZE - -0x8000 ;/* 32k reserved (8K stack + 24k context) */ +struct guc_css_header *css_header = &guc_fw->guc_fw_header; +size_t size;int err; DRM_DEBUG_DRIVER("before requesting firmware: GuC fw fetch status %s\n",@@ -482,12 +503,31 @@ static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)DRM_DEBUG_DRIVER ("fetch GuC fw from %s succeeded, fw %p\n" , guc_fw->guc_fw_path, fw); -DRM_DEBUG_DRIVER ("firmware file size %zu (minimum %zu, maximum %zu)\n" , - fw->size, minsize, maxsize); -/* Check the size of the blob befoe examining buffer contents */ -if (fw->size < minsize || fw->size > maxsize) +/* Check the size of the blob before examining buffer contents */ +if (fw->size <sizeof (struct guc_css_header )) { +DRM_ERROR ("Firmware header is missing\n" ); + goto fail; + } + +memcpy (css_header, fw->data,sizeof (struct guc_css_header )); + +/* At least, it should have header, uCode and RSA. Size of all three. */ + size = (css_header->size - css_header->modulus_size - + css_header->exponent_size) *sizeof (u32); +if (fw->size < size) { +DRM_ERROR ("Missing firmware components\n" ); goto fail; + } + +/* Header and uCode will be loaded to WOPCM. Size of the two. */ + size -= css_header->key_size *sizeof (u32); + +/* Top 32k of WOPCM is reserved (8K stack + 24k RC6 context). */ +if (size >GUC_WOPCM_SIZE_VALUE -0x8000 ) { +DRM_ERROR ("Firmware is too large to fit in WOPCM\n" ); + goto fail; + }/* * The GuC firmware image has the version number embedded at a well-known @@ -495,9 +535,8 @@ static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)* TWO bytes each (i.e. u16), although all pointers and offsets are defined drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw) · line 542
Quoted 10 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-3* in terms of bytes (u8). */ - css_header = fw->data +UOS_CSS_HEADER_OFFSET ; - guc_fw->guc_fw_major_found = *(u16 *)(css_header +UOS_VER_MAJOR_OFFSET ); - guc_fw->guc_fw_minor_found = *(u16 *)(css_header +UOS_VER_MINOR_OFFSET ); + guc_fw->guc_fw_major_found = css_header->guc_sw_version >>16 ; + guc_fw->guc_fw_minor_found = css_header->guc_sw_version &0xFFFF ;if (guc_fw->guc_fw_major_found != guc_fw->guc_fw_major_wanted || guc_fw->guc_fw_minor_found < guc_fw->guc_fw_minor_wanted) {We need to validate each of the sizes read from the binary blob before using them in calculations, and we then also need to validate the results of the calculations, to prevent anyone spoofing the loader into writing where it shouldn't.
In particular, we need to check:
fw->size >= sizeof(struct guc_css_header) css_header->size (*4) <= fw->size css_header->header_len <= css_header->size => (uCode_size = css_header->size - css_header_len) >= 0 css_header->key_size (*4) <= HW_SIG_SIZE (0x100) css_header->key_size <= css_header->header_len css_header->modulus_size <= css_header->header_len css_header->exponent_size <= css_header->header_len css_header->header_len >= css_header->key_size + css_header->modulus_size + css_header->exponent_size; => (css_header_size = css_header->header_len - css_header->key_size - css_header->modulus_size - css_header->exponent_size) >= 0 css_header_size + uCode_size == 0 mod cachelinesize(Since all these sizes are unsigned, we can't (and don't need to) check for negative results from the subtractions, but we can check that each value that's defined as including the sum of other values is actually large enough so that the subtractions give meaningful results).
Quoted 5 lines
Some of these checks are already there, but I think we should complete all of them to catch any other invalid combinations of values. And then save the computed start/size values so the DMA code can just retrieve the precalculated values.
I only agree with check between header size and fw size. This allows driver keeps going without bug check. All others between members within css_header are not needed. The reason is simple. If you trust content of css_header, then you don't need to validate them. If you don't trust it, no need to check it anyway. Again, as long as we have enough bits to load to HW, we will let it go.
Thanks,
Alex
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v2 2/6] drm/i915/guc: Add GuC css header parser
Quoted 182 lines · Yu Dai
Quoted 164 lines · Dave Gordon
Quoted 11 lines · On 22/09/15 21:48, [email protected] wrote:
From: Alex Dai <[email protected]>
By using information from GuC css header, we can eliminate some hard code w.r.t size of some components of firmware.
v2: Add indent into DOC to make fixed-width format rather than change the tmpl.
v1: 1)
guc_css_headeris defined as__packednow
2) Add and correct GuC related topics in kernel/DocQuoted 6 lines
Signed-off-by Alex Dai <[email protected]>--- Documentation/DocBook/drm.tmpl | 9 ++- drivers/gpu/drm/i915/intel_guc.h | 2 +- drivers/gpu/drm/i915/intel_guc_fwif.h | 36 +++++++++++ drivers/gpu/drm/i915/intel_guc_loader.c | 107++++++++++++++++++++++----------
Review
Quoted 3 lines
4 files changed, 117 insertions(+), 37 deletions(-)(quoted diff) +0
-0b/Documentation/DocBook/drm.tmpl
Quoted 4 lines
index 66bc646..116332f 100644
Documentation/DocBook/drm.tmpl int num_ioctls;</synopsis> · line 4163
Quoted 10 lines
Documentation/DocBook/drm.tmpl +1
-2@@ -4155,14 +4155,19 @@ int num_ioctls;</synopsis> <title>GuC-based Command Submission</title> <sect2>../linux-image-4.3.0-rc2-dsg-11022-g9765caf-dsg-intel-nightly_4.3.0-rc2-dsg-11022-g9765caf-dsg-intel-nightly-7_amd64.deb <title>GuC</title> -!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC-specific firmware loader +!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC !Idrivers/gpu/drm/i915/intel_guc_loader.c </sect2> <sect2> <title>GuC Client</title> -!Pdrivers/gpu/drm/i915/i915_guc_submission.c GuC-based commandsubmissison
Review
Quoted 12 lines
Documentation/DocBook/drm.tmpl +6
-0+!Pdrivers/gpu/drm/i915/i915_guc_submission.c GuC Client !Idrivers/gpu/drm/i915/i915_guc_submission.c </sect2> + <sect2> + <title>GuC Firmware Layout</title> +!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC Firmware Layout +!Idrivers/gpu/drm/i915/intel_guc_loader.c + </sect2> </sect1> <sect1>(quoted diff) +0
-0
b/drivers/gpu/drm/i915/intel_guc.hReview
Quoted 20 lines
index 4ec2d27..e1389fc 100644
drivers/gpu/drm/i915/intel_guc.h +1
-1@@ -71,6 +71,7 @@ struct intel_guc_fw {struct drm_i915_gem_object * guc_fw_obj;enum intel_guc_fw_status guc_fw_fetch_status;enum intel_guc_fw_status guc_fw_load_status; +struct guc_css_header guc_fw_header;uint16_t guc_fw_major_wanted;uint16_t guc_fw_minor_wanted;@@ -80,7 +81,6 @@ struct intel_guc_fw {struct intel_guc {struct intel_guc_fw guc_fw; -uint32_t log_flags;struct drm_i915_gem_object *log_obj;(quoted diff) +0
-0
b/drivers/gpu/drm/i915/intel_guc_fwif.hdrivers/gpu/drm/i915/intel_guc_fwif.h line 127
Quoted 10 lines
index e1f47ba..006dc0d 100644
drivers/gpu/drm/i915/intel_guc_fwif.h +3
-0@@ -122,6 +122,42 @@#define GUC_CTL_MAX_DWORDS (GUC_CTL_RSRVD + 1) +struct guc_css_header { +uint32_t module_type; +uint32_t header_len;/* header length plus size of all other keys */
Review
Quoted 37 lines
drivers/gpu/drm/i915/intel_guc_fwif.h +33
-0+uint32_t header_version; +uint32_t module_id; +uint32_t module_vendor; +union { +struct { +uint8_t day; +uint8_t month; +uint16_t year; + }; +uint32_t date; + }; +uint32_t size;/* uCode size plus header_len */ +uint32_t key_size; +uint32_t modulus_size; +uint32_t exponent_size; +union { +struct { +uint8_t hour; +uint8_t min; +uint16_t sec; + }; +uint32_t time; + }; + +char username[8 ]; +char buildnumber[12 ]; +uint32_t device_id; +uint32_t guc_sw_version; +uint32_t prod_preprod_fw; +uint32_t reserved[12 ]; +uint32_t header_info; +} __packed; +struct guc_doorbell_info {u32 db_status;u32 cookie;(quoted diff) +0
-0
b/drivers/gpu/drm/i915/intel_guc_loader.cdrivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct
Quoted 4 lines
index 40241f3..a6703b4 100644
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0@@ -215,18 +215,29 @@ static inline bool guc_ucode_response(struct
drm_i915_private*dev_priv,drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 215
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0((val & GS_MIA_CORE_STATE) && uk_val ==
GS_UKERNEL_LAPIC_DONE));drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +0
-2} -/* -* Transfer the firmware image to RAM for execution by the microcontroller.
Quoted 18 lines
drivers/gpu/drm/i915/intel_guc_loader.c +8
-9+/** +* DOC: GuC Firmware Layout * -* GuC Firmware layout: -* +-------------------------------+ ---- -* | CSS header | 128B -* | contains major/minor version | -* +-------------------------------+ ---- -* | uCode | -* +-------------------------------+ ---- -* | RSA signature | 256B -* +-------------------------------+ ---- +* The GuC firmware layout looks like this: +* +* +-------------------------------+ +* | guc_css_header | +* | contains major/minor version | +* +-------------------------------+ drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 10 lines
drivers/gpu/drm/i915/intel_guc_loader.c +10
-0+* | uCode | +* +-------------------------------+ +* | RSA signature | +* +-------------------------------+ +* | modulus key | +* +-------------------------------+ +* | exponent val | +* +-------------------------------+ +* +* The firmware may or may not have modulus key and exponent data. The header,
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 237
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +1
-0+* uCode and RSA signature are must-have components that will be used by driver.
Quoted 8 lines
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 238
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +1
-0+* Size of each components (in dwords) can be found in header. In the case that
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 239
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +1
-0+* modulus and exponent are not present in fw, the size value still appears in
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, · line 240
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +1
-0+* header. I think this picture & commentary belongs just ahead of the structure definition in
intel_guc_fwif.h, rather than with the code here. Also,Yes, this can be moved to
intel_guc_fwif.hright beforecss_headerstructure definition.Quoted 3 lines
perhaps we nede a bit more explanation of the '*size' fields, since they have been defined in such a counter-intuitive way :( I suggest:
Quoted 7 lines
Quoted 4 lines
* All the 'sizes' in the CSS header are expressed as numbers of
* "dwords", and therefore have to be multiplied by sizeof (u32) to
* get actual sizes (in the normal sense of byte counts). *In comments, I clearly mention that all size of these guc components are in dwords. In next version, I can add surfix
_dwordto avoid confuse.
The names are systematically (if not yet automatically) derived from the GuC header version, so best not to change them. The comment *in the header file* will suffice.
Quoted 8 lines
Quoted 4 lines
* The 'size' field is the total size of the data in the picture
* above, and should match the size of the file as provided by the
* loader; the file is invalid if this size field is greater than
* the actual filesize.This is not right assumption. And, that will change some expectation below related to size checking. I should have make my comments more clear. But
OK, I see, we're going to allow a truncated image file, as long as only unused sections are missing ...
Quoted 41 lines
"The firmware may or may not have modulus key and exponent data ... In the case that modulus and exponent are not present in fw, the size value still appears in header."
We have discussed this with firmware team. Since the 'size' (actually the header) is used to generate RSA key, we can't change it after signing. So, we have information of modulus etc. but driver doesn't need them to load firmware. Likely they are not part of the release bin file. So the 'size' may be larger than the bin file size. Currently, fw check is based on the following rules (maybe I need add these to the comment too):
1. Header, uCode and RSA are must-have components.
2. All firmware components, if they present, are in the sequence illustrated in the layout table.
3. Size info of each component can be found in header, in dwords.
4. Modulus and exponent key are not required by driver. They may not appear in fw but their size info are recorded in header anyway.Quoted 13 lines
* The '
header_len' field contains the total size of the non-uCode
* sections of the file (i.e. the sum of the sizes of the CSS header,
* the RSA signature, the modulus key and the exponent). Thus, to find
* the size of the uCode we subtract this total from 'size', but to
* find the size of the CSS header (which also defines the start of
* the uCode), we subtract the other three sizes from this total. The
* size of the CSS header thus calculated should match sizeof(struct
*guc_css_header) (or exceed it; allowing it to be larger permits
* future expansion of the CSS header or insertion of extra sections
* here). The file is invalid if this calculated size is less than
*sizeof(struct guc_css_header).
*
* The size of the RSA signature must not exceed that expected by theQuoted 8 lines
* hardware. The file is invalid if the value of this field is more
* than the size of the signature area in the GuC register space,
* currently0x100bytes.
*
* Due to the requirements of the DMA engine, the total size of the
* sections that are DMA'd into the GuC's memory (CSS header plus
* uCode) must be a multiple of the cache line size. The file is
* invalid if this requirement is not met.
Quoted 7 lines
All suggestions above are valid at some points. However, be note that, the firmware size checking I put into code is actually to protect driver
- just make sure we don't have a bug check due to memory access violation. No matter how much protection you put into driver, you still can't reject the case by driver if someone modifies one byte of uCode. So, as long as we have the bits of header, uCode and RSA, we will load it. HW will fail it anyway if anything goes wrong.
All the checks I suggested were of this type. For example, the change from using UOS_RSA_SIG_SIZE to the calculated RSA-signature-size would have allowed a malformed file to trigger writing beyond the 256 bytes of signature-register space, with unpredictable effects.
Even if the trailing sections themselves have been removed from the image file, the assertions about the numerical relationships between the '*size' values in the CSS header remain valid and should be checked.
Quoted 47 lines
Quoted 34 lines
The rest of this comment can stay with the code ...
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 242
Quoted 2 lines
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0* * Architecturally, the DMA engine is bidirectional, and can potentially even
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 243
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0* transfer between GTT locations. This functionality is left out of the API
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0@@ -236,30 +247,42 @@ static inline bool guc_ucode_response(struct
drm_i915_private*dev_priv,drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 247
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0* DMA engine in one operation, whereas the RSA signature is loaded via MMIO.
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 10 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-6*/ -#define UOS_CSS_HEADER_OFFSET 0 -#define UOS_VER_MINOR_OFFSET 0x44 -#define UOS_VER_MAJOR_OFFSET 0x46 -#define UOS_CSS_HEADER_SIZE 0x80 -#define UOS_RSA_SIG_SIZE 0x100 - +/* +* Transfer the firmware image to RAM for execution by the microcontroller.
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, · line 261
Quoted 11 lines
drivers/gpu/drm/i915/intel_guc_loader.c +3
-1+*/ static int guc_ucode_xfer_dma (struct drm_i915_private *dev_priv) {struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw; +struct guc_css_header *header = &guc_fw->guc_fw_header;struct drm_i915_gem_object *fw_obj = guc_fw->guc_fw_obj;unsigned long offset;struct sg_table *sg = fw_obj->pages; -u32 status, ucode_size, rsa[UOS_RSA_SIG_SIZE /sizeof (u32)]; +u32 status, header_size, rsa_size, ucode_size, *rsa;int i, ret =0 ;Quoted 5 lines
I don't like doing the complicated size-based calculations in the DMA routine; I'd rather the important values (RSA start/size, CSS+uCode start/size) were precalculated during loading and saved in the struct
intel_guc_fwor a member thereof so that this code already has the exact numbers it needs without any further computation.This is a good point.
Quoted 5 lines
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +1
-3-/* uCode size, also is where RSA signature starts */ - offset = ucode_size = guc_fw->guc_fw_size -UOS_RSA_SIG_SIZE ; -I915_WRITE (DMA_COPY_SIZE , ucode_size); +/* The header plus uCode will be copied to WOPCM via DMA, excluding any
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, · line 274
Quoted 11 lines
drivers/gpu/drm/i915/intel_guc_loader.c +11
-0+* other components */ + header_size = (header->header_len - header->key_size - + header->modulus_size - header->exponent_size) *sizeof (u32); + ucode_size = (header->size - header->header_len) *sizeof (u32); + +I915_WRITE (DMA_COPY_SIZE , header_size + ucode_size); + +/* where RSA signature starts */ + offset = header_size + ucode_size; + + rsa_size = header->key_size *sizeof (u32);
(header->key_size might be, say, 0x80) => rsa_size is 0x200
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 6 lines
drivers/gpu/drm/i915/intel_guc_loader.c +3
-1+ rsa =kmalloc (rsa_size,GFP_KERNEL ); +if (!rsa) +return -ENOMEM ;/* Copy RSA signature from the fw image to HW for verification */ - sg_pcopy_to_buffer(sg->sgl, sg->nents, rsa, UOS_RSA_SIG_SIZE,offset);
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-1-for (i =0 ; i <UOS_RSA_SIG_SIZE /sizeof (u32); i++) +sg_pcopy_to_buffer (sg->sgl, sg->nents, rsa, rsa_size, offset); +for (i =0 ; i < rsa_size /sizeof (u32); i++)I915_WRITE (UOS_RSA_SCRATCH_0 + i *sizeof (u32), rsa[i]);
i*sizeof(u32) had better not exceed 0x100! OOPS!
Quoted 120 lines
Quoted 108 lines
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device
Quoted 7 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-0+kfree (rsa); +/* Set the source address for the new blob */ offset =i915_gem_obj_ggtt_offset (fw_obj);I915_WRITE (DMA_ADDR_0_LOW ,lower_32_bits (offset));@@ -465,10 +488,8 @@ static void guc_fw_fetch(struct drm_device*dev, struct
intel_guc_fw*guc_fw)drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 12 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-4{struct drm_i915_gem_object *obj;const struct firmware *fw; -const u8 *css_header; -const size_t minsize =UOS_CSS_HEADER_SIZE +UOS_RSA_SIG_SIZE ; -const size_t maxsize =GUC_WOPCM_SIZE_VALUE +UOS_RSA_SIG_SIZE - -0x8000 ;/* 32k reserved (8K stack + 24k context) */ +struct guc_css_header *css_header = &guc_fw->guc_fw_header; +size_t size;int err; DRM_DEBUG_DRIVER("before requesting firmware: GuC fw fetchstatus %s\n",
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0@@ -482,12 +503,31 @@ static void guc_fw_fetch(struct drm_device*dev, struct
intel_guc_fw*guc_fw)drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +0
-1DRM_DEBUG_DRIVER ("fetch GuC fw from %s succeeded, fw %p\n" , guc_fw->guc_fw_path, fw); - DRM_DEBUG_DRIVER("firmware file size %zu (minimum %zu, maximum%zu)\n",
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 13 lines
drivers/gpu/drm/i915/intel_guc_loader.c +9
-3- fw->size, minsize, maxsize); -/* Check the size of the blob befoe examining buffer contents */ -if (fw->size < minsize || fw->size > maxsize) +/* Check the size of the blob before examining buffer contents */ +if (fw->size <sizeof (struct guc_css_header )) { +DRM_ERROR ("Firmware header is missing\n" ); + goto fail; + } + +memcpy (css_header, fw->data,sizeof (struct guc_css_header )); + +/* At least, it should have header, uCode and RSA. Size of all three. */
Quoted 8 lines
drivers/gpu/drm/i915/intel_guc_loader.c +7
-0+ size = (css_header->size - css_header->modulus_size - + css_header->exponent_size) *sizeof (u32); +if (fw->size < size) { +DRM_ERROR ("Missing firmware components\n" ); goto fail; + } + +/* Header and uCode will be loaded to WOPCM. Size of the two. */ drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 10 lines
drivers/gpu/drm/i915/intel_guc_loader.c +7
-0+ size -= css_header->key_size *sizeof (u32); + +/* Top 32k of WOPCM is reserved (8K stack + 24k RC6 context). */ +if (size >GUC_WOPCM_SIZE_VALUE -0x8000 ) { +DRM_ERROR ("Firmware is too large to fit in WOPCM\n" ); + goto fail; + }/* * The GuC firmware image has the version number embedded at a well-known
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev,
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0@@ -495,9 +535,8 @@ static void guc_fw_fetch(struct drm_device *dev,struct
intel_guc_fw*guc_fw)drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, · line 535
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0* TWO bytes each (i.e. u16), although all pointers and offsets are defined
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +0
-2* in terms of bytes (u8). */ - css_header = fw->data +UOS_CSS_HEADER_OFFSET ; - guc_fw->guc_fw_major_found = *(u16 *)(css_header +
UOS_VER_MAJOR_OFFSET);drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, · line 500
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-1- guc_fw->guc_fw_minor_found = *(u16 *)(css_header +
UOS_VER_MINOR_OFFSET);drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw) · line 542
Quoted 6 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-0+ guc_fw->guc_fw_major_found = css_header->guc_sw_version >>16 ; + guc_fw->guc_fw_minor_found = css_header->guc_sw_version &0xFFFF ;if (guc_fw->guc_fw_major_found != guc_fw->guc_fw_major_wanted || guc_fw->guc_fw_minor_found < guc_fw->guc_fw_minor_wanted) {We need to validate each of the sizes read from the binary blob before using them in calculations, and we then also need to validate the results of the calculations, to prevent anyone spoofing the loader into writing where it shouldn't.
In particular, we need to check:
fw->size >= sizeof(struct guc_css_header) css_header->size (*4) <= fw->size css_header->header_len <= css_header->size => (uCode_size = css_header->size - css_header_len) >= 0 css_header->key_size (*4) <= HW_SIG_SIZE (0x100) css_header->key_size <= css_header->header_len css_header->modulus_size <= css_header->header_len css_header->exponent_size <= css_header->header_len css_header->header_len >= css_header->key_size + css_header->modulus_size + css_header->exponent_size; => (css_header_size = css_header->header_len - css_header->key_size - css_header->modulus_size - css_header->exponent_size) >= 0 css_header_size + uCode_size == 0 mod cachelinesize(Since all these sizes are unsigned, we can't (and don't need to) check for negative results from the subtractions, but we can check that each value that's defined as including the sum of other values is actually large enough so that the subtractions give meaningful results).
Quoted 4 lines
Some of these checks are already there, but I think we should complete all of them to catch any other invalid combinations of values. And then save the computed start/size values so the DMA code can just retrieve the precalculated values.
I only agree with check between header size and fw size. This allows driver keeps going without bug check. All others between members within
css_headerare not needed. The reason is simple. If you trust content ofcss_header, then you don't need to validate them. If you don't trust it, no need to check it anyway. Again, as long as we have enough bits to load to HW, we will let it go.
Quoted 2 lines
Thanks,
Alex
We can't trust the CSS header *unless* we validate it, in the sense of ensuring that bad values in it won't cause the driver to do anything it shouldn't (e.g. out of range accesses). For example, what happens if I set header_len to 0x100 and modulus_size to 0xfffffe00?
Only if it passes all our checks should we put it into GuC memory; and then the GuC gets the final word on whether it's good or not.
.Dave.
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v2 2/6] drm/i915/guc: Add GuC css header parser
Quoted 456 lines · Dave Gordon
Quoted 182 lines · Yu Dai
Quoted 164 lines · Dave Gordon
Quoted 11 lines · On 22/09/15 21:48, [email protected] wrote:
From: Alex Dai <[email protected]>
By using information from GuC css header, we can eliminate some hard code w.r.t size of some components of firmware.
v2: Add indent into DOC to make fixed-width format rather than change the tmpl.
v1: 1)
guc_css_headeris defined as__packednow
2) Add and correct GuC related topics in kernel/DocQuoted 6 lines
Signed-off-by Alex Dai <[email protected]>--- Documentation/DocBook/drm.tmpl | 9 ++- drivers/gpu/drm/i915/intel_guc.h | 2 +- drivers/gpu/drm/i915/intel_guc_fwif.h | 36 +++++++++++ drivers/gpu/drm/i915/intel_guc_loader.c | 107++++++++++++++++++++++----------
Review
Quoted 3 lines
4 files changed, 117 insertions(+), 37 deletions(-)(quoted diff) +0
-0b/Documentation/DocBook/drm.tmpl
Quoted 4 lines
index 66bc646..116332f 100644
Documentation/DocBook/drm.tmpl int num_ioctls;</synopsis> · line 4163
Quoted 10 lines
Documentation/DocBook/drm.tmpl +1
-2@@ -4155,14 +4155,19 @@ int num_ioctls;</synopsis> <title>GuC-based Command Submission</title> <sect2>../linux-image-4.3.0-rc2-dsg-11022-g9765caf-dsg-intel-nightly_4.3.0-rc2-dsg-11022-g9765caf-dsg-intel-nightly-7_amd64.deb <title>GuC</title> -!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC-specific firmware loader +!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC !Idrivers/gpu/drm/i915/intel_guc_loader.c </sect2> <sect2> <title>GuC Client</title> -!Pdrivers/gpu/drm/i915/i915_guc_submission.c GuC-based commandsubmissison
Review
Quoted 12 lines
Documentation/DocBook/drm.tmpl +6
-0+!Pdrivers/gpu/drm/i915/i915_guc_submission.c GuC Client !Idrivers/gpu/drm/i915/i915_guc_submission.c </sect2> + <sect2> + <title>GuC Firmware Layout</title> +!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC Firmware Layout +!Idrivers/gpu/drm/i915/intel_guc_loader.c + </sect2> </sect1> <sect1>(quoted diff) +0
-0
b/drivers/gpu/drm/i915/intel_guc.hReview
Quoted 20 lines
index 4ec2d27..e1389fc 100644
drivers/gpu/drm/i915/intel_guc.h +1
-1@@ -71,6 +71,7 @@ struct intel_guc_fw {struct drm_i915_gem_object * guc_fw_obj;enum intel_guc_fw_status guc_fw_fetch_status;enum intel_guc_fw_status guc_fw_load_status; +struct guc_css_header guc_fw_header;uint16_t guc_fw_major_wanted;uint16_t guc_fw_minor_wanted;@@ -80,7 +81,6 @@ struct intel_guc_fw {struct intel_guc {struct intel_guc_fw guc_fw; -uint32_t log_flags;struct drm_i915_gem_object *log_obj;(quoted diff) +0
-0
b/drivers/gpu/drm/i915/intel_guc_fwif.hdrivers/gpu/drm/i915/intel_guc_fwif.h line 127
Quoted 10 lines
index e1f47ba..006dc0d 100644
drivers/gpu/drm/i915/intel_guc_fwif.h +3
-0@@ -122,6 +122,42 @@#define GUC_CTL_MAX_DWORDS (GUC_CTL_RSRVD + 1) +struct guc_css_header { +uint32_t module_type; +uint32_t header_len;/* header length plus size of all other keys */
Review
Quoted 37 lines
drivers/gpu/drm/i915/intel_guc_fwif.h +33
-0+uint32_t header_version; +uint32_t module_id; +uint32_t module_vendor; +union { +struct { +uint8_t day; +uint8_t month; +uint16_t year; + }; +uint32_t date; + }; +uint32_t size;/* uCode size plus header_len */ +uint32_t key_size; +uint32_t modulus_size; +uint32_t exponent_size; +union { +struct { +uint8_t hour; +uint8_t min; +uint16_t sec; + }; +uint32_t time; + }; + +char username[8 ]; +char buildnumber[12 ]; +uint32_t device_id; +uint32_t guc_sw_version; +uint32_t prod_preprod_fw; +uint32_t reserved[12 ]; +uint32_t header_info; +} __packed; +struct guc_doorbell_info {u32 db_status;u32 cookie;(quoted diff) +0
-0
b/drivers/gpu/drm/i915/intel_guc_loader.cdrivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct
Quoted 4 lines
index 40241f3..a6703b4 100644
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0@@ -215,18 +215,29 @@ static inline bool guc_ucode_response(struct
drm_i915_private*dev_priv,drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 215
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0((val & GS_MIA_CORE_STATE) && uk_val ==
GS_UKERNEL_LAPIC_DONE));drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +0
-2} -/* -* Transfer the firmware image to RAM for execution by the microcontroller.
Quoted 18 lines
drivers/gpu/drm/i915/intel_guc_loader.c +8
-9+/** +* DOC: GuC Firmware Layout * -* GuC Firmware layout: -* +-------------------------------+ ---- -* | CSS header | 128B -* | contains major/minor version | -* +-------------------------------+ ---- -* | uCode | -* +-------------------------------+ ---- -* | RSA signature | 256B -* +-------------------------------+ ---- +* The GuC firmware layout looks like this: +* +* +-------------------------------+ +* | guc_css_header | +* | contains major/minor version | +* +-------------------------------+ drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 10 lines
drivers/gpu/drm/i915/intel_guc_loader.c +10
-0+* | uCode | +* +-------------------------------+ +* | RSA signature | +* +-------------------------------+ +* | modulus key | +* +-------------------------------+ +* | exponent val | +* +-------------------------------+ +* +* The firmware may or may not have modulus key and exponent data. The header,
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 237
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +1
-0+* uCode and RSA signature are must-have components that will be used by driver.
Quoted 8 lines
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 238
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +1
-0+* Size of each components (in dwords) can be found in header. In the case that
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 239
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +1
-0+* modulus and exponent are not present in fw, the size value still appears in
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, · line 240
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +1
-0+* header. I think this picture & commentary belongs just ahead of the structure definition in
intel_guc_fwif.h, rather than with the code here. Also,Yes, this can be moved to
intel_guc_fwif.hright beforecss_headerstructure definition.Quoted 3 lines
perhaps we nede a bit more explanation of the '*size' fields, since they have been defined in such a counter-intuitive way :( I suggest:
Quoted 7 lines
Quoted 4 lines
* All the 'sizes' in the CSS header are expressed as numbers of
* "dwords", and therefore have to be multiplied by sizeof (u32) to
* get actual sizes (in the normal sense of byte counts). *In comments, I clearly mention that all size of these guc components are in dwords. In next version, I can add surfix
_dwordto avoid confuse.The names are systematically (if not yet automatically) derived from the GuC header version, so best not to change them. The comment *in the header file* will suffice.
Quoted 8 lines
Quoted 4 lines
* The 'size' field is the total size of the data in the picture
* above, and should match the size of the file as provided by the
* loader; the file is invalid if this size field is greater than
* the actual filesize.This is not right assumption. And, that will change some expectation below related to size checking. I should have make my comments more clear. But
OK, I see, we're going to allow a truncated image file, as long as only unused sections are missing ...
Quoted 41 lines
"The firmware may or may not have modulus key and exponent data ... In the case that modulus and exponent are not present in fw, the size value still appears in header."
We have discussed this with firmware team. Since the 'size' (actually the header) is used to generate RSA key, we can't change it after signing. So, we have information of modulus etc. but driver doesn't need them to load firmware. Likely they are not part of the release bin file. So the 'size' may be larger than the bin file size. Currently, fw check is based on the following rules (maybe I need add these to the comment too):
1. Header, uCode and RSA are must-have components.
2. All firmware components, if they present, are in the sequence illustrated in the layout table.
3. Size info of each component can be found in header, in dwords.
4. Modulus and exponent key are not required by driver. They may not appear in fw but their size info are recorded in header anyway.Quoted 13 lines
* The '
header_len' field contains the total size of the non-uCode
* sections of the file (i.e. the sum of the sizes of the CSS header,
* the RSA signature, the modulus key and the exponent). Thus, to find
* the size of the uCode we subtract this total from 'size', but to
* find the size of the CSS header (which also defines the start of
* the uCode), we subtract the other three sizes from this total. The
* size of the CSS header thus calculated should match sizeof(struct
*guc_css_header) (or exceed it; allowing it to be larger permits
* future expansion of the CSS header or insertion of extra sections
* here). The file is invalid if this calculated size is less than
*sizeof(struct guc_css_header).
*
* The size of the RSA signature must not exceed that expected by theQuoted 8 lines
* hardware. The file is invalid if the value of this field is more
* than the size of the signature area in the GuC register space,
* currently0x100bytes.
*
* Due to the requirements of the DMA engine, the total size of the
* sections that are DMA'd into the GuC's memory (CSS header plus
* uCode) must be a multiple of the cache line size. The file is
* invalid if this requirement is not met.Quoted 7 lines
All suggestions above are valid at some points. However, be note that, the firmware size checking I put into code is actually to protect driver
- just make sure we don't have a bug check due to memory access violation. No matter how much protection you put into driver, you still can't reject the case by driver if someone modifies one byte of uCode. So, as long as we have the bits of header, uCode and RSA, we will load it. HW will fail it anyway if anything goes wrong.All the checks I suggested were of this type. For example, the change from using
UOS_RSA_SIG_SIZEto the calculated RSA-signature-size would have allowed a malformed file to trigger writing beyond the 256 bytes of signature-register space, with unpredictable effects.Even if the trailing sections themselves have been removed from the image file, the assertions about the numerical relationships between the '*size' values in the CSS header remain valid and should be checked.
Quoted 47 lines
Quoted 34 lines
The rest of this comment can stay with the code ...
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 242
Quoted 2 lines
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0* * Architecturally, the DMA engine is bidirectional, and can potentially even
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 243
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0* transfer between GTT locations. This functionality is left out of the API
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0@@ -236,30 +247,42 @@ static inline bool guc_ucode_response(struct
drm_i915_private*dev_priv,drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 247
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0* DMA engine in one operation, whereas the RSA signature is loaded via MMIO.
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 10 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-6*/ -#define UOS_CSS_HEADER_OFFSET 0 -#define UOS_VER_MINOR_OFFSET 0x44 -#define UOS_VER_MAJOR_OFFSET 0x46 -#define UOS_CSS_HEADER_SIZE 0x80 -#define UOS_RSA_SIG_SIZE 0x100 - +/* +* Transfer the firmware image to RAM for execution by the microcontroller.
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, · line 261
Quoted 11 lines
drivers/gpu/drm/i915/intel_guc_loader.c +3
-1+*/ static int guc_ucode_xfer_dma (struct drm_i915_private *dev_priv) {struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw; +struct guc_css_header *header = &guc_fw->guc_fw_header;struct drm_i915_gem_object *fw_obj = guc_fw->guc_fw_obj;unsigned long offset;struct sg_table *sg = fw_obj->pages; -u32 status, ucode_size, rsa[UOS_RSA_SIG_SIZE /sizeof (u32)]; +u32 status, header_size, rsa_size, ucode_size, *rsa;int i, ret =0 ;Quoted 5 lines
I don't like doing the complicated size-based calculations in the DMA routine; I'd rather the important values (RSA start/size, CSS+uCode start/size) were precalculated during loading and saved in the struct
intel_guc_fwor a member thereof so that this code already has the exact numbers it needs without any further computation.This is a good point.
Quoted 5 lines
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +1
-3-/* uCode size, also is where RSA signature starts */ - offset = ucode_size = guc_fw->guc_fw_size -UOS_RSA_SIG_SIZE ; -I915_WRITE (DMA_COPY_SIZE , ucode_size); +/* The header plus uCode will be copied to WOPCM via DMA, excluding any
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, · line 274
Quoted 11 lines
drivers/gpu/drm/i915/intel_guc_loader.c +11
-0+* other components */ + header_size = (header->header_len - header->key_size - + header->modulus_size - header->exponent_size) *sizeof (u32); + ucode_size = (header->size - header->header_len) *sizeof (u32); + +I915_WRITE (DMA_COPY_SIZE , header_size + ucode_size); + +/* where RSA signature starts */ + offset = header_size + ucode_size; + + rsa_size = header->key_size *sizeof (u32);(
header->key_sizemight be, say,0x80) =>rsa_sizeis0x200Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 6 lines
drivers/gpu/drm/i915/intel_guc_loader.c +3
-1+ rsa =kmalloc (rsa_size,GFP_KERNEL ); +if (!rsa) +return -ENOMEM ;/* Copy RSA signature from the fw image to HW for verification */ - sg_pcopy_to_buffer(sg->sgl, sg->nents, rsa, UOS_RSA_SIG_SIZE,offset);
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-1-for (i =0 ; i <UOS_RSA_SIG_SIZE /sizeof (u32); i++) +sg_pcopy_to_buffer (sg->sgl, sg->nents, rsa, rsa_size, offset); +for (i =0 ; i < rsa_size /sizeof (u32); i++)I915_WRITE (UOS_RSA_SCRATCH_0 + i *sizeof (u32), rsa[i]);i*sizeof(u32) had better not exceed
0x100! OOPS!Quoted 120 lines
Quoted 108 lines
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device
Quoted 7 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-0+kfree (rsa); +/* Set the source address for the new blob */ offset =i915_gem_obj_ggtt_offset (fw_obj);I915_WRITE (DMA_ADDR_0_LOW ,lower_32_bits (offset));@@ -465,10 +488,8 @@ static void guc_fw_fetch(struct drm_device*dev, struct
intel_guc_fw*guc_fw)drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 12 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-4{struct drm_i915_gem_object *obj;const struct firmware *fw; -const u8 *css_header; -const size_t minsize =UOS_CSS_HEADER_SIZE +UOS_RSA_SIG_SIZE ; -const size_t maxsize =GUC_WOPCM_SIZE_VALUE +UOS_RSA_SIG_SIZE - -0x8000 ;/* 32k reserved (8K stack + 24k context) */ +struct guc_css_header *css_header = &guc_fw->guc_fw_header; +size_t size;int err; DRM_DEBUG_DRIVER("before requesting firmware: GuC fw fetchstatus %s\n",
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0@@ -482,12 +503,31 @@ static void guc_fw_fetch(struct drm_device*dev, struct
intel_guc_fw*guc_fw)drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +0
-1DRM_DEBUG_DRIVER ("fetch GuC fw from %s succeeded, fw %p\n" , guc_fw->guc_fw_path, fw); - DRM_DEBUG_DRIVER("firmware file size %zu (minimum %zu, maximum%zu)\n",
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 13 lines
drivers/gpu/drm/i915/intel_guc_loader.c +9
-3- fw->size, minsize, maxsize); -/* Check the size of the blob befoe examining buffer contents */ -if (fw->size < minsize || fw->size > maxsize) +/* Check the size of the blob before examining buffer contents */ +if (fw->size <sizeof (struct guc_css_header )) { +DRM_ERROR ("Firmware header is missing\n" ); + goto fail; + } + +memcpy (css_header, fw->data,sizeof (struct guc_css_header )); + +/* At least, it should have header, uCode and RSA. Size of all three. */
Quoted 8 lines
drivers/gpu/drm/i915/intel_guc_loader.c +7
-0+ size = (css_header->size - css_header->modulus_size - + css_header->exponent_size) *sizeof (u32); +if (fw->size < size) { +DRM_ERROR ("Missing firmware components\n" ); goto fail; + } + +/* Header and uCode will be loaded to WOPCM. Size of the two. */ drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 10 lines
drivers/gpu/drm/i915/intel_guc_loader.c +7
-0+ size -= css_header->key_size *sizeof (u32); + +/* Top 32k of WOPCM is reserved (8K stack + 24k RC6 context). */ +if (size >GUC_WOPCM_SIZE_VALUE -0x8000 ) { +DRM_ERROR ("Firmware is too large to fit in WOPCM\n" ); + goto fail; + }/* * The GuC firmware image has the version number embedded at a well-known
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev,
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0@@ -495,9 +535,8 @@ static void guc_fw_fetch(struct drm_device *dev,struct
intel_guc_fw*guc_fw)drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, · line 535
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0* TWO bytes each (i.e. u16), although all pointers and offsets are defined
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +0
-2* in terms of bytes (u8). */ - css_header = fw->data +UOS_CSS_HEADER_OFFSET ; - guc_fw->guc_fw_major_found = *(u16 *)(css_header +
UOS_VER_MAJOR_OFFSET);drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, · line 500
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-1- guc_fw->guc_fw_minor_found = *(u16 *)(css_header +
UOS_VER_MINOR_OFFSET);drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw) · line 542
Quoted 6 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-0+ guc_fw->guc_fw_major_found = css_header->guc_sw_version >>16 ; + guc_fw->guc_fw_minor_found = css_header->guc_sw_version &0xFFFF ;if (guc_fw->guc_fw_major_found != guc_fw->guc_fw_major_wanted || guc_fw->guc_fw_minor_found < guc_fw->guc_fw_minor_wanted) {We need to validate each of the sizes read from the binary blob before using them in calculations, and we then also need to validate the results of the calculations, to prevent anyone spoofing the loader into writing where it shouldn't.
In particular, we need to check:
fw->size >= sizeof(struct guc_css_header) css_header->size (*4) <= fw->size css_header->header_len <= css_header->size => (uCode_size = css_header->size - css_header_len) >= 0 css_header->key_size (*4) <= HW_SIG_SIZE (0x100) css_header->key_size <= css_header->header_len css_header->modulus_size <= css_header->header_len css_header->exponent_size <= css_header->header_len css_header->header_len >= css_header->key_size + css_header->modulus_size + css_header->exponent_size; => (css_header_size = css_header->header_len - css_header->key_size - css_header->modulus_size - css_header->exponent_size) >= 0 css_header_size + uCode_size == 0 mod cachelinesize(Since all these sizes are unsigned, we can't (and don't need to) check for negative results from the subtractions, but we can check that each value that's defined as including the sum of other values is actually large enough so that the subtractions give meaningful results).
Quoted 4 lines
Some of these checks are already there, but I think we should complete all of them to catch any other invalid combinations of values. And then save the computed start/size values so the DMA code can just retrieve the precalculated values.
I only agree with check between header size and fw size. This allows driver keeps going without bug check. All others between members within
css_headerare not needed. The reason is simple. If you trust content ofcss_header, then you don't need to validate them. If you don't trust it, no need to check it anyway. Again, as long as we have enough bits to load to HW, we will let it go.
Quoted 8 lines
Quoted 2 lines
Thanks,
AlexWe can't trust the CSS header *unless* we validate it, in the sense of ensuring that bad values in it won't cause the driver to do anything it shouldn't (e.g. out of range accesses). For example, what happens if I set
header_lento0x100andmodulus_sizeto0xfffffe00?
We will use whatever provided from header to calculate uCode size and RSA offset etc. If all of them are within the bin file range, we will load it. Otherwise, reject it to avoid SW memory access violation. This is already implemented. My point is: if we can't trust the CSS header, then the check such as (css_header.A >= css_header.B - css_header.C) itself is insignificant. Yes, header data might be corrupted. HW will verify it as part of RSA key authentication anyway.
-Alex
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Jani Nikula
maintainerRe: [PATCH v2 2/6] drm/i915/guc: Add GuC css header parser
Quoted 466 lines · Yu Dai
Quoted 456 lines · Dave Gordon
Quoted 182 lines · Yu Dai
Quoted 164 lines · Dave Gordon
Quoted 11 lines · On 22/09/15 21:48, [email protected] wrote:
From: Alex Dai <[email protected]>
By using information from GuC css header, we can eliminate some hard code w.r.t size of some components of firmware.
v2: Add indent into DOC to make fixed-width format rather than change the tmpl.
v1: 1)
guc_css_headeris defined as__packednow
2) Add and correct GuC related topics in kernel/DocQuoted 6 lines
Signed-off-by Alex Dai <[email protected]>--- Documentation/DocBook/drm.tmpl | 9 ++- drivers/gpu/drm/i915/intel_guc.h | 2 +- drivers/gpu/drm/i915/intel_guc_fwif.h | 36 +++++++++++ drivers/gpu/drm/i915/intel_guc_loader.c | 107++++++++++++++++++++++----------
Review
Quoted 3 lines
4 files changed, 117 insertions(+), 37 deletions(-)(quoted diff) +0
-0b/Documentation/DocBook/drm.tmpl
Quoted 4 lines
index 66bc646..116332f 100644
Documentation/DocBook/drm.tmpl int num_ioctls;</synopsis> · line 4163
Quoted 10 lines
Documentation/DocBook/drm.tmpl +1
-2@@ -4155,14 +4155,19 @@ int num_ioctls;</synopsis> <title>GuC-based Command Submission</title> <sect2>../linux-image-4.3.0-rc2-dsg-11022-g9765caf-dsg-intel-nightly_4.3.0-rc2-dsg-11022-g9765caf-dsg-intel-nightly-7_amd64.deb <title>GuC</title> -!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC-specific firmware loader +!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC !Idrivers/gpu/drm/i915/intel_guc_loader.c </sect2> <sect2> <title>GuC Client</title> -!Pdrivers/gpu/drm/i915/i915_guc_submission.c GuC-based commandsubmissison
Review
Quoted 12 lines
Documentation/DocBook/drm.tmpl +6
-0+!Pdrivers/gpu/drm/i915/i915_guc_submission.c GuC Client !Idrivers/gpu/drm/i915/i915_guc_submission.c </sect2> + <sect2> + <title>GuC Firmware Layout</title> +!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC Firmware Layout +!Idrivers/gpu/drm/i915/intel_guc_loader.c + </sect2> </sect1> <sect1>(quoted diff) +0
-0
b/drivers/gpu/drm/i915/intel_guc.hReview
Quoted 20 lines
index 4ec2d27..e1389fc 100644
drivers/gpu/drm/i915/intel_guc.h +1
-1@@ -71,6 +71,7 @@ struct intel_guc_fw {struct drm_i915_gem_object * guc_fw_obj;enum intel_guc_fw_status guc_fw_fetch_status;enum intel_guc_fw_status guc_fw_load_status; +struct guc_css_header guc_fw_header;uint16_t guc_fw_major_wanted;uint16_t guc_fw_minor_wanted;@@ -80,7 +81,6 @@ struct intel_guc_fw {struct intel_guc {struct intel_guc_fw guc_fw; -uint32_t log_flags;struct drm_i915_gem_object *log_obj;(quoted diff) +0
-0
b/drivers/gpu/drm/i915/intel_guc_fwif.hdrivers/gpu/drm/i915/intel_guc_fwif.h line 127
Quoted 10 lines
index e1f47ba..006dc0d 100644
drivers/gpu/drm/i915/intel_guc_fwif.h +3
-0@@ -122,6 +122,42 @@#define GUC_CTL_MAX_DWORDS (GUC_CTL_RSRVD + 1) +struct guc_css_header { +uint32_t module_type; +uint32_t header_len;/* header length plus size of all other keys */
Review
Quoted 37 lines
drivers/gpu/drm/i915/intel_guc_fwif.h +33
-0+uint32_t header_version; +uint32_t module_id; +uint32_t module_vendor; +union { +struct { +uint8_t day; +uint8_t month; +uint16_t year; + }; +uint32_t date; + }; +uint32_t size;/* uCode size plus header_len */ +uint32_t key_size; +uint32_t modulus_size; +uint32_t exponent_size; +union { +struct { +uint8_t hour; +uint8_t min; +uint16_t sec; + }; +uint32_t time; + }; + +char username[8 ]; +char buildnumber[12 ]; +uint32_t device_id; +uint32_t guc_sw_version; +uint32_t prod_preprod_fw; +uint32_t reserved[12 ]; +uint32_t header_info; +} __packed; +struct guc_doorbell_info {u32 db_status;u32 cookie;(quoted diff) +0
-0
b/drivers/gpu/drm/i915/intel_guc_loader.cdrivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct
Quoted 4 lines
index 40241f3..a6703b4 100644
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0@@ -215,18 +215,29 @@ static inline bool guc_ucode_response(struct
drm_i915_private*dev_priv,drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 215
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0((val & GS_MIA_CORE_STATE) && uk_val ==
GS_UKERNEL_LAPIC_DONE));drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +0
-2} -/* -* Transfer the firmware image to RAM for execution by the microcontroller.
Quoted 18 lines
drivers/gpu/drm/i915/intel_guc_loader.c +8
-9+/** +* DOC: GuC Firmware Layout * -* GuC Firmware layout: -* +-------------------------------+ ---- -* | CSS header | 128B -* | contains major/minor version | -* +-------------------------------+ ---- -* | uCode | -* +-------------------------------+ ---- -* | RSA signature | 256B -* +-------------------------------+ ---- +* The GuC firmware layout looks like this: +* +* +-------------------------------+ +* | guc_css_header | +* | contains major/minor version | +* +-------------------------------+ drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 10 lines
drivers/gpu/drm/i915/intel_guc_loader.c +10
-0+* | uCode | +* +-------------------------------+ +* | RSA signature | +* +-------------------------------+ +* | modulus key | +* +-------------------------------+ +* | exponent val | +* +-------------------------------+ +* +* The firmware may or may not have modulus key and exponent data. The header,
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 237
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +1
-0+* uCode and RSA signature are must-have components that will be used by driver.
Quoted 8 lines
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 238
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +1
-0+* Size of each components (in dwords) can be found in header. In the case that
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 239
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +1
-0+* modulus and exponent are not present in fw, the size value still appears in
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, · line 240
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +1
-0+* header. I think this picture & commentary belongs just ahead of the structure definition in
intel_guc_fwif.h, rather than with the code here. Also,Yes, this can be moved to
intel_guc_fwif.hright beforecss_headerstructure definition.Quoted 3 lines
perhaps we nede a bit more explanation of the '*size' fields, since they have been defined in such a counter-intuitive way :( I suggest:
Quoted 7 lines
Quoted 4 lines
* All the 'sizes' in the CSS header are expressed as numbers of
* "dwords", and therefore have to be multiplied by sizeof (u32) to
* get actual sizes (in the normal sense of byte counts). *In comments, I clearly mention that all size of these guc components are in dwords. In next version, I can add surfix
_dwordto avoid confuse.The names are systematically (if not yet automatically) derived from the GuC header version, so best not to change them. The comment *in the header file* will suffice.
Quoted 8 lines
Quoted 4 lines
* The 'size' field is the total size of the data in the picture
* above, and should match the size of the file as provided by the
* loader; the file is invalid if this size field is greater than
* the actual filesize.This is not right assumption. And, that will change some expectation below related to size checking. I should have make my comments more clear. But
OK, I see, we're going to allow a truncated image file, as long as only unused sections are missing ...
Quoted 41 lines
"The firmware may or may not have modulus key and exponent data ... In the case that modulus and exponent are not present in fw, the size value still appears in header."
We have discussed this with firmware team. Since the 'size' (actually the header) is used to generate RSA key, we can't change it after signing. So, we have information of modulus etc. but driver doesn't need them to load firmware. Likely they are not part of the release bin file. So the 'size' may be larger than the bin file size. Currently, fw check is based on the following rules (maybe I need add these to the comment too):
1. Header, uCode and RSA are must-have components.
2. All firmware components, if they present, are in the sequence illustrated in the layout table.
3. Size info of each component can be found in header, in dwords.
4. Modulus and exponent key are not required by driver. They may not appear in fw but their size info are recorded in header anyway.Quoted 13 lines
* The '
header_len' field contains the total size of the non-uCode
* sections of the file (i.e. the sum of the sizes of the CSS header,
* the RSA signature, the modulus key and the exponent). Thus, to find
* the size of the uCode we subtract this total from 'size', but to
* find the size of the CSS header (which also defines the start of
* the uCode), we subtract the other three sizes from this total. The
* size of the CSS header thus calculated should match sizeof(struct
*guc_css_header) (or exceed it; allowing it to be larger permits
* future expansion of the CSS header or insertion of extra sections
* here). The file is invalid if this calculated size is less than
*sizeof(struct guc_css_header).
*
* The size of the RSA signature must not exceed that expected by theQuoted 8 lines
* hardware. The file is invalid if the value of this field is more
* than the size of the signature area in the GuC register space,
* currently0x100bytes.
*
* Due to the requirements of the DMA engine, the total size of the
* sections that are DMA'd into the GuC's memory (CSS header plus
* uCode) must be a multiple of the cache line size. The file is
* invalid if this requirement is not met.Quoted 7 lines
All suggestions above are valid at some points. However, be note that, the firmware size checking I put into code is actually to protect driver
- just make sure we don't have a bug check due to memory access violation. No matter how much protection you put into driver, you still can't reject the case by driver if someone modifies one byte of uCode. So, as long as we have the bits of header, uCode and RSA, we will load it. HW will fail it anyway if anything goes wrong.All the checks I suggested were of this type. For example, the change from using
UOS_RSA_SIG_SIZEto the calculated RSA-signature-size would have allowed a malformed file to trigger writing beyond the 256 bytes of signature-register space, with unpredictable effects.Even if the trailing sections themselves have been removed from the image file, the assertions about the numerical relationships between the '*size' values in the CSS header remain valid and should be checked.
Quoted 47 lines
Quoted 34 lines
The rest of this comment can stay with the code ...
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 242
Quoted 2 lines
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0* * Architecturally, the DMA engine is bidirectional, and can potentially even
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 243
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0* transfer between GTT locations. This functionality is left out of the API
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0@@ -236,30 +247,42 @@ static inline bool guc_ucode_response(struct
drm_i915_private*dev_priv,drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 247
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0* DMA engine in one operation, whereas the RSA signature is loaded via MMIO.
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 10 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-6*/ -#define UOS_CSS_HEADER_OFFSET 0 -#define UOS_VER_MINOR_OFFSET 0x44 -#define UOS_VER_MAJOR_OFFSET 0x46 -#define UOS_CSS_HEADER_SIZE 0x80 -#define UOS_RSA_SIG_SIZE 0x100 - +/* +* Transfer the firmware image to RAM for execution by the microcontroller.
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, · line 261
Quoted 11 lines
drivers/gpu/drm/i915/intel_guc_loader.c +3
-1+*/ static int guc_ucode_xfer_dma (struct drm_i915_private *dev_priv) {struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw; +struct guc_css_header *header = &guc_fw->guc_fw_header;struct drm_i915_gem_object *fw_obj = guc_fw->guc_fw_obj;unsigned long offset;struct sg_table *sg = fw_obj->pages; -u32 status, ucode_size, rsa[UOS_RSA_SIG_SIZE /sizeof (u32)]; +u32 status, header_size, rsa_size, ucode_size, *rsa;int i, ret =0 ;Quoted 5 lines
I don't like doing the complicated size-based calculations in the DMA routine; I'd rather the important values (RSA start/size, CSS+uCode start/size) were precalculated during loading and saved in the struct
intel_guc_fwor a member thereof so that this code already has the exact numbers it needs without any further computation.This is a good point.
Quoted 5 lines
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +1
-3-/* uCode size, also is where RSA signature starts */ - offset = ucode_size = guc_fw->guc_fw_size -UOS_RSA_SIG_SIZE ; -I915_WRITE (DMA_COPY_SIZE , ucode_size); +/* The header plus uCode will be copied to WOPCM via DMA, excluding any
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, · line 274
Quoted 11 lines
drivers/gpu/drm/i915/intel_guc_loader.c +11
-0+* other components */ + header_size = (header->header_len - header->key_size - + header->modulus_size - header->exponent_size) *sizeof (u32); + ucode_size = (header->size - header->header_len) *sizeof (u32); + +I915_WRITE (DMA_COPY_SIZE , header_size + ucode_size); + +/* where RSA signature starts */ + offset = header_size + ucode_size; + + rsa_size = header->key_size *sizeof (u32);(
header->key_sizemight be, say,0x80) =>rsa_sizeis0x200Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 6 lines
drivers/gpu/drm/i915/intel_guc_loader.c +3
-1+ rsa =kmalloc (rsa_size,GFP_KERNEL ); +if (!rsa) +return -ENOMEM ;/* Copy RSA signature from the fw image to HW for verification */ - sg_pcopy_to_buffer(sg->sgl, sg->nents, rsa, UOS_RSA_SIG_SIZE,offset);
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-1-for (i =0 ; i <UOS_RSA_SIG_SIZE /sizeof (u32); i++) +sg_pcopy_to_buffer (sg->sgl, sg->nents, rsa, rsa_size, offset); +for (i =0 ; i < rsa_size /sizeof (u32); i++)I915_WRITE (UOS_RSA_SCRATCH_0 + i *sizeof (u32), rsa[i]);i*sizeof(u32) had better not exceed
0x100! OOPS!Quoted 120 lines
Quoted 108 lines
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device
Quoted 7 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-0+kfree (rsa); +/* Set the source address for the new blob */ offset =i915_gem_obj_ggtt_offset (fw_obj);I915_WRITE (DMA_ADDR_0_LOW ,lower_32_bits (offset));@@ -465,10 +488,8 @@ static void guc_fw_fetch(struct drm_device*dev, struct
intel_guc_fw*guc_fw)drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 12 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-4{struct drm_i915_gem_object *obj;const struct firmware *fw; -const u8 *css_header; -const size_t minsize =UOS_CSS_HEADER_SIZE +UOS_RSA_SIG_SIZE ; -const size_t maxsize =GUC_WOPCM_SIZE_VALUE +UOS_RSA_SIG_SIZE - -0x8000 ;/* 32k reserved (8K stack + 24k context) */ +struct guc_css_header *css_header = &guc_fw->guc_fw_header; +size_t size;int err; DRM_DEBUG_DRIVER("before requesting firmware: GuC fw fetchstatus %s\n",
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0@@ -482,12 +503,31 @@ static void guc_fw_fetch(struct drm_device*dev, struct
intel_guc_fw*guc_fw)drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +0
-1DRM_DEBUG_DRIVER ("fetch GuC fw from %s succeeded, fw %p\n" , guc_fw->guc_fw_path, fw); - DRM_DEBUG_DRIVER("firmware file size %zu (minimum %zu, maximum%zu)\n",
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 13 lines
drivers/gpu/drm/i915/intel_guc_loader.c +9
-3- fw->size, minsize, maxsize); -/* Check the size of the blob befoe examining buffer contents */ -if (fw->size < minsize || fw->size > maxsize) +/* Check the size of the blob before examining buffer contents */ +if (fw->size <sizeof (struct guc_css_header )) { +DRM_ERROR ("Firmware header is missing\n" ); + goto fail; + } + +memcpy (css_header, fw->data,sizeof (struct guc_css_header )); + +/* At least, it should have header, uCode and RSA. Size of all three. */
Quoted 8 lines
drivers/gpu/drm/i915/intel_guc_loader.c +7
-0+ size = (css_header->size - css_header->modulus_size - + css_header->exponent_size) *sizeof (u32); +if (fw->size < size) { +DRM_ERROR ("Missing firmware components\n" ); goto fail; + } + +/* Header and uCode will be loaded to WOPCM. Size of the two. */ drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 10 lines
drivers/gpu/drm/i915/intel_guc_loader.c +7
-0+ size -= css_header->key_size *sizeof (u32); + +/* Top 32k of WOPCM is reserved (8K stack + 24k RC6 context). */ +if (size >GUC_WOPCM_SIZE_VALUE -0x8000 ) { +DRM_ERROR ("Firmware is too large to fit in WOPCM\n" ); + goto fail; + }/* * The GuC firmware image has the version number embedded at a well-known
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev,
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0@@ -495,9 +535,8 @@ static void guc_fw_fetch(struct drm_device *dev,struct
intel_guc_fw*guc_fw)drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, · line 535
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0* TWO bytes each (i.e. u16), although all pointers and offsets are defined
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +0
-2* in terms of bytes (u8). */ - css_header = fw->data +UOS_CSS_HEADER_OFFSET ; - guc_fw->guc_fw_major_found = *(u16 *)(css_header +
UOS_VER_MAJOR_OFFSET);drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, · line 500
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-1- guc_fw->guc_fw_minor_found = *(u16 *)(css_header +
UOS_VER_MINOR_OFFSET);drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw) · line 542
Quoted 6 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-0+ guc_fw->guc_fw_major_found = css_header->guc_sw_version >>16 ; + guc_fw->guc_fw_minor_found = css_header->guc_sw_version &0xFFFF ;if (guc_fw->guc_fw_major_found != guc_fw->guc_fw_major_wanted || guc_fw->guc_fw_minor_found < guc_fw->guc_fw_minor_wanted) {We need to validate each of the sizes read from the binary blob before using them in calculations, and we then also need to validate the results of the calculations, to prevent anyone spoofing the loader into writing where it shouldn't.
In particular, we need to check:
fw->size >= sizeof(struct guc_css_header) css_header->size (*4) <= fw->size css_header->header_len <= css_header->size => (uCode_size = css_header->size - css_header_len) >= 0 css_header->key_size (*4) <= HW_SIG_SIZE (0x100) css_header->key_size <= css_header->header_len css_header->modulus_size <= css_header->header_len css_header->exponent_size <= css_header->header_len css_header->header_len >= css_header->key_size + css_header->modulus_size + css_header->exponent_size; => (css_header_size = css_header->header_len - css_header->key_size - css_header->modulus_size - css_header->exponent_size) >= 0 css_header_size + uCode_size == 0 mod cachelinesize(Since all these sizes are unsigned, we can't (and don't need to) check for negative results from the subtractions, but we can check that each value that's defined as including the sum of other values is actually large enough so that the subtractions give meaningful results).
Quoted 4 lines
Some of these checks are already there, but I think we should complete all of them to catch any other invalid combinations of values. And then save the computed start/size values so the DMA code can just retrieve the precalculated values.
I only agree with check between header size and fw size. This allows driver keeps going without bug check. All others between members within
css_headerare not needed. The reason is simple. If you trust content ofcss_header, then you don't need to validate them. If you don't trust it, no need to check it anyway. Again, as long as we have enough bits to load to HW, we will let it go.Quoted 8 lines
Quoted 2 lines
Thanks,
AlexWe can't trust the CSS header *unless* we validate it, in the sense of ensuring that bad values in it won't cause the driver to do anything it shouldn't (e.g. out of range accesses). For example, what happens if I set
header_lento0x100andmodulus_sizeto0xfffffe00?
Quoted 7 lines
We will use whatever provided from header to calculate uCode size and RSA offset etc. If all of them are within the bin file range, we will load it. Otherwise, reject it to avoid SW memory access violation. This is already implemented. My point is: if we can't trust the CSS header, then the check such as (css_header.A >= css_header.B - css_header.C) itself is insignificant. Yes, header data might be corrupted. HW will verify it as part of RSA key authentication anyway.
I guess I was late to the party and commented on an old version [1]. But I'm with Dave here; you need to make sure nothing in kernel breaks with the data you read from the firmware blob.
It's not immediately obvious that you're safe when you write malicious data to DMA_COPY_SIZE, or you write out of bounds of UOS_RSA_SCRATCH_0, for example. You *must* make sure they are within sensible limits.
BR,
Jani.
[1] http://mid.gmane.org/[email protected]
Quoted 8 lines
-Alex
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v2 2/6] drm/i915/guc: Add GuC css header parser
Quoted 475 lines · Jani Nikula
Quoted 466 lines · Yu Dai
Quoted 456 lines · Dave Gordon
Quoted 182 lines · Yu Dai
Quoted 164 lines · Dave Gordon
Quoted 11 lines · On 22/09/15 21:48, [email protected] wrote:
From: Alex Dai <[email protected]>
By using information from GuC css header, we can eliminate some hard code w.r.t size of some components of firmware.
v2: Add indent into DOC to make fixed-width format rather than change the tmpl.
v1: 1)
guc_css_headeris defined as__packednow
2) Add and correct GuC related topics in kernel/DocQuoted 6 lines
Signed-off-by Alex Dai <[email protected]>--- Documentation/DocBook/drm.tmpl | 9 ++- drivers/gpu/drm/i915/intel_guc.h | 2 +- drivers/gpu/drm/i915/intel_guc_fwif.h | 36 +++++++++++ drivers/gpu/drm/i915/intel_guc_loader.c | 107++++++++++++++++++++++----------
Review
Quoted 3 lines
4 files changed, 117 insertions(+), 37 deletions(-)(quoted diff) +0
-0b/Documentation/DocBook/drm.tmpl
Quoted 4 lines
index 66bc646..116332f 100644
Documentation/DocBook/drm.tmpl int num_ioctls;</synopsis> · line 4163
Quoted 10 lines
Documentation/DocBook/drm.tmpl +1
-2@@ -4155,14 +4155,19 @@ int num_ioctls;</synopsis> <title>GuC-based Command Submission</title> <sect2>../linux-image-4.3.0-rc2-dsg-11022-g9765caf-dsg-intel-nightly_4.3.0-rc2-dsg-11022-g9765caf-dsg-intel-nightly-7_amd64.deb <title>GuC</title> -!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC-specific firmware loader +!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC !Idrivers/gpu/drm/i915/intel_guc_loader.c </sect2> <sect2> <title>GuC Client</title> -!Pdrivers/gpu/drm/i915/i915_guc_submission.c GuC-based commandsubmissison
Review
Quoted 12 lines
Documentation/DocBook/drm.tmpl +6
-0+!Pdrivers/gpu/drm/i915/i915_guc_submission.c GuC Client !Idrivers/gpu/drm/i915/i915_guc_submission.c </sect2> + <sect2> + <title>GuC Firmware Layout</title> +!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC Firmware Layout +!Idrivers/gpu/drm/i915/intel_guc_loader.c + </sect2> </sect1> <sect1>(quoted diff) +0
-0
b/drivers/gpu/drm/i915/intel_guc.hReview
Quoted 20 lines
index 4ec2d27..e1389fc 100644
drivers/gpu/drm/i915/intel_guc.h +1
-1@@ -71,6 +71,7 @@ struct intel_guc_fw {struct drm_i915_gem_object * guc_fw_obj;enum intel_guc_fw_status guc_fw_fetch_status;enum intel_guc_fw_status guc_fw_load_status; +struct guc_css_header guc_fw_header;uint16_t guc_fw_major_wanted;uint16_t guc_fw_minor_wanted;@@ -80,7 +81,6 @@ struct intel_guc_fw {struct intel_guc {struct intel_guc_fw guc_fw; -uint32_t log_flags;struct drm_i915_gem_object *log_obj;(quoted diff) +0
-0
b/drivers/gpu/drm/i915/intel_guc_fwif.hdrivers/gpu/drm/i915/intel_guc_fwif.h line 127
Quoted 10 lines
index e1f47ba..006dc0d 100644
drivers/gpu/drm/i915/intel_guc_fwif.h +3
-0@@ -122,6 +122,42 @@#define GUC_CTL_MAX_DWORDS (GUC_CTL_RSRVD + 1) +struct guc_css_header { +uint32_t module_type; +uint32_t header_len;/* header length plus size of all other keys */
Review
Quoted 37 lines
drivers/gpu/drm/i915/intel_guc_fwif.h +33
-0+uint32_t header_version; +uint32_t module_id; +uint32_t module_vendor; +union { +struct { +uint8_t day; +uint8_t month; +uint16_t year; + }; +uint32_t date; + }; +uint32_t size;/* uCode size plus header_len */ +uint32_t key_size; +uint32_t modulus_size; +uint32_t exponent_size; +union { +struct { +uint8_t hour; +uint8_t min; +uint16_t sec; + }; +uint32_t time; + }; + +char username[8 ]; +char buildnumber[12 ]; +uint32_t device_id; +uint32_t guc_sw_version; +uint32_t prod_preprod_fw; +uint32_t reserved[12 ]; +uint32_t header_info; +} __packed; +struct guc_doorbell_info {u32 db_status;u32 cookie;(quoted diff) +0
-0
b/drivers/gpu/drm/i915/intel_guc_loader.cdrivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct
Quoted 4 lines
index 40241f3..a6703b4 100644
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0@@ -215,18 +215,29 @@ static inline bool guc_ucode_response(struct
drm_i915_private*dev_priv,drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 215
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0((val & GS_MIA_CORE_STATE) && uk_val ==
GS_UKERNEL_LAPIC_DONE));drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +0
-2} -/* -* Transfer the firmware image to RAM for execution by the microcontroller.
Quoted 18 lines
drivers/gpu/drm/i915/intel_guc_loader.c +8
-9+/** +* DOC: GuC Firmware Layout * -* GuC Firmware layout: -* +-------------------------------+ ---- -* | CSS header | 128B -* | contains major/minor version | -* +-------------------------------+ ---- -* | uCode | -* +-------------------------------+ ---- -* | RSA signature | 256B -* +-------------------------------+ ---- +* The GuC firmware layout looks like this: +* +* +-------------------------------+ +* | guc_css_header | +* | contains major/minor version | +* +-------------------------------+ drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 10 lines
drivers/gpu/drm/i915/intel_guc_loader.c +10
-0+* | uCode | +* +-------------------------------+ +* | RSA signature | +* +-------------------------------+ +* | modulus key | +* +-------------------------------+ +* | exponent val | +* +-------------------------------+ +* +* The firmware may or may not have modulus key and exponent data. The header,
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 237
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +1
-0+* uCode and RSA signature are must-have components that will be used by driver.
Quoted 8 lines
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 238
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +1
-0+* Size of each components (in dwords) can be found in header. In the case that
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 239
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +1
-0+* modulus and exponent are not present in fw, the size value still appears in
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, · line 240
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +1
-0+* header. I think this picture & commentary belongs just ahead of the structure definition in
intel_guc_fwif.h, rather than with the code here. Also,Yes, this can be moved to
intel_guc_fwif.hright beforecss_headerstructure definition.Quoted 3 lines
perhaps we nede a bit more explanation of the '*size' fields, since they have been defined in such a counter-intuitive way :( I suggest:
Quoted 7 lines
Quoted 4 lines
* All the 'sizes' in the CSS header are expressed as numbers of
* "dwords", and therefore have to be multiplied by sizeof (u32) to
* get actual sizes (in the normal sense of byte counts). *In comments, I clearly mention that all size of these guc components are in dwords. In next version, I can add surfix
_dwordto avoid confuse.The names are systematically (if not yet automatically) derived from the GuC header version, so best not to change them. The comment *in the header file* will suffice.
Quoted 8 lines
Quoted 4 lines
* The 'size' field is the total size of the data in the picture
* above, and should match the size of the file as provided by the
* loader; the file is invalid if this size field is greater than
* the actual filesize.This is not right assumption. And, that will change some expectation below related to size checking. I should have make my comments more clear. But
OK, I see, we're going to allow a truncated image file, as long as only unused sections are missing ...
Quoted 41 lines
"The firmware may or may not have modulus key and exponent data ... In the case that modulus and exponent are not present in fw, the size value still appears in header."
We have discussed this with firmware team. Since the 'size' (actually the header) is used to generate RSA key, we can't change it after signing. So, we have information of modulus etc. but driver doesn't need them to load firmware. Likely they are not part of the release bin file. So the 'size' may be larger than the bin file size. Currently, fw check is based on the following rules (maybe I need add these to the comment too):
1. Header, uCode and RSA are must-have components.
2. All firmware components, if they present, are in the sequence illustrated in the layout table.
3. Size info of each component can be found in header, in dwords.
4. Modulus and exponent key are not required by driver. They may not appear in fw but their size info are recorded in header anyway.Quoted 13 lines
* The '
header_len' field contains the total size of the non-uCode
* sections of the file (i.e. the sum of the sizes of the CSS header,
* the RSA signature, the modulus key and the exponent). Thus, to find
* the size of the uCode we subtract this total from 'size', but to
* find the size of the CSS header (which also defines the start of
* the uCode), we subtract the other three sizes from this total. The
* size of the CSS header thus calculated should match sizeof(struct
*guc_css_header) (or exceed it; allowing it to be larger permits
* future expansion of the CSS header or insertion of extra sections
* here). The file is invalid if this calculated size is less than
*sizeof(struct guc_css_header).
*
* The size of the RSA signature must not exceed that expected by theQuoted 8 lines
* hardware. The file is invalid if the value of this field is more
* than the size of the signature area in the GuC register space,
* currently0x100bytes.
*
* Due to the requirements of the DMA engine, the total size of the
* sections that are DMA'd into the GuC's memory (CSS header plus
* uCode) must be a multiple of the cache line size. The file is
* invalid if this requirement is not met.Quoted 7 lines
All suggestions above are valid at some points. However, be note that, the firmware size checking I put into code is actually to protect driver
- just make sure we don't have a bug check due to memory access violation. No matter how much protection you put into driver, you still can't reject the case by driver if someone modifies one byte of uCode. So, as long as we have the bits of header, uCode and RSA, we will load it. HW will fail it anyway if anything goes wrong.All the checks I suggested were of this type. For example, the change from using
UOS_RSA_SIG_SIZEto the calculated RSA-signature-size would have allowed a malformed file to trigger writing beyond the 256 bytes of signature-register space, with unpredictable effects.Even if the trailing sections themselves have been removed from the image file, the assertions about the numerical relationships between the '*size' values in the CSS header remain valid and should be checked.
Quoted 47 lines
Quoted 34 lines
The rest of this comment can stay with the code ...
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 242
Quoted 2 lines
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0* * Architecturally, the DMA engine is bidirectional, and can potentially even
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 243
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0* transfer between GTT locations. This functionality is left out of the API
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0@@ -236,30 +247,42 @@ static inline bool guc_ucode_response(struct
drm_i915_private*dev_priv,drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct · line 247
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0* DMA engine in one operation, whereas the RSA signature is loaded via MMIO.
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 10 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-6*/ -#define UOS_CSS_HEADER_OFFSET 0 -#define UOS_VER_MINOR_OFFSET 0x44 -#define UOS_VER_MAJOR_OFFSET 0x46 -#define UOS_CSS_HEADER_SIZE 0x80 -#define UOS_RSA_SIG_SIZE 0x100 - +/* +* Transfer the firmware image to RAM for execution by the microcontroller.
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, · line 261
Quoted 11 lines
drivers/gpu/drm/i915/intel_guc_loader.c +3
-1+*/ static int guc_ucode_xfer_dma (struct drm_i915_private *dev_priv) {struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw; +struct guc_css_header *header = &guc_fw->guc_fw_header;struct drm_i915_gem_object *fw_obj = guc_fw->guc_fw_obj;unsigned long offset;struct sg_table *sg = fw_obj->pages; -u32 status, ucode_size, rsa[UOS_RSA_SIG_SIZE /sizeof (u32)]; +u32 status, header_size, rsa_size, ucode_size, *rsa;int i, ret =0 ;Quoted 5 lines
I don't like doing the complicated size-based calculations in the DMA routine; I'd rather the important values (RSA start/size, CSS+uCode start/size) were precalculated during loading and saved in the struct
intel_guc_fwor a member thereof so that this code already has the exact numbers it needs without any further computation.This is a good point.
Quoted 5 lines
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +1
-3-/* uCode size, also is where RSA signature starts */ - offset = ucode_size = guc_fw->guc_fw_size -UOS_RSA_SIG_SIZE ; -I915_WRITE (DMA_COPY_SIZE , ucode_size); +/* The header plus uCode will be copied to WOPCM via DMA, excluding any
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv, · line 274
Quoted 11 lines
drivers/gpu/drm/i915/intel_guc_loader.c +11
-0+* other components */ + header_size = (header->header_len - header->key_size - + header->modulus_size - header->exponent_size) *sizeof (u32); + ucode_size = (header->size - header->header_len) *sizeof (u32); + +I915_WRITE (DMA_COPY_SIZE , header_size + ucode_size); + +/* where RSA signature starts */ + offset = header_size + ucode_size; + + rsa_size = header->key_size *sizeof (u32);(
header->key_sizemight be, say,0x80) =>rsa_sizeis0x200Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/i915/intel_guc_loader.c static inline bool guc_ucode_response(struct drm_i915_private *dev_priv,
Quoted 6 lines
drivers/gpu/drm/i915/intel_guc_loader.c +3
-1+ rsa =kmalloc (rsa_size,GFP_KERNEL ); +if (!rsa) +return -ENOMEM ;/* Copy RSA signature from the fw image to HW for verification */ - sg_pcopy_to_buffer(sg->sgl, sg->nents, rsa, UOS_RSA_SIG_SIZE,offset);
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-1-for (i =0 ; i <UOS_RSA_SIG_SIZE /sizeof (u32); i++) +sg_pcopy_to_buffer (sg->sgl, sg->nents, rsa, rsa_size, offset); +for (i =0 ; i < rsa_size /sizeof (u32); i++)I915_WRITE (UOS_RSA_SCRATCH_0 + i *sizeof (u32), rsa[i]);i*sizeof(u32) had better not exceed
0x100! OOPS!Quoted 120 lines
Quoted 108 lines
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device
Quoted 7 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-0+kfree (rsa); +/* Set the source address for the new blob */ offset =i915_gem_obj_ggtt_offset (fw_obj);I915_WRITE (DMA_ADDR_0_LOW ,lower_32_bits (offset));@@ -465,10 +488,8 @@ static void guc_fw_fetch(struct drm_device*dev, struct
intel_guc_fw*guc_fw)drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 12 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-4{struct drm_i915_gem_object *obj;const struct firmware *fw; -const u8 *css_header; -const size_t minsize =UOS_CSS_HEADER_SIZE +UOS_RSA_SIG_SIZE ; -const size_t maxsize =GUC_WOPCM_SIZE_VALUE +UOS_RSA_SIG_SIZE - -0x8000 ;/* 32k reserved (8K stack + 24k context) */ +struct guc_css_header *css_header = &guc_fw->guc_fw_header; +size_t size;int err; DRM_DEBUG_DRIVER("before requesting firmware: GuC fw fetchstatus %s\n",
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0@@ -482,12 +503,31 @@ static void guc_fw_fetch(struct drm_device*dev, struct
intel_guc_fw*guc_fw)drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +0
-1DRM_DEBUG_DRIVER ("fetch GuC fw from %s succeeded, fw %p\n" , guc_fw->guc_fw_path, fw); - DRM_DEBUG_DRIVER("firmware file size %zu (minimum %zu, maximum%zu)\n",
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 13 lines
drivers/gpu/drm/i915/intel_guc_loader.c +9
-3- fw->size, minsize, maxsize); -/* Check the size of the blob befoe examining buffer contents */ -if (fw->size < minsize || fw->size > maxsize) +/* Check the size of the blob before examining buffer contents */ +if (fw->size <sizeof (struct guc_css_header )) { +DRM_ERROR ("Firmware header is missing\n" ); + goto fail; + } + +memcpy (css_header, fw->data,sizeof (struct guc_css_header )); + +/* At least, it should have header, uCode and RSA. Size of all three. */
Quoted 8 lines
drivers/gpu/drm/i915/intel_guc_loader.c +7
-0+ size = (css_header->size - css_header->modulus_size - + css_header->exponent_size) *sizeof (u32); +if (fw->size < size) { +DRM_ERROR ("Missing firmware components\n" ); goto fail; + } + +/* Header and uCode will be loaded to WOPCM. Size of the two. */ drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 10 lines
drivers/gpu/drm/i915/intel_guc_loader.c +7
-0+ size -= css_header->key_size *sizeof (u32); + +/* Top 32k of WOPCM is reserved (8K stack + 24k RC6 context). */ +if (size >GUC_WOPCM_SIZE_VALUE -0x8000 ) { +DRM_ERROR ("Firmware is too large to fit in WOPCM\n" ); + goto fail; + }/* * The GuC firmware image has the version number embedded at a well-known
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev,
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0@@ -495,9 +535,8 @@ static void guc_fw_fetch(struct drm_device *dev,struct
intel_guc_fw*guc_fw)drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, · line 535
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-0* TWO bytes each (i.e. u16), although all pointers and offsets are defined
drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw)
Quoted 4 lines
drivers/gpu/drm/i915/intel_guc_loader.c +0
-2* in terms of bytes (u8). */ - css_header = fw->data +UOS_CSS_HEADER_OFFSET ; - guc_fw->guc_fw_major_found = *(u16 *)(css_header +
UOS_VER_MAJOR_OFFSET);drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, · line 500
Quoted 1 line
drivers/gpu/drm/i915/intel_guc_loader.c +0
-1- guc_fw->guc_fw_minor_found = *(u16 *)(css_header +
UOS_VER_MINOR_OFFSET);drivers/gpu/drm/i915/intel_guc_loader.c static void guc_fw_fetch(struct drm_device *dev, struct intel_guc_fw *guc_fw) · line 542
Quoted 6 lines
drivers/gpu/drm/i915/intel_guc_loader.c +2
-0+ guc_fw->guc_fw_major_found = css_header->guc_sw_version >>16 ; + guc_fw->guc_fw_minor_found = css_header->guc_sw_version &0xFFFF ;if (guc_fw->guc_fw_major_found != guc_fw->guc_fw_major_wanted || guc_fw->guc_fw_minor_found < guc_fw->guc_fw_minor_wanted) {We need to validate each of the sizes read from the binary blob before using them in calculations, and we then also need to validate the results of the calculations, to prevent anyone spoofing the loader into writing where it shouldn't.
In particular, we need to check:
fw->size >= sizeof(struct guc_css_header) css_header->size (*4) <= fw->size css_header->header_len <= css_header->size => (uCode_size = css_header->size - css_header_len) >= 0 css_header->key_size (*4) <= HW_SIG_SIZE (0x100) css_header->key_size <= css_header->header_len css_header->modulus_size <= css_header->header_len css_header->exponent_size <= css_header->header_len css_header->header_len >= css_header->key_size + css_header->modulus_size + css_header->exponent_size; => (css_header_size = css_header->header_len - css_header->key_size - css_header->modulus_size - css_header->exponent_size) >= 0 css_header_size + uCode_size == 0 mod cachelinesize(Since all these sizes are unsigned, we can't (and don't need to) check for negative results from the subtractions, but we can check that each value that's defined as including the sum of other values is actually large enough so that the subtractions give meaningful results).
Quoted 4 lines
Some of these checks are already there, but I think we should complete all of them to catch any other invalid combinations of values. And then save the computed start/size values so the DMA code can just retrieve the precalculated values.
I only agree with check between header size and fw size. This allows driver keeps going without bug check. All others between members within
css_headerare not needed. The reason is simple. If you trust content ofcss_header, then you don't need to validate them. If you don't trust it, no need to check it anyway. Again, as long as we have enough bits to load to HW, we will let it go.Quoted 8 lines
Quoted 2 lines
Thanks,
AlexWe can't trust the CSS header *unless* we validate it, in the sense of ensuring that bad values in it won't cause the driver to do anything it shouldn't (e.g. out of range accesses). For example, what happens if I set
header_lento0x100andmodulus_sizeto0xfffffe00?Quoted 7 lines
We will use whatever provided from header to calculate uCode size and RSA offset etc. If all of them are within the bin file range, we will load it. Otherwise, reject it to avoid SW memory access violation. This is already implemented. My point is: if we can't trust the CSS header, then the check such as (css_header.A >= css_header.B - css_header.C) itself is insignificant. Yes, header data might be corrupted. HW will verify it as part of RSA key authentication anyway.
Quoted 8 lines
I guess I was late to the party and commented on an old version [1]. But I'm with Dave here; you need to make sure nothing in kernel breaks with the data you read from the firmware blob.
It's not immediately obvious that you're safe when you write malicious data to
DMA_COPY_SIZE, or you write out of bounds ofUOS_RSA_SCRATCH_0, for example. You *must* make sure they are within sensible limits.
Agree. I should have not used the word *trust*. What I mean is presume the data in header is correct, then calculate size / offset of all firmware ingredients based on that. If any of them is out of bound, driver will reject it. In the new version I am working on, the check related to sizes includes:
1. The fw blob should be larger than sizeof(css_header)
2. The header size should match sizeof(css_header)
3. The RSA length (in dwords) should match UOS_RSA_SCRATCH_MAX_COUNT (64). This is missing in previous patch. The number 64 (2048 bits) is from BSpec.
4. The fw blob should have header, ucode and rsa key.
Be note that I will use term *length* or *len* in header definition, which is in dwords unit. This is to avoid the confusion with *size*.
Thanks,
Alex
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v2 2/6] drm/i915/guc: Add GuC css header parser
Quoted 2 lines · Yu Dai
Be note that I will use term *length* or *len* in header definition, which is in dwords unit. This is to avoid the confusion with *size*.
lenght is also generally in bytes. If you want to use separate variables to avoid confusion I'd suggest num_dwords (treat it like an array of dwords) or size_dw (_dw as the unit suffix, like we do with e.g. _usec). -Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v2 3/6 drm/i915/guc: Add host2guc notification for suspend and resume
In reply to [email protected]From: Alex Dai <[email protected]>
Add host2guc interfaces to nofigy GuC power state changes when enter or resume from power saving state.
v1: Change to a more flexible way when fill host to GuC scratch data in order to remove hard coding.
--- drivers/gpu/drm/i915/i915_drv.c | 1 + drivers/gpu/drm/i915/i915_gem.c | 1 + drivers/gpu/drm/i915/i915_guc_submission.c | 50 ++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/intel_guc.h | 2 ++ drivers/gpu/drm/i915/intel_guc_fwif.h | 8 +++++ drivers/gpu/drm/i915/intel_guc_loader.c | 4 ++- 6 files changed, 65 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.c +1 -0
@@ -735,6 +735,7 @@ static int i915_drm_resume(struct drm_device *dev)DRM_ERROR ("failed to re-initialize GPU, declaring wedged!\n" );atomic_or (I915_WEDGED , &dev_priv->gpu_error.reset_counter); } +intel_guc_resume (dev);mutex_unlock (&dev->struct_mutex);intel_modeset_init_hw (dev);
drivers/gpu/drm/i915/i915_gem.c +1 -0
@@ -4458,6 +4458,7 @@ i915_gem_suspend(struct drm_device *dev)i915_gem_retire_requests (dev);i915_gem_stop_ringbuffers (dev); +intel_guc_suspend (dev);mutex_unlock (&dev->struct_mutex);cancel_delayed_work_sync (&dev_priv->gpu_error.hangcheck_work);
drivers/gpu/drm/i915/i915_guc_submission.c +50 -0
53 lines not on this page · raw message
drivers/gpu/drm/i915/intel_guc.h +2 -0
@@ -110,6 +110,8 @@ extern void intel_guc_ucode_init(struct drm_device *dev);extern int intel_guc_ucode_load (struct drm_device *dev);extern void intel_guc_ucode_fini (struct drm_device *dev);extern const char *intel_guc_fw_status_repr (enum intel_guc_fw_status status); +extern int intel_guc_suspend (struct drm_device *dev); +extern int intel_guc_resume (struct drm_device *dev);/* i915_guc_submission.c */ int i915_guc_submission_init (struct drm_device *dev);
drivers/gpu/drm/i915/intel_guc_fwif.h +8 -0
@@ -254,12 +254,20 @@ struct guc_context_desc {u64 desc_private; } __packed; +#define GUC_POWER_UNSPECIFIED 0 +#define GUC_POWER_D0 1 +#define GUC_POWER_D1 2 +#define GUC_POWER_D2 3 +#define GUC_POWER_D3 4 +/* This Action will be programmed in C180 - SOFT_SCRATCH_O_REG */ enum host2guc_action {HOST2GUC_ACTION_DEFAULT =0x0 ,HOST2GUC_ACTION_SAMPLE_FORCEWAKE =0x6 ,HOST2GUC_ACTION_ALLOCATE_DOORBELL =0x10 ,HOST2GUC_ACTION_DEALLOCATE_DOORBELL =0x20 , +HOST2GUC_ACTION_ENTER_S_STATE =0x501 , +HOST2GUC_ACTION_EXIT_S_STATE =0x502 ,HOST2GUC_ACTION_SLPC_REQUEST =0x3003 ,HOST2GUC_ACTION_LIMIT };
drivers/gpu/drm/i915/intel_guc_loader.c +3 -1
@@ -416,7 +416,6 @@ int intel_guc_ucode_load(struct drm_device *dev) intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));direct_interrupts_to_host (dev_priv); -i915_guc_submission_disable (dev);if (guc_fw->guc_fw_fetch_status ==GUC_FIRMWARE_NONE )return 0 ;
@@ -466,6 +465,9 @@ int intel_guc_ucode_load(struct drm_device *dev) intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));if (i915.enable_guc_submission) { +/* The execbuf_client will be recreated. Release it first. */ +i915_guc_submission_disable (dev); + err =i915_guc_submission_enable (dev);if (err) goto fail;
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v2 3/6] drm/i915/guc: Add host2guc notification for suspend and resume
Quoted 3 lines · On 9/23/2015 2:18 AM, [email protected] wrote:
From: Alex Dai <[email protected]>
Add host2guc interfaces to nofigy GuC power state changes when
*notify
Quoted 20 lines
enter or resume from power saving state.
v1: Change to a more flexible way when fill host to GuC scratch data in order to remove hard coding.
Signed-off-by Alex Dai <[email protected]>--- drivers/gpu/drm/i915/i915_drv.c | 1 + drivers/gpu/drm/i915/i915_gem.c | 1 + drivers/gpu/drm/i915/i915_guc_submission.c | 50 ++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/intel_guc.h | 2 ++ drivers/gpu/drm/i915/intel_guc_fwif.h | 8 +++++ drivers/gpu/drm/i915/intel_guc_loader.c | 4 ++- 6 files changed, 65 insertions(+), 1 deletion(-)drivers/gpu/drm/i915/i915_drv.c +0
-0
drivers/gpu/drm/i915/i915_drv.c static int i915_drm_resume(struct drm_device *dev) · line 738
Quoted 4 lines
drivers/gpu/drm/i915/i915_drv.c +1
-0@@ -735,6 +735,7 @@ static int i915_drm_resume(struct drm_device *dev)DRM_ERROR ("failed to re-initialize GPU, declaring wedged!\n" );atomic_or (I915_WEDGED , &dev_priv->gpu_error.reset_counter); } +intel_guc_resume (dev);
Need to call from intel_runtime_resume as well.
drivers/gpu/drm/i915/i915_gem.c i915_gem_suspend(struct drm_device *dev) · line 4461
Quoted 12 lines
drivers/gpu/drm/i915/i915_drv.c +0
-0mutex_unlock (&dev->struct_mutex);intel_modeset_init_hw (dev);drivers/gpu/drm/i915/i915_gem.c +1
-0@@ -4458,6 +4458,7 @@ i915_gem_suspend(struct drm_device *dev)i915_gem_retire_requests (dev);i915_gem_stop_ringbuffers (dev); +intel_guc_suspend (dev);
Should this be called as part of i915_drm_suspend for consistency? Need to call from intel_runtime_suspend as well.
Quoted 112 lines
drivers/gpu/drm/i915/i915_gem.c +0
-0mutex_unlock (&dev->struct_mutex);cancel_delayed_work_sync (&dev_priv->gpu_error.hangcheck_work);drivers/gpu/drm/i915/i915_guc_submission.c +50
-0@@ -914,3 +914,53 @@ void i915_guc_submission_fini(struct drm_device *dev)gem_release_guc_obj (guc->ctx_pool_obj); guc->ctx_pool_obj =NULL ; } + +/** +* intel_guc_suspend() - notify GuC entering suspend state +* @dev: drm device +*/ +int intel_guc_suspend (struct drm_device *dev) +{ +struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_guc *guc = &dev_priv->guc; +struct intel_context *ctx; +u32 data[3 ]; + +if (!i915.enable_guc_submission) +return 0 ; + + ctx = dev_priv->ring[RCS ].default_context; + + data[0 ] =HOST2GUC_ACTION_ENTER_S_STATE ; +/* any value greater than GUC_POWER_D0 */ + data[1 ] =GUC_POWER_D1 ; +/* first page is shared data with GuC */ + data[2 ] =i915_gem_obj_ggtt_offset (ctx->engine[RCS ].state); + +return host2guc_action (guc, data,ARRAY_SIZE (data)); +} + + +/** +* intel_guc_resume() - notify GuC resuming from suspend state +* @dev: drm device +*/ +int intel_guc_resume (struct drm_device *dev) +{ +struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_guc *guc = &dev_priv->guc; +struct intel_context *ctx; +u32 data[3 ]; + +if (!i915.enable_guc_submission) +return 0 ; + + ctx = dev_priv->ring[RCS ].default_context; + + data[0 ] =HOST2GUC_ACTION_EXIT_S_STATE ; + data[1 ] =GUC_POWER_D0 ; +/* first page is shared data with GuC */ + data[2 ] =i915_gem_obj_ggtt_offset (ctx->engine[RCS ].state); + +return host2guc_action (guc, data,ARRAY_SIZE (data)); +}drivers/gpu/drm/i915/intel_guc.h +2
-0@@ -110,6 +110,8 @@ extern void intel_guc_ucode_init(struct drm_device *dev);extern int intel_guc_ucode_load (struct drm_device *dev);extern void intel_guc_ucode_fini (struct drm_device *dev);extern const char *intel_guc_fw_status_repr (enum intel_guc_fw_status status); +extern int intel_guc_suspend (struct drm_device *dev); +extern int intel_guc_resume (struct drm_device *dev);/* i915_guc_submission.c */ int i915_guc_submission_init (struct drm_device *dev);drivers/gpu/drm/i915/intel_guc_fwif.h +8
-0@@ -254,12 +254,20 @@ struct guc_context_desc {u64 desc_private; } __packed; +#define GUC_POWER_UNSPECIFIED 0 +#define GUC_POWER_D0 1 +#define GUC_POWER_D1 2 +#define GUC_POWER_D2 3 +#define GUC_POWER_D3 4 +/* This Action will be programmed in C180 - SOFT_SCRATCH_O_REG */ enum host2guc_action {HOST2GUC_ACTION_DEFAULT =0x0 ,HOST2GUC_ACTION_SAMPLE_FORCEWAKE =0x6 ,HOST2GUC_ACTION_ALLOCATE_DOORBELL =0x10 ,HOST2GUC_ACTION_DEALLOCATE_DOORBELL =0x20 , +HOST2GUC_ACTION_ENTER_S_STATE =0x501 , +HOST2GUC_ACTION_EXIT_S_STATE =0x502 ,HOST2GUC_ACTION_SLPC_REQUEST =0x3003 ,HOST2GUC_ACTION_LIMIT };drivers/gpu/drm/i915/intel_guc_loader.c +0
-1@@ -416,7 +416,6 @@ int intel_guc_ucode_load(struct drm_device *dev) intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));direct_interrupts_to_host (dev_priv); -i915_guc_submission_disable (dev);if (guc_fw->guc_fw_fetch_status ==GUC_FIRMWARE_NONE )return 0 ;
drivers/gpu/drm/i915/intel_guc_loader.c int intel_guc_ucode_load(struct drm_device *dev) · line 473
Quoted 9 lines
drivers/gpu/drm/i915/intel_guc_loader.c +3
-0@@ -466,6 +465,9 @@ int intel_guc_ucode_load(struct drm_device *dev) intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));if (i915.enable_guc_submission) { +/* The execbuf_client will be recreated. Release it first. */ +i915_guc_submission_disable (dev); + err =i915_guc_submission_enable (dev);if (err) goto fail;
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v2 4/6 drm/i915/guc: Don't send flips to GuC
In reply to [email protected]From: Sagar Arun Kamble <[email protected]>
Due to flip interrupts GuC stays awake always and GT does not enter RC6. Do not route those interrupts to GuC for now. Driver won't touch DE_GUCRMR register and leave it as what default value.
--- drivers/gpu/drm/i915/intel_guc_loader.c | 10 ---------- 1 file changed, 10 deletions(-)
drivers/gpu/drm/i915/intel_guc_loader.c +0 -10
@@ -90,9 +90,6 @@ static void direct_interrupts_to_host(struct drm_i915_private *dev_priv)for_each_ring (ring, dev_priv, i)I915_WRITE (RING_MODE_GEN7 (ring), irqs); -/* tell DE to send nothing to GuC */ -I915_WRITE (DE_GUCRMR , ~0 ); -/* route all GT interrupts to the host */ I915_WRITE (GUC_BCS_RCS_IER ,0 );I915_WRITE (GUC_VCS2_VCS1_IER ,0 );
@@ -110,13 +107,6 @@ static void direct_interrupts_to_guc(struct drm_i915_private *dev_priv)for_each_ring (ring, dev_priv, i)I915_WRITE (RING_MODE_GEN7 (ring), irqs); -/* tell DE to send (all) flip_done to GuC */ - irqs =DERRMR_PIPEA_PRI_FLIP_DONE |DERRMR_PIPEA_SPR_FLIP_DONE | -DERRMR_PIPEB_PRI_FLIP_DONE |DERRMR_PIPEB_SPR_FLIP_DONE | -DERRMR_PIPEC_PRI_FLIP_DONE |DERRMR_PIPEC_SPR_FLIP_DONE ; -/* Unmasked bits will cause GuC response message to be sent */ -I915_WRITE (DE_GUCRMR , ~irqs); -/* route USER_INTERRUPT to Host, all others are sent to GuC. */ irqs =GT_RENDER_USER_INTERRUPT <<GEN8_RCS_IRQ_SHIFT |GT_RENDER_USER_INTERRUPT <<GEN8_BCS_IRQ_SHIFT ;
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 1/1 drm/i915/guc: Don't send flips to GuC
From: Sagar Arun Kamble <[email protected]>
Due to flip interrupts GuC stays awake always and GT does not enter RC6. Do not route those interrupts to GuC for now. Driver won't touch DE_GUCRMR register and leave it as what default value.
--- drivers/gpu/drm/i915/intel_guc_loader.c | 10 ---------- 1 file changed, 10 deletions(-)
drivers/gpu/drm/i915/intel_guc_loader.c +0 -10
@@ -90,9 +90,6 @@ static void direct_interrupts_to_host(struct drm_i915_private *dev_priv)for_each_ring (ring, dev_priv, i)I915_WRITE (RING_MODE_GEN7 (ring), irqs); -/* tell DE to send nothing to GuC */ -I915_WRITE (DE_GUCRMR , ~0 ); -/* route all GT interrupts to the host */ I915_WRITE (GUC_BCS_RCS_IER ,0 );I915_WRITE (GUC_VCS2_VCS1_IER ,0 );
@@ -110,13 +107,6 @@ static void direct_interrupts_to_guc(struct drm_i915_private *dev_priv)for_each_ring (ring, dev_priv, i)I915_WRITE (RING_MODE_GEN7 (ring), irqs); -/* tell DE to send (all) flip_done to GuC */ - irqs =DERRMR_PIPEA_PRI_FLIP_DONE |DERRMR_PIPEA_SPR_FLIP_DONE | -DERRMR_PIPEB_PRI_FLIP_DONE |DERRMR_PIPEB_SPR_FLIP_DONE | -DERRMR_PIPEC_PRI_FLIP_DONE |DERRMR_PIPEC_SPR_FLIP_DONE ; -/* Unmasked bits will cause GuC response message to be sent */ -I915_WRITE (DE_GUCRMR , ~irqs); -/* route USER_INTERRUPT to Host, all others are sent to GuC. */ irqs =GT_RENDER_USER_INTERRUPT <<GEN8_RCS_IRQ_SHIFT |GT_RENDER_USER_INTERRUPT <<GEN8_BCS_IRQ_SHIFT ;
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH] drm/i915/guc: Don't send flips to GuC
Quoted 8 lines · On Tue, Sep 22, 2015 at 04:11:48PM -0700, [email protected] wrote:
From: Sagar Arun Kamble <[email protected]>
Due to flip interrupts GuC stays awake always and GT does not enter RC6. Do not route those interrupts to GuC for now. Driver won't touch
DE_GUCRMRregister and leave it as what default value.Signed-off-by Sagar Arun Kamble <[email protected]>Signed-off-by Alex Dai <[email protected]>
Looks good to me.
Quoted 39 lines
--- drivers/gpu/drm/i915/intel_guc_loader.c | 10 ---------- 1 file changed, 10 deletions(-)drivers/gpu/drm/i915/intel_guc_loader.c +0
-10@@ -90,9 +90,6 @@ static void direct_interrupts_to_host(struct drm_i915_private *dev_priv)for_each_ring (ring, dev_priv, i)I915_WRITE (RING_MODE_GEN7 (ring), irqs); -/* tell DE to send nothing to GuC */ -I915_WRITE (DE_GUCRMR , ~0 ); -/* route all GT interrupts to the host */ I915_WRITE (GUC_BCS_RCS_IER ,0 );I915_WRITE (GUC_VCS2_VCS1_IER ,0 );@@ -110,13 +107,6 @@ static void direct_interrupts_to_guc(struct drm_i915_private *dev_priv)for_each_ring (ring, dev_priv, i)I915_WRITE (RING_MODE_GEN7 (ring), irqs); -/* tell DE to send (all) flip_done to GuC */ - irqs =DERRMR_PIPEA_PRI_FLIP_DONE |DERRMR_PIPEA_SPR_FLIP_DONE | -DERRMR_PIPEB_PRI_FLIP_DONE |DERRMR_PIPEB_SPR_FLIP_DONE | -DERRMR_PIPEC_PRI_FLIP_DONE |DERRMR_PIPEC_SPR_FLIP_DONE ; -/* Unmasked bits will cause GuC response message to be sent */ -I915_WRITE (DE_GUCRMR , ~irqs); -/* route USER_INTERRUPT to Host, all others are sent to GuC. */ irqs =GT_RENDER_USER_INTERRUPT <<GEN8_RCS_IRQ_SHIFT |GT_RENDER_USER_INTERRUPT <<GEN8_BCS_IRQ_SHIFT ;Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v2 5/6 drm/i915/guc: Media domain bit needed when notify GuC rc6 state
In reply to [email protected]From: Alex Dai <[email protected]>
GuC expects two bits for Render and Media domain separately when driver sends data via host2guc SAMPLE_FORCEWAKE. Bit 0 is for Render and bit 1 is for Media domain.
v1: Add parameters definition to avoid magic value
--- drivers/gpu/drm/i915/i915_guc_submission.c | 6 ++++-- drivers/gpu/drm/i915/intel_guc_fwif.h | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_guc_submission.c +4 -2
@@ -158,9 +158,11 @@ static int host2guc_sample_forcewake(struct intel_guc *guc,u32 data[2 ]; data[0 ] =HOST2GUC_ACTION_SAMPLE_FORCEWAKE ; - data[1 ] = (intel_enable_rc6 (dev_priv->dev)) ?1 :0 ; +/* bit 0 and 1 are for Render and Media domain separately */ + data[1 ] =intel_enable_rc6 (dev_priv->dev) ? +GUC_FORCEWAKE_RENDER |GUC_FORCEWAKE_MEDIA :0 ; -return host2guc_action (guc, data,2 ); +return host2guc_action (guc, data,ARRAY_SIZE (data)); }/*
drivers/gpu/drm/i915/intel_guc_fwif.h +3 -0
@@ -260,6 +260,9 @@ struct guc_context_desc {#define GUC_POWER_D2 3#define GUC_POWER_D3 4 +#define GUC_FORCEWAKE_RENDER (1 << 0) +#define GUC_FORCEWAKE_MEDIA (1 << 1) +/* This Action will be programmed in C180 - SOFT_SCRATCH_O_REG */ enum host2guc_action {HOST2GUC_ACTION_DEFAULT =0x0 ,
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v2 5/6] drm/i915/guc: Media domain bit needed when notify GuC rc6 state
Quoted 9 lines · On Tue, Sep 22, 2015 at 01:48:44PM -0700, [email protected] wrote:
From: Alex Dai <[email protected]>
GuC expects two bits for Render and Media domain separately when driver sends data via host2guc
SAMPLE_FORCEWAKE. Bit 0 is for Render and bit 1 is for Media domain.v1: Add parameters definition to avoid magic value
Signed-off-by Alex Dai <[email protected]>
Quoted 44 lines
--- drivers/gpu/drm/i915/i915_guc_submission.c | 6 ++++-- drivers/gpu/drm/i915/intel_guc_fwif.h | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/i915_guc_submission.c +4
-2@@ -158,9 +158,11 @@ static int host2guc_sample_forcewake(struct intel_guc *guc,u32 data[2 ]; data[0 ] =HOST2GUC_ACTION_SAMPLE_FORCEWAKE ; - data[1 ] = (intel_enable_rc6 (dev_priv->dev)) ?1 :0 ; +/* bit 0 and 1 are for Render and Media domain separately */ + data[1 ] =intel_enable_rc6 (dev_priv->dev) ? +GUC_FORCEWAKE_RENDER |GUC_FORCEWAKE_MEDIA :0 ; -return host2guc_action (guc, data,2 ); +return host2guc_action (guc, data,ARRAY_SIZE (data)); }/* drivers/gpu/drm/i915/intel_guc_fwif.h +3
-0@@ -260,6 +260,9 @@ struct guc_context_desc {#define GUC_POWER_D2 3#define GUC_POWER_D3 4 +#define GUC_FORCEWAKE_RENDER (1 << 0) +#define GUC_FORCEWAKE_MEDIA (1 << 1) +/* This Action will be programmed in C180 - SOFT_SCRATCH_O_REG */ enum host2guc_action {HOST2GUC_ACTION_DEFAULT =0x0 ,Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v2 5/6] drm/i915/guc: Media domain bit needed when notify GuC rc6 state
Quoted 7 lines · Tom
Quoted 6 lines · On Tue, Sep 22, 2015 at 01:48:44PM -0700, [email protected] wrote:
From: Alex Dai <[email protected]>
GuC expects two bits for Render and Media domain separately when driver sends data via host2guc
SAMPLE_FORCEWAKE. Bit 0 is for Render and bit 1 is for Media domain.
Quoted 5 lines
Quoted 3 lines
v1: Add parameters definition to avoid magic value
Signed-off-by Alex Dai <[email protected]>Reviewed-by Tom O'Rourke <Tom.O'[email protected]>
I'm lacking r-b for all but 2 patches in this series ... is that still ongoing?
-Daniel
Quoted 49 lines
Quoted 45 lines
--- drivers/gpu/drm/i915/i915_guc_submission.c | 6 ++++-- drivers/gpu/drm/i915/intel_guc_fwif.h | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/i915_guc_submission.c +4
-2@@ -158,9 +158,11 @@ static int host2guc_sample_forcewake(struct intel_guc *guc,u32 data[2 ]; data[0 ] =HOST2GUC_ACTION_SAMPLE_FORCEWAKE ; - data[1 ] = (intel_enable_rc6 (dev_priv->dev)) ?1 :0 ; +/* bit 0 and 1 are for Render and Media domain separately */ + data[1 ] =intel_enable_rc6 (dev_priv->dev) ? +GUC_FORCEWAKE_RENDER |GUC_FORCEWAKE_MEDIA :0 ; -return host2guc_action (guc, data,2 ); +return host2guc_action (guc, data,ARRAY_SIZE (data)); }/* drivers/gpu/drm/i915/intel_guc_fwif.h +3
-0@@ -260,6 +260,9 @@ struct guc_context_desc {#define GUC_POWER_D2 3#define GUC_POWER_D3 4 +#define GUC_FORCEWAKE_RENDER (1 << 0) +#define GUC_FORCEWAKE_MEDIA (1 << 1) +/* This Action will be programmed in C180 - SOFT_SCRATCH_O_REG */ enum host2guc_action {HOST2GUC_ACTION_DEFAULT =0x0 ,Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v2 6/6 drm/i915/guc: Enable GuC submission, where supported
In reply to [email protected]From: Dave Gordon <[email protected]>
This is to enable command submission via GuC.
--- drivers/gpu/drm/i915/i915_params.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_params.c +2 -2
@@ -52,7 +52,7 @@ struct i915_params i915 __read_mostly = { .verbose_state_checks = 1, .nuclear_pageflip = 0, .edp_vswing = 0, - .enable_guc_submission = false, + .enable_guc_submission = true, .guc_log_level = -1, };
@@ -185,7 +185,7 @@ MODULE_PARM_DESC(edp_vswing, "2=default swing(400mV))");module_param_named_unsafe (enable_guc_submission, i915.enable_guc_submission, bool,0400 ); -MODULE_PARM_DESC (enable_guc_submission,"Enable GuC submission (default:false)" ); +MODULE_PARM_DESC (enable_guc_submission,"Enable GuC submission (default:true)" );module_param_named (guc_log_level, i915.guc_log_level, int,0400 ); MODULE_PARM_DESC(guc_log_level,
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 1/1 drm/i915/guc: Enable GuC submission, where supported
From: Dave Gordon <[email protected]>
This is to enable command submission via GuC.
--- drivers/gpu/drm/i915/i915_params.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_params.c +2 -2
@@ -52,7 +52,7 @@ struct i915_params i915 __read_mostly = { .verbose_state_checks = 1, .nuclear_pageflip = 0, .edp_vswing = 0, - .enable_guc_submission = false, + .enable_guc_submission = true, .guc_log_level = -1, };
@@ -185,7 +185,7 @@ MODULE_PARM_DESC(edp_vswing, "2=default swing(400mV))");module_param_named_unsafe (enable_guc_submission, i915.enable_guc_submission, bool,0400 ); -MODULE_PARM_DESC (enable_guc_submission,"Enable GuC submission (default:false)" ); +MODULE_PARM_DESC (enable_guc_submission,"Enable GuC submission (default:true)" );module_param_named (guc_log_level, i915.guc_log_level, int,0400 ); MODULE_PARM_DESC(guc_log_level,
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx