All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Auld <matthew.auld@intel.com>
To: Arunpravin <arunpravin.paneerselvam@amd.com>,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	intel-gfx@lists.freedesktop.org
Cc: alexander.deucher@amd.com, christian.koenig@amd.com
Subject: Re: [PATCH] drm: remove min_order BUG_ON check
Date: Tue, 8 Mar 2022 17:01:54 +0000	[thread overview]
Message-ID: <8909011e-d18b-03cd-aeb5-bae10db41a00@intel.com> (raw)
In-Reply-To: <1ff8a246-8df9-c098-302c-f73b4425ccbf@amd.com>

On 08/03/2022 13:59, Arunpravin wrote:
> 
> 
> On 07/03/22 10:11 pm, Matthew Auld wrote:
>> On 07/03/2022 14:37, Arunpravin wrote:
>>> place BUG_ON(order < min_order) outside do..while
>>> loop as it fails Unigine Heaven benchmark.
>>>
>>> Unigine Heaven has buffer allocation requests for
>>> example required pages are 161 and alignment request
>>> is 128. To allocate the remaining 33 pages, continues
>>> the iteration to find the order value which is 5 and
>>> when it compares with min_order = 7, enables the
>>> BUG_ON(). To avoid this problem, placed the BUG_ON
>>> check outside of do..while loop.
>>>
>>> Signed-off-by: Arunpravin <Arunpravin.PaneerSelvam@amd.com>
>>> ---
>>>    drivers/gpu/drm/drm_buddy.c | 3 ++-
>>>    1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
>>> index 72f52f293249..ed94c56b720f 100644
>>> --- a/drivers/gpu/drm/drm_buddy.c
>>> +++ b/drivers/gpu/drm/drm_buddy.c
>>> @@ -669,10 +669,11 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm,
>>>    	order = fls(pages) - 1;
>>>    	min_order = ilog2(min_page_size) - ilog2(mm->chunk_size);
>>>    
>>> +	BUG_ON(order < min_order);
>>
>> Isn't the issue that we are allowing a size that is not aligned to the
>> requested min_page_size? Should we not fix the caller(and throw a normal
>> error here), or perhaps add the round_up() here instead?
>>
> CASE 1:
> when size is not aligned to the requested min_page_size, for instance,
> required size = 161 pages, min_page_size = 128 pages, here we have 3
> possible options,
> a. AFAIK,This kind of situation is common in any workload,the first
> allocation (i.e) 128 pages is aligned to min_page_size, Should we just
> allocate the left over 33 pages (2 pow 5, 2 pow 0) since the caller does
> know the left over pages are not in min_page_size alignment?

So IIUC looking at amdgpu_gem_create_ioctl(), userspace can specify some 
arbitrary physical alignment for an object? Is that not meant to apply 
to every page/chunk? The above example would only have the correct 
physical alignment guaranteed for the first chunk, or so, is this the 
expected ABI behaviour?

Also looking at this some more, the other related bug here is the 
order-- == min_order check, since it now won't bail when order == 0, 
leading to order = -1, if we are unlucky...

Originally, if asking for min_page_size > chunk_size, then the 
allocation was meant to fail if it can't fill the resource request with 
pages of at least that size(and also alignment). Or at least that was 
the original meaning in i915 IIRC.

