All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] io_uring: fix bug of wrong BUILD_BUG_ON check
@ 2021-09-06 15:12 Hao Xu
  2021-09-06 15:22 ` Pavel Begunkov
  0 siblings, 1 reply; 5+ messages in thread
From: Hao Xu @ 2021-09-06 15:12 UTC (permalink / raw)
  To: Jens Axboe; +Cc: io-uring, Pavel Begunkov, Joseph Qi

Some check should be large than not equal or large than.

Signed-off-by: Hao Xu <haoxu@linux.alibaba.com>
---
 fs/io_uring.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 2bde732a1183..3a833037af43 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -10637,13 +10637,13 @@ static int __init io_uring_init(void)
 		     sizeof(struct io_uring_rsrc_update2));
 
 	/* ->buf_index is u16 */
-	BUILD_BUG_ON(IORING_MAX_REG_BUFFERS >= (1u << 16));
+	BUILD_BUG_ON(IORING_MAX_REG_BUFFERS > (1u << 16));
 
 	/* should fit into one byte */
-	BUILD_BUG_ON(SQE_VALID_FLAGS >= (1 << 8));
+	BUILD_BUG_ON(SQE_VALID_FLAGS > (1 << 8));
 
 	BUILD_BUG_ON(ARRAY_SIZE(io_op_defs) != IORING_OP_LAST);
-	BUILD_BUG_ON(__REQ_F_LAST_BIT >= 8 * sizeof(int));
+	BUILD_BUG_ON(__REQ_F_LAST_BIT > 8 * sizeof(int));
 
 	req_cachep = KMEM_CACHE(io_kiocb, SLAB_HWCACHE_ALIGN | SLAB_PANIC |
 				SLAB_ACCOUNT);
-- 
2.24.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] io_uring: fix bug of wrong BUILD_BUG_ON check
  2021-09-06 15:12 [PATCH] io_uring: fix bug of wrong BUILD_BUG_ON check Hao Xu
@ 2021-09-06 15:22 ` Pavel Begunkov
  2021-09-06 17:03   ` Hao Xu
  0 siblings, 1 reply; 5+ messages in thread
From: Pavel Begunkov @ 2021-09-06 15:22 UTC (permalink / raw)
  To: Hao Xu, Jens Axboe; +Cc: io-uring, Joseph Qi

On 9/6/21 4:12 PM, Hao Xu wrote:
> Some check should be large than not equal or large than.
> 
> Signed-off-by: Hao Xu <haoxu@linux.alibaba.com>
> ---
>  fs/io_uring.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 2bde732a1183..3a833037af43 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -10637,13 +10637,13 @@ static int __init io_uring_init(void)
>  		     sizeof(struct io_uring_rsrc_update2));
>  
>  	/* ->buf_index is u16 */
> -	BUILD_BUG_ON(IORING_MAX_REG_BUFFERS >= (1u << 16));
> +	BUILD_BUG_ON(IORING_MAX_REG_BUFFERS > (1u << 16));
>  
>  	/* should fit into one byte */
> -	BUILD_BUG_ON(SQE_VALID_FLAGS >= (1 << 8));
> +	BUILD_BUG_ON(SQE_VALID_FLAGS > (1 << 8));

0xff = 255 is the largest number fitting in u8,
1<<8 = 256.

let SQE_VALID_FLAGS = 256,
(256 > (1<<8)) == (256 > 256) == false,  even though it can't
be represented by u8.


>  	BUILD_BUG_ON(ARRAY_SIZE(io_op_defs) != IORING_OP_LAST);
> -	BUILD_BUG_ON(__REQ_F_LAST_BIT >= 8 * sizeof(int));
> +	BUILD_BUG_ON(__REQ_F_LAST_BIT > 8 * sizeof(int));
>  
>  	req_cachep = KMEM_CACHE(io_kiocb, SLAB_HWCACHE_ALIGN | SLAB_PANIC |
>  				SLAB_ACCOUNT);
> 

-- 
Pavel Begunkov

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] io_uring: fix bug of wrong BUILD_BUG_ON check
  2021-09-06 15:22 ` Pavel Begunkov
@ 2021-09-06 17:03   ` Hao Xu
  2021-09-06 19:15     ` Pavel Begunkov
  0 siblings, 1 reply; 5+ messages in thread
From: Hao Xu @ 2021-09-06 17:03 UTC (permalink / raw)
  To: Pavel Begunkov, Jens Axboe; +Cc: io-uring, Joseph Qi

在 2021/9/6 下午11:22, Pavel Begunkov 写道:
> On 9/6/21 4:12 PM, Hao Xu wrote:
>> Some check should be large than not equal or large than.
>>
>> Signed-off-by: Hao Xu <haoxu@linux.alibaba.com>
>> ---
>>   fs/io_uring.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/fs/io_uring.c b/fs/io_uring.c
>> index 2bde732a1183..3a833037af43 100644
>> --- a/fs/io_uring.c
>> +++ b/fs/io_uring.c
>> @@ -10637,13 +10637,13 @@ static int __init io_uring_init(void)
>>   		     sizeof(struct io_uring_rsrc_update2));
>>   
>>   	/* ->buf_index is u16 */
>> -	BUILD_BUG_ON(IORING_MAX_REG_BUFFERS >= (1u << 16));
>> +	BUILD_BUG_ON(IORING_MAX_REG_BUFFERS > (1u << 16));
>>   
>>   	/* should fit into one byte */
>> -	BUILD_BUG_ON(SQE_VALID_FLAGS >= (1 << 8));
>> +	BUILD_BUG_ON(SQE_VALID_FLAGS > (1 << 8));
> 
> 0xff = 255 is the largest number fitting in u8,
> 1<<8 = 256.
> 
> let SQE_VALID_FLAGS = 256,
> (256 > (1<<8)) == (256 > 256) == false,  even though it can't
> be represented by u8.
Isn't SQE_VALID_FLAGS = 256 a valid value for it?
> 
> 
>>   	BUILD_BUG_ON(ARRAY_SIZE(io_op_defs) != IORING_OP_LAST);
>> -	BUILD_BUG_ON(__REQ_F_LAST_BIT >= 8 * sizeof(int));
>> +	BUILD_BUG_ON(__REQ_F_LAST_BIT > 8 * sizeof(int));
>>   
>>   	req_cachep = KMEM_CACHE(io_kiocb, SLAB_HWCACHE_ALIGN | SLAB_PANIC |
>>   				SLAB_ACCOUNT);
>>
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] io_uring: fix bug of wrong BUILD_BUG_ON check
  2021-09-06 17:03   ` Hao Xu
@ 2021-09-06 19:15     ` Pavel Begunkov
  2021-09-07  3:02       ` Hao Xu
  0 siblings, 1 reply; 5+ messages in thread
From: Pavel Begunkov @ 2021-09-06 19:15 UTC (permalink / raw)
  To: Hao Xu, Jens Axboe; +Cc: io-uring, Joseph Qi

On 9/6/21 6:03 PM, Hao Xu wrote:
> 在 2021/9/6 下午11:22, Pavel Begunkov 写道:
>> On 9/6/21 4:12 PM, Hao Xu wrote:
>>> Some check should be large than not equal or large than.
>>>
>>> Signed-off-by: Hao Xu <haoxu@linux.alibaba.com>
>>> ---
>>>   fs/io_uring.c | 6 +++---
>>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/fs/io_uring.c b/fs/io_uring.c
>>> index 2bde732a1183..3a833037af43 100644
>>> --- a/fs/io_uring.c
>>> +++ b/fs/io_uring.c
>>> @@ -10637,13 +10637,13 @@ static int __init io_uring_init(void)
>>>                sizeof(struct io_uring_rsrc_update2));
>>>         /* ->buf_index is u16 */
>>> -    BUILD_BUG_ON(IORING_MAX_REG_BUFFERS >= (1u << 16));
>>> +    BUILD_BUG_ON(IORING_MAX_REG_BUFFERS > (1u << 16));
>>>         /* should fit into one byte */
>>> -    BUILD_BUG_ON(SQE_VALID_FLAGS >= (1 << 8));
>>> +    BUILD_BUG_ON(SQE_VALID_FLAGS > (1 << 8));
>>
>> 0xff = 255 is the largest number fitting in u8,
>> 1<<8 = 256.
>>
>> let SQE_VALID_FLAGS = 256,
>> (256 > (1<<8)) == (256 > 256) == false,  even though it can't
>> be represented by u8.
> Isn't SQE_VALID_FLAGS = 256 a valid value for it?

SQE_VALID_FLAGS is a "bitwise OR" combination of valid flags, so
can't be go beyond 0xff

>>
>>
>>>       BUILD_BUG_ON(ARRAY_SIZE(io_op_defs) != IORING_OP_LAST);
>>> -    BUILD_BUG_ON(__REQ_F_LAST_BIT >= 8 * sizeof(int));
>>> +    BUILD_BUG_ON(__REQ_F_LAST_BIT > 8 * sizeof(int));
>>>         req_cachep = KMEM_CACHE(io_kiocb, SLAB_HWCACHE_ALIGN | SLAB_PANIC |
>>>                   SLAB_ACCOUNT);
>>>
>>
> 

-- 
Pavel Begunkov

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] io_uring: fix bug of wrong BUILD_BUG_ON check
  2021-09-06 19:15     ` Pavel Begunkov
