Skip to contentSkip to conversation

io_uring: fix bug of wrong BUILD_BUG_ON check

PATCH Superseded Hao Xu 2 participants 5 messages Sep 6, 2021 – Sep 7, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Hao Xu

author
#0 lore raw

PATCH 1/1 io_uring: fix bug of wrong BUILD_BUG_ON check

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

---
 fs/io_uring.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/io_uring.c +3 -3
index 2bde732a1183..3a833037af43 100644
@@ -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);
Signature · 1 line
2.24.4
#1 lore raw
Quoted 12 lines · Hao Xu

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

---
 fs/io_uring.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/io_uring.c +0 -0
index 2bde732a1183..3a833037af43 100644

fs/io_uring.c static int __init io_uring_init(void) · line 10643

Quoted 9 lines
fs/io_uring.c +2 -2
@@ -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.

Quoted 7 lines
fs/io_uring.c +1 -1
 	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);
 
Signature · 1 line
Pavel Begunkov
author
#2 lore raw
Quoted 26 lines · Pavel Begunkov
Quoted 12 lines · Hao Xu

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

---
  fs/io_uring.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
fs/io_uring.c +0 -0
index 2bde732a1183..3a833037af43 100644

fs/io_uring.c static int __init io_uring_init(void) · line 10643

Quoted 9 lines
fs/io_uring.c +2 -2
@@ -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.

Quoted 3 lines

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?

Quoted 10 lines
Quoted 9 lines
fs/io_uring.c +1 -1
  	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);
 
#3 lore raw
Quoted 25 lines · Hao Xu
Quoted 24 lines · Pavel Begunkov
Quoted 12 lines · Hao Xu

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

---
  fs/io_uring.c | 6 +++---

  1 file changed, 3 insertions(+), 3 deletions(-)
fs/io_uring.c +0 -0
index 2bde732a1183..3a833037af43 100644

fs/io_uring.c static int __init io_uring_init(void) · line 10641

Quoted 7 lines
fs/io_uring.c +2 -2
@@ -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.

Quoted 4 lines
Quoted 3 lines

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

Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
fs/io_uring.c +1 -1
       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);

Signature · 1 line
Pavel Begunkov
author
#4 lore raw
Quoted 26 lines · Pavel Begunkov
Quoted 25 lines · Hao Xu
Quoted 24 lines · Pavel Begunkov
Quoted 12 lines · Hao Xu

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

---
   fs/io_uring.c | 6 +++---
   1 file changed, 3 insertions(+), 3 deletions(-)
fs/io_uring.c +0 -0
index 2bde732a1183..3a833037af43 100644

fs/io_uring.c static int __init io_uring_init(void) · line 10641

Quoted 7 lines
fs/io_uring.c +2 -2
@@ -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.

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines

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..

Quoted 12 lines
Quoted 11 lines
Quoted 10 lines
Quoted 9 lines
fs/io_uring.c +1 -1
       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);