> 
> b. There are many such instances in unigine heaven workload (there would
> be many such workloads), throwing a normal error would lower the FPS? is
> it possible to fix at caller application?
> 
> c. adding the round_up() is possible, but in every such instances we end
> up allocating extra unused memory. For example, if required pages = 1028
> and min_page_size = 1024 pages, we end up round up of left over 4 pages
> to the min_page_size, so the total size would be 2048 pages.
> 
>> i.e if someone does:
>>
>> alloc_blocks(mm, 0, end, 4096, 1<<16, &blocks, flags);
> CASE 2:
> I think this case should be detected (i.e) when min_page_size > size,
> should we return -EINVAL?
>>
>> This will still trigger the BUG_ON() even if we move it out of the loop,
>> AFAICT.
>>
> 
> Should we just allow the CASE 1 proceed for the allocation and return
> -EINVAL for the CASE 2?
> 
>>> +
>>>    	do {
>>>    		order = min(order, (unsigned int)fls(pages) - 1);
>>>    		BUG_ON(order > mm->max_order);
>>> -		BUG_ON(order < min_order);
>>>    
>>>    		do {
>>>    			if (flags & DRM_BUDDY_RANGE_ALLOCATION)
>>>
>>> base-commit: 8025c79350b90e5a8029234d433578f12abbae2b

WARNING: multiple messages have this Message-ID (diff)
From: Matthew Auld <matthew.auld@intel.com>
To: Arunpravin <arunpravin.paneerselvam@amd.com>,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	intel-gfx@lists.freedesktop.org
Cc: alexander.deucher@amd.com, christian.koenig@amd.com
Subject: Re: [Intel-gfx] [PATCH] drm: remove min_order BUG_ON check
Date: Tue, 8 Mar 2022 17:01:54 +0000	[thread overview]
Message-ID: <8909011e-d18b-03cd-aeb5-bae10db41a00@intel.com> (raw)
In-Reply-To: <1ff8a246-8df9-c098-302c-f73b4425ccbf@amd.com>

On 08/03/2022 13:59, Arunpravin wrote:
> 
> 
> On 07/03/22 10:11 pm, Matthew Auld wrote:
>> On 07/03/2022 14:37, Arunpravin wrote:
>>> place BUG_ON(order < min_order) outside do..while
>>> loop as it fails Unigine Heaven benchmark.
>>>
>>> Unigine Heaven has buffer allocation requests for
>>> example required pages are 161 and alignment request
>>> is 128. To allocate the remaining 33 pages, continues
>>> the iteration to find the order value which is 5 and
>>> when it compares with min_order = 7, enables the
>>> BUG_ON(). To avoid this problem, placed the BUG_ON
>>> check outside of do..while loop.
>>>
>>> Signed-off-by: Arunpravin <Arunpravin.PaneerSelvam@amd.com>
>>> ---
>>>    drivers/gpu/drm/drm_buddy.c | 3 ++-
>>>    1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
>>> index 72f52f293249..ed94c56b720f 100644
>>> --- a/drivers/gpu/drm/drm_buddy.c
>>> +++ b/drivers/gpu/drm/drm_buddy.c
>>> @@ -669,10 +669,11 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm,
>>>    	order = fls(pages) - 1;
>>>    	min_order = ilog2(min_page_size) - ilog2(mm->chunk_size);
>>>    
>>> +	BUG_ON(order < min_order);
>>
>> Isn't the issue that we are allowing a size that is not aligned to the
>> requested min_page_size? Should we not fix the caller(and throw a normal
>> error here), or perhaps add the round_up() here instead?
>>
> CASE 1:
> when size is not aligned to the requested min_page_size, for instance,
> required size = 161 pages, min_page_size = 128 pages, here we have 3
> possible options,
> a. AFAIK,This kind of situation is common in any workload,the first
> allocation (i.e) 128 pages is aligned to min_page_size, Should we just
> allocate the left over 33 pages (2 pow 5, 2 pow 0) since the caller does
> know the left over pages are not in min_page_size alignment?

So IIUC looking at amdgpu_gem_create_ioctl(), userspace can specify some 
arbitrary physical alignment for an object? Is that not meant to apply 
to every page/chunk? The above example would only have the correct 
physical alignment guaranteed for the first chunk, or so, is this the 
expected ABI behaviour?

Also looking at this some more, the other related bug here is the 
order-- == min_order check, since it now won't bail when order == 0, 
leading to order = -1, if we are unlucky...

Originally, if asking for min_page_size > chunk_size, then the 
allocation was meant to fail if it can't fill the resource request with 
pages of at least that size(and also alignment). Or at least that was 
the original meaning in i915 IIRC.

> 
> b. There are many such instances in unigine heaven workload (there would
> be many such workloads), throwing a normal error would lower the FPS? is
> it possible to fix at caller application?
> 
> c. adding the round_up() is possible, but in every such instances we end
> up allocating extra unused memory. For example, if required pages = 1028
> and min_page_size = 1024 pages, we end up round up of left over 4 pages
> to the min_page_size, so the total size would be 2048 pages.
> 
>> i.e if someone does:
>>
>> alloc_blocks(mm, 0, end, 4096, 1<<16, &blocks, flags);
> CASE 2:
> I think this case should be detected (i.e) when min_page_size > size,
> should we return -EINVAL?
>>
>> This will still trigger the BUG_ON() even if we move it out of the loop,
>> AFAICT.
>>
> 
> Should we just allow the CASE 1 proceed for the allocation and return
> -EINVAL for the CASE 2?
> 
>>> +
>>>    	do {
>>>    		order = min(order, (unsigned int)fls(pages) - 1);
>>>    		BUG_ON(order > mm->max_order);
>>> -		BUG_ON(order < min_order);
>>>    
>>>    		do {
>>>    			if (flags & DRM_BUDDY_RANGE_ALLOCATION)
>>>
>>> base-commit: 8025c79350b90e5a8029234d433578f12abbae2b

WARNING: multiple messages have this Message-ID (diff)
From: Matthew Auld <matthew.auld@intel.com>
To: Arunpravin <arunpravin.paneerselvam@amd.com>,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	intel-gfx@lists.freedesktop.org
Cc: alexander.deucher@amd.com, christian.koenig@amd.com, daniel@ffwll.ch
Subject: Re: [PATCH] drm: remove min_order BUG_ON check
Date: Tue, 8 Mar 2022 17:01:54 +0000	[thread overview]
Message-ID: <8909011e-d18b-03cd-aeb5-bae10db41a00@intel.com> (raw)
In-Reply-To: <1ff8a246-8df9-c098-302c-f73b4425ccbf@amd.com>

On 08/03/2022 13:59, Arunpravin wrote:
> 
> 
> On 07/03/22 10:11 pm, Matthew Auld wrote:
>> On 07/03/2022 14:37, Arunpravin wrote:
>>> place BUG_ON(order < min_order) outside do..while
>>> loop as it fails Unigine Heaven benchmark.
>>>
>>> Unigine Heaven has buffer allocation requests for
>>> example required pages are 161 and alignment request
>>> is 128. To allocate the remaining 33 pages, continues
>>> the iteration to find the order value which is 5 and
>>> when it compares with min_order = 7, enables the
>>> BUG_ON(). To avoid this problem, placed the BUG_ON
>>> check outside of do..while loop.
>>>
>>> Signed-off-by: Arunpravin <Arunpravin.PaneerSelvam@amd.com>
>>> ---
>>>    drivers/gpu/drm/drm_buddy.c | 3 ++-
>>>    1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
>>> index 72f52f293249..ed94c56b720f 100644
>>> --- a/drivers/gpu/drm/drm_buddy.c
>>> +++ b/drivers/gpu/drm/drm_buddy.c
>>> @@ -669,10 +669,11 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm,
>>>    	order = fls(pages) - 1;
>>>    	min_order = ilog2(min_page_size) - ilog2(mm->chunk_size);
>>>    
>>> +	BUG_ON(order < min_order);
>>
>> Isn't the issue that we are allowing a size that is not aligned to the
>> requested min_page_size? Should we not fix the caller(and throw a normal
>> error here), or perhaps add the round_up() here instead?
>>
> CASE 1:
> when size is not aligned to the requested min_page_size, for instance,
> required size = 161 pages, min_page_size = 128 pages, here we have 3
> possible options,
> a. AFAIK,This kind of situation is common in any workload,the first
> allocation (i.e) 128 pages is aligned to min_page_size, Should we just
> allocate the left over 33 pages (2 pow 5, 2 pow 0) since the caller does
> know the left over pages are not in min_page_size alignment?

So IIUC looking at amdgpu_gem_create_ioctl(), userspace can specify some 
arbitrary physical alignment for an object? Is that not meant to apply 
to every page/chunk? The above example would only have the correct 
physical alignment guaranteed for the first chunk, or so, is this the 
expected ABI behaviour?

Also looking at this some more, the other related bug here is the 
order-- == min_order check, since it now won't bail when order == 0, 
leading to order = -1, if we are unlucky...

Originally, if asking for min_page_size > chunk_size, then the 
allocation was meant to fail if it can't fill the resource request with 
pages of at least that size(and also alignment). Or at least that was 
the original meaning in i915 IIRC.

> 
> b. There are many such instances in unigine heaven workload (there would
> be many such workloads), throwing a normal error would lower the FPS? is
> it possible to fix at caller application?
> 
> c. adding the round_up() is possible, but in every such instances we end
> up allocating extra unused memory. For example, if required pages = 1028
> and min_page_size = 1024 pages, we end up round up of left over 4 pages
> to the min_page_size, so the total size would be 2048 pages.
> 
>> i.e if someone does:
>>
>> alloc_blocks(mm, 0, end, 4096, 1<<16, &blocks, flags);
> CASE 2:
> I think this case should be detected (i.e) when min_page_size > size,
> should we return -EINVAL?
>>
>> This will still trigger the BUG_ON() even if we move it out of the loop,
>> AFAICT.
>>
> 
> Should we just allow the CASE 1 proceed for the allocation and return
> -EINVAL for the CASE 2?
> 
>>> +
>>>    	do {
>>>    		order = min(order, (unsigned int)fls(pages) - 1);
>>>    		BUG_ON(order > mm->max_order);
>>> -		BUG_ON(order < min_order);
>>>    
>>>    		do {
>>>    			if (flags & DRM_BUDDY_RANGE_ALLOCATION)
>>>
>>> base-commit: 8025c79350b90e5a8029234d433578f12abbae2b

  reply	other threads:[~2022-03-08 17:04 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-07 14:37 [PATCH] drm: remove min_order BUG_ON check Arunpravin
2022-03-07 14:37 ` Arunpravin
2022-03-07 14:37 ` [Intel-gfx] " Arunpravin
2022-03-07 14:45 ` Jani Nikula
2022-03-08 14:32   ` Arunpravin
2022-03-07 15:04 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for " Patchwork
2022-03-07 15:36 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2022-03-07 15:53 ` [PATCH] " Christian König
2022-03-07 15:53   ` Christian König
2022-03-07 15:53   ` [Intel-gfx] " Christian König
2022-03-08 14:27   ` Arunpravin
2022-03-08 14:27     ` Arunpravin
2022-03-08 14:27     ` [Intel-gfx] " Arunpravin
2022-03-07 16:41 ` Matthew Auld
2022-03-07 16:41   ` Matthew Auld
2022-03-07 16:41   ` [Intel-gfx] " Matthew Auld
2022-03-08 13:59   ` Arunpravin
2022-03-08 13:59     ` Arunpravin
2022-03-08 13:59     ` [Intel-gfx] " Arunpravin
2022-03-08 17:01     ` Matthew Auld [this message]
2022-03-08 17:01       ` Matthew Auld
2022-03-08 17:01       ` [Intel-gfx] " Matthew Auld
2022-03-10 14:47       ` Arunpravin
2022-03-10 14:47         ` Arunpravin
2022-03-10 14:47         ` [Intel-gfx] " Arunpravin
2022-03-10 15:29         ` Matthew Auld
2022-03-10 15:29           ` Matthew Auld
2022-03-10 15:29           ` [Intel-gfx] " Matthew Auld
2022-03-14 19:38           ` Arunpravin
2022-03-14 19:38             ` Arunpravin
2022-03-14 19:38             ` [Intel-gfx] " Arunpravin
2022-03-07 18:31 ` [Intel-gfx] ✓ Fi.CI.IGT: success for " 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=8909011e-d18b-03cd-aeb5-bae10db41a00@intel.com \
    --to=matthew.auld@intel.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=arunpravin.paneerselvam@amd.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.