From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Jordan Justen <jordan.l.justen@intel.com>,
intel-gfx <intel-gfx@lists.freedesktop.org>
Cc: dri-devel <dri-devel@lists.freedesktop.org>
Subject: Re: [Intel-gfx] [PATCH v5 4/4] drm/i915/guc: Verify hwconfig blob matches supported format
Date: Tue, 22 Feb 2022 11:24:07 +0000 [thread overview]
Message-ID: <4fcd914b-3360-b246-40d9-24f35679f702@linux.intel.com> (raw)
In-Reply-To: <20220222103640.1006006-5-jordan.l.justen@intel.com>
On 22/02/2022 10:36, Jordan Justen wrote:
> i915_drm.h now defines the format of the returned
> DRM_I915_QUERY_HWCONFIG_BLOB query item. Since i915 receives this from
> the black box GuC software, it should verify that the data matches
> that format before sending it to user-space.
>
> The verification makes a single simple pass through the blob contents,
> so this verification step should not add a significant amount of init
> time to i915.
>
> v3:
> * Add various changes suggested by Tvrtko
>
> v4:
> * Rewrite verify_hwconfig_blob() to hopefully be clearer without
> relying on comments so much, and add various suggestions from
> Michal.
>
> Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
> Acked-by: Jon Bloomfield <jon.bloomfield@intel.com>
> ---
> .../gpu/drm/i915/gt/uc/intel_guc_hwconfig.c | 44 ++++++++++++++++++-
> 1 file changed, 43 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_hwconfig.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_hwconfig.c
> index ad289603460c..a844b880cbdb 100644
> --- a/drivers/gpu/drm/i915/gt/uc/intel_guc_hwconfig.c
> +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_hwconfig.c
> @@ -73,9 +73,46 @@ static int guc_hwconfig_discover_size(struct intel_guc_hwconfig *hwconfig)
> return 0;
> }
>
> +static int verify_hwconfig_blob(struct intel_guc_hwconfig *hwconfig)
> +{
> + struct intel_guc *guc = hwconfig_to_guc(hwconfig);
> + struct drm_device *drm = &guc_to_gt(guc)->i915->drm;
> + struct drm_i915_query_hwconfig_blob_item *item = hwconfig->ptr;
> + u64 offset = 0;
> + u64 remaining = hwconfig->size;
> + /* Everything before the data field is required */
> + u64 min_item_size = offsetof(struct drm_i915_query_hwconfig_blob_item, data);
> + u64 item_size;
> +
> + if (!IS_ALIGNED(hwconfig->size, sizeof(u32))) {
> + drm_err(drm, "hwconfig blob size (%d) is not u32 aligned\n", hwconfig->size);
> + return -EINVAL;
> + }
> +
> + while (offset < hwconfig->size) {
> + if (remaining < min_item_size) {
> + drm_err(drm, "hwconfig blob invalid (no room for item required fields at offset %lld)\n",
> + offset);
> + return -EINVAL;
> + }
> + item_size = min_item_size + sizeof(u32) * item->length;
> + if (item_size > remaining) {
> + drm_err(drm, "hwconfig blob invalid (no room for data array of item at offset %lld)\n",
> + offset);
> + return -EINVAL;
> + }
> + offset += item_size;
> + remaining -= item_size;
> + item = (void *)&item->data[item->length];
> + }
> +
> + return 0;
> +}
> +
> static int guc_hwconfig_fill_buffer(struct intel_guc_hwconfig *hwconfig)
> {
> struct intel_guc *guc = hwconfig_to_guc(hwconfig);
> + struct drm_device *drm = &guc_to_gt(guc)->i915->drm;
> struct i915_vma *vma;
> u32 ggtt_offset;
> void *vaddr;
> @@ -90,8 +127,13 @@ static int guc_hwconfig_fill_buffer(struct intel_guc_hwconfig *hwconfig)
> ggtt_offset = intel_guc_ggtt_offset(guc, vma);
>
> ret = __guc_action_get_hwconfig(guc, ggtt_offset, hwconfig->size);
> - if (ret >= 0)
> + if (ret >= 0) {
> memcpy(hwconfig->ptr, vaddr, hwconfig->size);
> + if (verify_hwconfig_blob(hwconfig)) {
> + drm_err(drm, "Ignoring invalid hwconfig blob received from GuC!\n");
> + ret = -EINVAL;
> + }
> + }
>
> i915_vma_unpin_and_release(&vma, I915_VMA_RELEASE_MAP);
>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Regards,
Tvrtko
next prev parent reply other threads:[~2022-02-22 11:24 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-22 10:36 [Intel-gfx] [PATCH v5 0/4] GuC HWCONFIG with documentation Jordan Justen
2022-02-22 10:36 ` [Intel-gfx] [PATCH v5 1/4] drm/i915/guc: Add fetch of hwconfig table Jordan Justen
2022-02-24 13:58 ` Michal Wajdeczko
2022-02-25 2:17 ` John Harrison
2022-02-25 2:24 ` [Intel-gfx] [PATCH] " John.C.Harrison
2022-02-25 5:03 ` [Intel-gfx] [PATCH v5 1/4] " Jordan Justen
2022-02-25 9:44 ` Michal Wajdeczko
2022-02-25 13:26 ` Tvrtko Ursulin
2022-02-25 16:46 ` John Harrison
2022-02-25 17:18 ` Tvrtko Ursulin
2022-02-25 18:05 ` Michal Wajdeczko
2022-02-25 18:35 ` Tvrtko Ursulin
2022-02-22 10:36 ` [Intel-gfx] [PATCH v5 2/4] drm/i915/uapi: Add query for hwconfig blob Jordan Justen
2022-02-22 10:36 ` [Intel-gfx] [PATCH v5 3/4] drm/i915/uapi: Add struct drm_i915_query_hwconfig_blob_item Jordan Justen
2022-02-22 10:36 ` [Intel-gfx] [PATCH v5 4/4] drm/i915/guc: Verify hwconfig blob matches supported format Jordan Justen
2022-02-22 11:24 ` Tvrtko Ursulin [this message]
2022-02-22 11:28 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for GuC HWCONFIG with documentation (rev5) Patchwork
2022-02-22 11:29 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2022-02-22 12:03 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2022-02-25 2:07 ` John Harrison
2022-02-22 13:30 ` [Intel-gfx] ✓ Fi.CI.IGT: " Patchwork
2022-02-25 7:20 ` [Intel-gfx] ✗ Fi.CI.BUILD: failure for GuC HWCONFIG with documentation (rev6) Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4fcd914b-3360-b246-40d9-24f35679f702@linux.intel.com \
--to=tvrtko.ursulin@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jordan.l.justen@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox