@@ -179,7 +179,7 @@ void __user *io_buffer_select(struct io_kiocb *req, size_t *len,
179179
180180 bl = io_buffer_get_list (ctx , req -> buf_index );
181181 if (likely (bl )) {
182- if (bl -> buf_nr_pages )
182+ if (bl -> is_mapped )
183183 ret = io_ring_buffer_select (req , len , bl , issue_flags );
184184 else
185185 ret = io_provided_buffer_select (req , len , bl );
@@ -214,7 +214,7 @@ static int __io_remove_buffers(struct io_ring_ctx *ctx,
214214 if (!nbufs )
215215 return 0 ;
216216
217- if (bl -> buf_nr_pages ) {
217+ if (bl -> is_mapped && bl -> buf_nr_pages ) {
218218 int j ;
219219
220220 i = bl -> buf_ring -> tail - bl -> head ;
@@ -225,6 +225,7 @@ static int __io_remove_buffers(struct io_ring_ctx *ctx,
225225 bl -> buf_nr_pages = 0 ;
226226 /* make sure it's seen as empty */
227227 INIT_LIST_HEAD (& bl -> buf_list );
228+ bl -> is_mapped = 0 ;
228229 return i ;
229230 }
230231
@@ -303,7 +304,7 @@ int io_remove_buffers(struct io_kiocb *req, unsigned int issue_flags)
303304 if (bl ) {
304305 ret = - EINVAL ;
305306 /* can't use provide/remove buffers command on mapped buffers */
306- if (!bl -> buf_nr_pages )
307+ if (!bl -> is_mapped )
307308 ret = __io_remove_buffers (ctx , bl , p -> nbufs );
308309 }
309310 io_ring_submit_unlock (ctx , issue_flags );
@@ -448,7 +449,7 @@ int io_provide_buffers(struct io_kiocb *req, unsigned int issue_flags)
448449 }
449450 }
450451 /* can't add buffers via this command for a mapped buffer ring */
451- if (bl -> buf_nr_pages ) {
452+ if (bl -> is_mapped ) {
452453 ret = - EINVAL ;
453454 goto err ;
454455 }
@@ -480,6 +481,7 @@ static int io_pin_pbuf_ring(struct io_uring_buf_reg *reg,
480481 bl -> buf_pages = pages ;
481482 bl -> buf_nr_pages = nr_pages ;
482483 bl -> buf_ring = br ;
484+ bl -> is_mapped = 1 ;
483485 return 0 ;
484486}
485487
@@ -514,7 +516,7 @@ int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
514516 bl = io_buffer_get_list (ctx , reg .bgid );
515517 if (bl ) {
516518 /* if mapped buffer ring OR classic exists, don't allow */
517- if (bl -> buf_nr_pages || !list_empty (& bl -> buf_list ))
519+ if (bl -> is_mapped || !list_empty (& bl -> buf_list ))
518520 return - EEXIST ;
519521 } else {
520522 free_bl = bl = kzalloc (sizeof (* bl ), GFP_KERNEL );
@@ -548,7 +550,7 @@ int io_unregister_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
548550 bl = io_buffer_get_list (ctx , reg .bgid );
549551 if (!bl )
550552 return - ENOENT ;
551- if (!bl -> buf_nr_pages )
553+ if (!bl -> is_mapped )
552554 return - EINVAL ;
553555
554556 __io_remove_buffers (ctx , bl , -1U );
0 commit comments