From: Andrzej Hajda <andrzej.hajda@intel.com>
To: Matthew Auld <matthew.auld@intel.com>, intel-gfx@lists.freedesktop.org
Cc: Chris Wilson <chris.p.wilson@intel.com>,
stable@vger.kernel.org, Nirmoy Das <nirmoy.das@intel.com>
Subject: Re: [Intel-gfx] [PATCH v2 1/2] drm/i915/migrate: Account for the reserved_space
Date: Tue, 6 Dec 2022 13:46:13 +0100 [thread overview]
Message-ID: <453dda8d-ffba-9352-df99-74b7bcc6a860@intel.com> (raw)
In-Reply-To: <20221118135723.621653-1-matthew.auld@intel.com>
On 18.11.2022 14:57, Matthew Auld wrote:
> From: Chris Wilson <chris.p.wilson@intel.com>
>
> If the ring is nearly full when calling into emit_pte(), we might
> incorrectly trample the reserved_space when constructing the packet to
> emit the PTEs. This then triggers the GEM_BUG_ON(rq->reserved_space >
> ring->space) when later submitting the request, since the request itself
> doesn't have enough space left in the ring to emit things like
> workarounds, breadcrumbs etc.
>
> Testcase: igt@i915_selftests@live_emit_pte_full_ring
> Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/7535
> Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/6889
> Fixes: cf586021642d ("drm/i915/gt: Pipelined page migration")
> Signed-off-by: Chris Wilson <chris.p.wilson@intel.com>
> Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> Cc: Andrzej Hajda <andrzej.hajda@intel.com>
> Cc: Nirmoy Das <nirmoy.das@intel.com>
> Cc: <stable@vger.kernel.org> # v5.15+
> ---
> drivers/gpu/drm/i915/gt/intel_migrate.c | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gt/intel_migrate.c b/drivers/gpu/drm/i915/gt/intel_migrate.c
> index b405a04135ca..48c3b5168558 100644
> --- a/drivers/gpu/drm/i915/gt/intel_migrate.c
> +++ b/drivers/gpu/drm/i915/gt/intel_migrate.c
> @@ -342,6 +342,16 @@ static int emit_no_arbitration(struct i915_request *rq)
> return 0;
> }
>
> +static int max_pte_pkt_size(struct i915_request *rq, int pkt)
> +{
> + struct intel_ring *ring = rq->ring;
> +
> + pkt = min_t(int, pkt, (ring->space - rq->reserved_space) / sizeof(u32) + 5);
> + pkt = min_t(int, pkt, (ring->size - ring->emit) / sizeof(u32) + 5);
> +
> + return pkt;
> +}
> +
I guess, the assumption that subtractions of u32 values do not
overflows, is valid.
Then I guess more natural would be use u32 for all vars involved, this
way we can use min instead of min_t, minor nit.
Anyway:
Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com>
Regards
Andrzej
> static int emit_pte(struct i915_request *rq,
> struct sgt_dma *it,
> enum i915_cache_level cache_level,
> @@ -388,8 +398,7 @@ static int emit_pte(struct i915_request *rq,
> return PTR_ERR(cs);
>
> /* Pack as many PTE updates as possible into a single MI command */
> - pkt = min_t(int, dword_length, ring->space / sizeof(u32) + 5);
> - pkt = min_t(int, pkt, (ring->size - ring->emit) / sizeof(u32) + 5);
> + pkt = max_pte_pkt_size(rq, dword_length);
>
> hdr = cs;
> *cs++ = MI_STORE_DATA_IMM | REG_BIT(21); /* as qword elements */
> @@ -422,8 +431,7 @@ static int emit_pte(struct i915_request *rq,
> }
> }
>
> - pkt = min_t(int, dword_rem, ring->space / sizeof(u32) + 5);
> - pkt = min_t(int, pkt, (ring->size - ring->emit) / sizeof(u32) + 5);
> + pkt = max_pte_pkt_size(rq, dword_rem);
>
> hdr = cs;
> *cs++ = MI_STORE_DATA_IMM | REG_BIT(21);
prev parent reply other threads:[~2022-12-06 12:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-18 13:57 [Intel-gfx] [PATCH v2 1/2] drm/i915/migrate: Account for the reserved_space Matthew Auld
2022-11-18 13:57 ` [Intel-gfx] [PATCH v2 2/2] drm/i915/selftests: exercise emit_pte() with nearly full ring Matthew Auld
2022-11-18 14:33 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for series starting with [v2,1/2] drm/i915/migrate: Account for the reserved_space Patchwork
2022-11-18 14:58 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork
2022-12-06 12:46 ` Andrzej Hajda [this message]
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=453dda8d-ffba-9352-df99-74b7bcc6a860@intel.com \
--to=andrzej.hajda@intel.com \
--cc=chris.p.wilson@intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=matthew.auld@intel.com \
--cc=nirmoy.das@intel.com \
--cc=stable@vger.kernel.org \
/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