diff mbox series

[04/10] drm/i915: Fix MAX_ORDER usage in i915_gem_object_get_pages_internal()

Message ID 20230315113133.11326-5-kirill.shutemov@linux.intel.com (mailing list archive)
State New
Headers show
Series Fix confusion around MAX_ORDER | expand

Commit Message

kirill.shutemov@linux.intel.com March 15, 2023, 11:31 a.m. UTC
MAX_ORDER is not inclusive: the maximum allocation order buddy allocator
can deliver is MAX_ORDER-1.

Fix MAX_ORDER usage in i915_gem_object_get_pages_internal().

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
---
 drivers/gpu/drm/i915/gem/i915_gem_internal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Tvrtko Ursulin March 15, 2023, 2:18 p.m. UTC | #1
On 15/03/2023 11:31, Kirill A. Shutemov wrote:
> MAX_ORDER is not inclusive: the maximum allocation order buddy allocator
> can deliver is MAX_ORDER-1.

This looks to be true on inspection:

__alloc_pages():
..
	if (WARN_ON_ONCE_GFP(order >= MAX_ORDER, gfp))

So a bit of a misleading name "max".. For the i915 patch:

Acked-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

I don't however see the whole series to understand the context, or how 
you want to handle the individual patches. Is it a tree wide cleanup of 
the same mistake?

Regards,

Tvrtko

> Fix MAX_ORDER usage in i915_gem_object_get_pages_internal().
> 
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: Jani Nikula <jani.nikula@linux.intel.com>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
> ---
>   drivers/gpu/drm/i915/gem/i915_gem_internal.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_internal.c b/drivers/gpu/drm/i915/gem/i915_gem_internal.c
> index 6bc26b4b06b8..eae9e9f6d3bf 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_internal.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_internal.c
> @@ -36,7 +36,7 @@ static int i915_gem_object_get_pages_internal(struct drm_i915_gem_object *obj)
>   	struct sg_table *st;
>   	struct scatterlist *sg;
>   	unsigned int npages; /* restricted by sg_alloc_table */
> -	int max_order = MAX_ORDER;
> +	int max_order = MAX_ORDER - 1;
>   	unsigned int max_segment;
>   	gfp_t gfp;
>
Kirill A . Shutemov March 15, 2023, 3:28 p.m. UTC | #2
On Wed, Mar 15, 2023 at 02:18:52PM +0000, Tvrtko Ursulin wrote:
> 
> On 15/03/2023 11:31, Kirill A. Shutemov wrote:
> > MAX_ORDER is not inclusive: the maximum allocation order buddy allocator
> > can deliver is MAX_ORDER-1.
> 
> This looks to be true on inspection:
> 
> __alloc_pages():
> ..
> 	if (WARN_ON_ONCE_GFP(order >= MAX_ORDER, gfp))
> 
> So a bit of a misleading name "max".. For the i915 patch:
> 
> Acked-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> 
> I don't however see the whole series to understand the context, or how you
> want to handle the individual patches. Is it a tree wide cleanup of the same
> mistake?

The whole patchset can be seen here:

https://lore.kernel.org/all/20230315113133.11326-1-kirill.shutemov@linux.intel.com/

The idea is to fix all MAX_ORDER bugs first and then re-define MAX_ORDER
more sensibly.
Tvrtko Ursulin March 15, 2023, 3:35 p.m. UTC | #3
On 15/03/2023 15:28, Kirill A. Shutemov wrote:
> On Wed, Mar 15, 2023 at 02:18:52PM +0000, Tvrtko Ursulin wrote:
>>
>> On 15/03/2023 11:31, Kirill A. Shutemov wrote:
>>> MAX_ORDER is not inclusive: the maximum allocation order buddy allocator
>>> can deliver is MAX_ORDER-1.
>>
>> This looks to be true on inspection:
>>
>> __alloc_pages():
>> ..
>> 	if (WARN_ON_ONCE_GFP(order >= MAX_ORDER, gfp))
>>
>> So a bit of a misleading name "max".. For the i915 patch:
>>
>> Acked-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>>
>> I don't however see the whole series to understand the context, or how you
>> want to handle the individual patches. Is it a tree wide cleanup of the same
>> mistake?
> 
> The whole patchset can be seen here:
> 
> https://lore.kernel.org/all/20230315113133.11326-1-kirill.shutemov@linux.intel.com/
> 
> The idea is to fix all MAX_ORDER bugs first and then re-define MAX_ORDER
> more sensibly.