@ 2021-09-07  3:02       ` Hao Xu
  0 siblings, 0 replies; 5+ messages in thread
From: Hao Xu @ 2021-09-07  3:02 UTC (permalink / raw)
  To: Pavel Begunkov, Jens Axboe; +Cc: io-uring, Joseph Qi

在 2021/9/7 上午3:15, Pavel Begunkov 写道:
> On 9/6/21 6:03 PM, Hao Xu wrote:
>> 在 2021/9/6 下午11:22, Pavel Begunkov 写道:
>>> On 9/6/21 4:12 PM, Hao Xu wrote:
>>>> Some check should be large than not equal or large than.
>>>>
>>>> Signed-off-by: Hao Xu <haoxu@linux.alibaba.com>
>>>> ---
>>>>    fs/io_uring.c | 6 +++---
>>>>    1 file changed, 3 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/fs/io_uring.c b/fs/io_uring.c
>>>> index 2bde732a1183..3a833037af43 100644
>>>> --- a/fs/io_uring.c
>>>> +++ b/fs/io_uring.c
>>>> @@ -10637,13 +10637,13 @@ static int __init io_uring_init(void)
>>>>                 sizeof(struct io_uring_rsrc_update2));
>>>>          /* ->buf_index is u16 */
>>>> -    BUILD_BUG_ON(IORING_MAX_REG_BUFFERS >= (1u << 16));
>>>> +    BUILD_BUG_ON(IORING_MAX_REG_BUFFERS > (1u << 16));
>>>>          /* should fit into one byte */
>>>> -    BUILD_BUG_ON(SQE_VALID_FLAGS >= (1 << 8));
>>>> +    BUILD_BUG_ON(SQE_VALID_FLAGS > (1 << 8));
>>>
>>> 0xff = 255 is the largest number fitting in u8,
>>> 1<<8 = 256.
>>>
>>> let SQE_VALID_FLAGS = 256,
>>> (256 > (1<<8)) == (256 > 256) == false,  even though it can't
>>> be represented by u8.
>> Isn't SQE_VALID_FLAGS = 256 a valid value for it?
> 
> SQE_VALID_FLAGS is a "bitwise OR" combination of valid flags, so
> can't be go beyond 0xff
I see, don't know why I mix it with __REQ_F_LAST_BIT in my mind..
> 
>>>
>>>
>>>>        BUILD_BUG_ON(ARRAY_SIZE(io_op_defs) != IORING_OP_LAST);
>>>> -    BUILD_BUG_ON(__REQ_F_LAST_BIT >= 8 * sizeof(int));
>>>> +    BUILD_BUG_ON(__REQ_F_LAST_BIT > 8 * sizeof(int));
>>>>          req_cachep = KMEM_CACHE(io_kiocb, SLAB_HWCACHE_ALIGN | SLAB_PANIC |
>>>>                    SLAB_ACCOUNT);
>>>>
>>>
>>
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-09-07  3:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-06 15:12 [PATCH] io_uring: fix bug of wrong BUILD_BUG_ON check Hao Xu
2021-09-06 15:22 ` Pavel Begunkov
2021-09-06 17:03   ` Hao Xu
2021-09-06 19:15     ` Pavel Begunkov
2021-09-07  3:02       ` Hao Xu

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.