From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: Ohad Sharabi <osharabi@habana.ai>,
"intel-xe@lists.freedesktop.org" <intel-xe@lists.freedesktop.org>
Subject: Re: [Intel-xe] [PATCH 1/4] drm/xe: Ensure that we don't access the placements array out-of-bounds
Date: Thu, 23 Nov 2023 15:32:28 +0100 [thread overview]
Message-ID: <5f627133-2312-fe24-2ebe-e3aa05387f3f@linux.intel.com> (raw)
In-Reply-To: <34f31f28-9095-e802-4243-e77eedb63cfc@habana.ai>
Hi, Ohad.
On 11/22/23 18:18, Ohad Sharabi wrote:
> On 22/11/2023 13:03, Thomas Hellström wrote:
>> Ensure, using xe_assert that the various try_add_<placement> functions
>> don't access the bo placements array out-of-bounds.
>>
>> Suggested-by: Ohad Sharabi <osharabi@habana.ai>
>> Link: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/946
>> Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Reviewed-by: Ohad Sharabi<osharabi@habana.ai>
Thanks for reviewing. I'll make a v2 of this patch according to Matthew
Auld's suggestion.
/Thomas
>
>> ---
>> drivers/gpu/drm/xe/xe_bo.c | 14 ++++++++++----
>> 1 file changed, 10 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
>> index 4305f5cbc2ab..915910b87faa 100644
>> --- a/drivers/gpu/drm/xe/xe_bo.c
>> +++ b/drivers/gpu/drm/xe/xe_bo.c
>> @@ -121,9 +121,11 @@ static struct xe_mem_region *res_to_mem_region(struct ttm_resource *res)
>> return to_xe_ttm_vram_mgr(mgr)->vram;
>> }
>>
>> -static void try_add_system(struct xe_bo *bo, struct ttm_place *places,
>> - u32 bo_flags, u32 *c)
>> +static void try_add_system(struct xe_device *xe, struct xe_bo *bo,
>> + struct ttm_place *places, u32 bo_flags, u32 *c)
>> {
>> + xe_assert(xe, *c < ARRAY_SIZE(bo->placements));
>> +
>> if (bo_flags & XE_BO_CREATE_SYSTEM_BIT) {
>> places[*c] = (struct ttm_place) {
>> .mem_type = XE_PL_TT,
>> @@ -172,6 +174,8 @@ static void add_vram(struct xe_device *xe, struct xe_bo *bo,
>> static void try_add_vram(struct xe_device *xe, struct xe_bo *bo,
>> struct ttm_place *places, u32 bo_flags, u32 *c)
>> {
>> + xe_assert(xe, *c < ARRAY_SIZE(bo->placements));
>> +
>> if (bo->props.preferred_gt == XE_GT1) {
>> if (bo_flags & XE_BO_CREATE_VRAM1_BIT)
>> add_vram(xe, bo, places, bo_flags, XE_PL_VRAM1, c);
>> @@ -188,6 +192,8 @@ static void try_add_vram(struct xe_device *xe, struct xe_bo *bo,
>> static void try_add_stolen(struct xe_device *xe, struct xe_bo *bo,
>> struct ttm_place *places, u32 bo_flags, u32 *c)
>> {
>> + xe_assert(xe, *c < ARRAY_SIZE(bo->placements));
>> +
>> if (bo_flags & XE_BO_CREATE_STOLEN_BIT) {
>> places[*c] = (struct ttm_place) {
>> .mem_type = XE_PL_STOLEN,
>> @@ -210,11 +216,11 @@ static int __xe_bo_placement_for_flags(struct xe_device *xe, struct xe_bo *bo,
>> /* The order of placements should indicate preferred location */
>>
>> if (bo->props.preferred_mem_class == DRM_XE_MEM_REGION_CLASS_SYSMEM) {
>> - try_add_system(bo, places, bo_flags, &c);
>> + try_add_system(xe, bo, places, bo_flags, &c);
>> try_add_vram(xe, bo, places, bo_flags, &c);
>> } else {
>> try_add_vram(xe, bo, places, bo_flags, &c);
>> - try_add_system(bo, places, bo_flags, &c);
>> + try_add_system(xe, bo, places, bo_flags, &c);
>> }
>> try_add_stolen(xe, bo, places, bo_flags, &c);
>>
next prev parent reply other threads:[~2023-11-23 14:32 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-22 11:03 [Intel-xe] [PATCH 0/4] drm/xe: Assorted memory-management fixes Thomas Hellström
2023-11-22 11:03 ` [Intel-xe] [PATCH 1/4] drm/xe: Ensure that we don't access the placements array out-of-bounds Thomas Hellström
2023-11-22 12:20 ` Matthew Auld
2023-11-23 14:30 ` Thomas Hellström
2023-11-22 17:18 ` Ohad Sharabi
2023-11-23 14:32 ` Thomas Hellström [this message]
2023-11-22 11:03 ` [Intel-xe] [PATCH 2/4] drm/xe/bo: Rename xe_bo_get_sg() to xe_bo_sg() Thomas Hellström
2023-11-22 12:21 ` Matthew Auld
2023-11-22 17:19 ` Ohad Sharabi
2023-11-22 11:03 ` [Intel-xe] [PATCH 3/4] drm/xe/bo: Remove leftover trace_printk() Thomas Hellström
2023-11-22 12:22 ` Matthew Auld
2023-11-22 17:19 ` Ohad Sharabi
2023-11-22 11:03 ` [Intel-xe] [PATCH 4/4] drm/xe/vm: Fix ASID XA usage Thomas Hellström
2023-11-22 12:35 ` Matthew Auld
2023-11-22 17:23 ` Ohad Sharabi
2023-11-22 13:32 ` [Intel-xe] ✓ CI.Patch_applied: success for drm/xe: Assorted memory-management fixes Patchwork
2023-11-22 13:32 ` [Intel-xe] ✓ CI.checkpatch: " Patchwork
2023-11-22 13:34 ` [Intel-xe] ✓ CI.KUnit: " Patchwork
2023-11-22 13:41 ` [Intel-xe] ✓ CI.Build: " Patchwork
2023-11-22 13:41 ` [Intel-xe] ✓ CI.Hooks: " Patchwork
2023-11-22 13:43 ` [Intel-xe] ✓ CI.checksparse: " Patchwork
2023-11-23 10:09 ` [Intel-xe] ✓ CI.Patch_applied: " Patchwork
2023-11-23 10:10 ` [Intel-xe] ✓ CI.checkpatch: " Patchwork
2023-11-23 10:11 ` [Intel-xe] ✓ CI.KUnit: " Patchwork
2023-11-23 10:18 ` [Intel-xe] ✓ CI.Build: " Patchwork
2023-11-23 10:19 ` [Intel-xe] ✓ CI.Hooks: " Patchwork
2023-11-23 10:20 ` [Intel-xe] ✓ CI.checksparse: " Patchwork
2023-11-23 10:58 ` [Intel-xe] ✓ CI.BAT: " 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=5f627133-2312-fe24-2ebe-e3aa05387f3f@linux.intel.com \
--to=thomas.hellstrom@linux.intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=osharabi@habana.ai \
/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