Sounds good.

Would you like i915 to take this patch or you will be bringing the whole 
lot via some other route? Former is okay and latter should also be fine 
for i915 since I don't envisage any conflicts here.

Regards,

Tvrtko
Kirill A . Shutemov March 15, 2023, 3:38 p.m. UTC | #4
On Wed, Mar 15, 2023 at 03:35:23PM +0000, Tvrtko Ursulin wrote:
> 
> On 15/03/2023 15:28, Kirill A. Shutemov wrote:
> > On Wed, Mar 15, 2023 at 02:18:52PM +0000, Tvrtko Ursulin wrote:
> > > 
> > > On 15/03/2023 11:31, Kirill A. Shutemov wrote:
> > > > MAX_ORDER is not inclusive: the maximum allocation order buddy allocator
> > > > can deliver is MAX_ORDER-1.
> > > 
> > > This looks to be true on inspection:
> > > 
> > > __alloc_pages():
> > > ..
> > > 	if (WARN_ON_ONCE_GFP(order >= MAX_ORDER, gfp))
> > > 
> > > So a bit of a misleading name "max".. For the i915 patch:
> > > 
> > > Acked-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> > > 
> > > I don't however see the whole series to understand the context, or how you
> > > want to handle the individual patches. Is it a tree wide cleanup of the same
> > > mistake?
> > 
> > The whole patchset can be seen here:
> > 
> > https://lore.kernel.org/all/20230315113133.11326-1-kirill.shutemov@linux.intel.com/
> > 
> > The idea is to fix all MAX_ORDER bugs first and then re-define MAX_ORDER
> > more sensibly.
> 
> Sounds good.
> 
> Would you like i915 to take this patch or you will be bringing the whole lot
> via some other route? Former is okay and latter should also be fine for i915
> since I don't envisage any conflicts here.

I think would be better to get it via mm tree.
Tvrtko Ursulin March 16, 2023, 8:55 a.m. UTC | #5
On 15/03/2023 15:38, Kirill A. Shutemov wrote:
> On Wed, Mar 15, 2023 at 03:35:23PM +0000, Tvrtko Ursulin wrote:
>>
>> On 15/03/2023 15:28, Kirill A. Shutemov wrote:
>>> On Wed, Mar 15, 2023 at 02:18:52PM +0000, Tvrtko Ursulin wrote:
>>>>
>>>> On 15/03/2023 11:31, Kirill A. Shutemov wrote:
>>>>> MAX_ORDER is not inclusive: the maximum allocation order buddy allocator
>>>>> can deliver is MAX_ORDER-1.
>>>>
>>>> This looks to be true on inspection:
>>>>
>>>> __alloc_pages():
>>>> ..
>>>> 	if (WARN_ON_ONCE_GFP(order >= MAX_ORDER, gfp))
>>>>
>>>> So a bit of a misleading name "max".. For the i915 patch:
>>>>
>>>> Acked-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>>>>
>>>> I don't however see the whole series to understand the context, or how you
>>>> want to handle the individual patches. Is it a tree wide cleanup of the same
>>>> mistake?
>>>
>>> The whole patchset can be seen here:
>>>
>>> https://lore.kernel.org/all/20230315113133.11326-1-kirill.shutemov@linux.intel.com/
>>>
>>> The idea is to fix all MAX_ORDER bugs first and then re-define MAX_ORDER
>>> more sensibly.
>>
>> Sounds good.
>>
>> Would you like i915 to take this patch or you will be bringing the whole lot
>> via some other route? Former is okay and latter should also be fine for i915
>> since I don't envisage any conflicts here.
> 
> I think would be better to get it via mm tree.

Ack for that. But as I saw that by the end of the series you also change 
this back as you redefine MAX_ORDER to be inclusive you could even 
simplify things and just not do anything for i915. I am pretty sure we 
never call this helper for > 4M allocations otherwise we would have seen 
this warn.

Regards,

Tvrtko
Vlastimil Babka March 21, 2023, 7:55 a.m. UTC | #6
On 3/15/23 12:31, Kirill A. Shutemov wrote:
> MAX_ORDER is not inclusive: the maximum allocation order buddy allocator
> can deliver is MAX_ORDER-1.
> 
> Fix MAX_ORDER usage in i915_gem_object_get_pages_internal().
> 
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> Cc: Jani Nikula <jani.nikula@linux.intel.com>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
> ---
>  drivers/gpu/drm/i915/gem/i915_gem_internal.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_internal.c b/drivers/gpu/drm/i915/gem/i915_gem_internal.c
> index 6bc26b4b06b8..eae9e9f6d3bf 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_internal.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_internal.c
> @@ -36,7 +36,7 @@ static int i915_gem_object_get_pages_internal(struct drm_i915_gem_object *obj)
>  	struct sg_table *st;
>  	struct scatterlist *sg;
>  	unsigned int npages; /* restricted by sg_alloc_table */
> -	int max_order = MAX_ORDER;
> +	int max_order = MAX_ORDER - 1;
>  	unsigned int max_segment;
>  	gfp_t gfp;
>
Vlastimil Babka March 21, 2023, 7:57 a.m. UTC | #7
On 3/16/23 09:55, Tvrtko Ursulin wrote:
> 
> On 15/03/2023 15:38, Kirill A. Shutemov wrote:
>> On Wed, Mar 15, 2023 at 03:35:23PM +0000, Tvrtko Ursulin wrote:
>>>
>>> On 15/03/2023 15:28, Kirill A. Shutemov wrote:
>>>> On Wed, Mar 15, 2023 at 02:18:52PM +0000, Tvrtko Ursulin wrote:
>>>>>
>>>>> On 15/03/2023 11:31, Kirill A. Shutemov wrote:
>>>>>> MAX_ORDER is not inclusive: the maximum allocation order buddy allocator
>>>>>> can deliver is MAX_ORDER-1.
>>>>>
>>>>> This looks to be true on inspection:
>>>>>
>>>>> __alloc_pages():
>>>>> ..
>>>>> 	if (WARN_ON_ONCE_GFP(order >= MAX_ORDER, gfp))
>>>>>
>>>>> So a bit of a misleading name "max".. For the i915 patch:
>>>>>
>>>>> Acked-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>>>>>
>>>>> I don't however see the whole series to understand the context, or how you
>>>>> want to handle the individual patches. Is it a tree wide cleanup of the same
>>>>> mistake?
>>>>
>>>> The whole patchset can be seen here:
>>>>
>>>> https://lore.kernel.org/all/20230315113133.11326-1-kirill.shutemov@linux.intel.com/
>>>>
>>>> The idea is to fix all MAX_ORDER bugs first and then re-define MAX_ORDER
>>>> more sensibly.
>>>
>>> Sounds good.
>>>
>>> Would you like i915 to take this patch or you will be bringing the whole lot
>>> via some other route? Former is okay and latter should also be fine for i915
>>> since I don't envisage any conflicts here.
>> 
>> I think would be better to get it via mm tree.
> 
> Ack for that. But as I saw that by the end of the series you also change 
> this back as you redefine MAX_ORDER to be inclusive you could even 
> simplify things and just not do anything for i915. I am pretty sure we 
> never call this helper for > 4M allocations otherwise we would have seen 
> this warn.

I think it's better the Kirill's way as the redefinition patch then isn't
also a silent bugfix. In case some of the bugfixes would need to be
backported to stable (maybe you don't seen the warn, but something else will
change and start seeing it?), it's better if they are separate.

> Regards,
> 
> Tvrtko
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_internal.c b/drivers/gpu/drm/i915/gem/i915_gem_internal.c
index 6bc26b4b06b8..eae9e9f6d3bf 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_internal.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_internal.c
@@ -36,7 +36,7 @@  static int i915_gem_object_get_pages_internal(struct drm_i915_gem_object *obj)
 	struct sg_table *st;
 	struct scatterlist *sg;
 	unsigned int npages; /* restricted by sg_alloc_table */
-	int max_order = MAX_ORDER;
+	int max_order = MAX_ORDER - 1;
 	unsigned int max_segment;
 	gfp_t gfp;