public inbox for [email protected]
 help / color / mirror / Atom feed
* [liburing PATCH] io_uring: invalid fd for file-less operations
@ 2019-11-13 21:27 Pavel Begunkov
  2019-11-13 21:31 ` Pavel Begunkov
  2019-11-13 21:39 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Pavel Begunkov @ 2019-11-13 21:27 UTC (permalink / raw)
  To: Jens Axboe, io-uring

If an operation doesn't need a file, set fd to an invalid value.
This would help to spot an unwanted fdget() in the kernel, and is
conceptually more correct (though negotiable)

Signed-off-by: Pavel Begunkov <[email protected]>
---
 src/include/liburing.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/include/liburing.h b/src/include/liburing.h
index 17bc80e..892efcf 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -240,7 +240,7 @@ static inline void io_uring_prep_poll_add(struct io_uring_sqe *sqe, int fd,
 static inline void io_uring_prep_poll_remove(struct io_uring_sqe *sqe,
 					     void *user_data)
 {
-	io_uring_prep_rw(IORING_OP_POLL_REMOVE, sqe, 0, user_data, 0, 0);
+	io_uring_prep_rw(IORING_OP_POLL_REMOVE, sqe, -1, user_data, 0, 0);
 }
 
 static inline void io_uring_prep_fsync(struct io_uring_sqe *sqe, int fd,
@@ -252,21 +252,21 @@ static inline void io_uring_prep_fsync(struct io_uring_sqe *sqe, int fd,
 
 static inline void io_uring_prep_nop(struct io_uring_sqe *sqe)
 {
-	io_uring_prep_rw(IORING_OP_NOP, sqe, 0, NULL, 0, 0);
+	io_uring_prep_rw(IORING_OP_NOP, sqe, -1, NULL, 0, 0);
 }
 
 static inline void io_uring_prep_timeout(struct io_uring_sqe *sqe,
 					 struct __kernel_timespec *ts,
 					 unsigned count, unsigned flags)
 {
-	io_uring_prep_rw(IORING_OP_TIMEOUT, sqe, 0, ts, 1, count);
+	io_uring_prep_rw(IORING_OP_TIMEOUT, sqe, -1, ts, 1, count);
 	sqe->timeout_flags = flags;
 }
 
 static inline void io_uring_prep_timeout_remove(struct io_uring_sqe *sqe,
 						__u64 user_data, unsigned flags)
 {
-	io_uring_prep_rw(IORING_OP_TIMEOUT_REMOVE, sqe, 0, (void *)user_data, 0, 0);
+	io_uring_prep_rw(IORING_OP_TIMEOUT_REMOVE, sqe, -1, (void *)user_data, 0, 0);
 	sqe->timeout_flags = flags;
 }
 
@@ -281,7 +281,7 @@ static inline void io_uring_prep_accept(struct io_uring_sqe *sqe, int fd,
 static inline void io_uring_prep_cancel(struct io_uring_sqe *sqe, void *user_data,
 					int flags)
 {
-	io_uring_prep_rw(IORING_OP_ASYNC_CANCEL, sqe, 0, user_data, 0, 0);
+	io_uring_prep_rw(IORING_OP_ASYNC_CANCEL, sqe, -1, user_data, 0, 0);
 	sqe->cancel_flags = flags;
 }
 
@@ -289,7 +289,7 @@ static inline void io_uring_prep_link_timeout(struct io_uring_sqe *sqe,
 					      struct __kernel_timespec *ts,
 					      unsigned flags)
 {
-	io_uring_prep_rw(IORING_OP_LINK_TIMEOUT, sqe, 0, ts, 1, 0);
+	io_uring_prep_rw(IORING_OP_LINK_TIMEOUT, sqe, -1, ts, 1, 0);
 	sqe->timeout_flags = flags;
 }
 
-- 
2.24.0


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

* Re: [liburing PATCH] io_uring: invalid fd for file-less operations
  2019-11-13 21:27 [liburing PATCH] io_uring: invalid fd for file-less operations Pavel Begunkov
@ 2019-11-13 21:31 ` Pavel Begunkov
  2019-11-13 21:39 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Pavel Begunkov @ 2019-11-13 21:31 UTC (permalink / raw)
  To: Jens Axboe, io-uring


[-- Attachment #1.1: Type: text/plain, Size: 370 bytes --]

On 14/11/2019 00:27, Pavel Begunkov wrote:
> If an operation doesn't need a file, set fd to an invalid value.
> This would help to spot an unwanted fdget() in the kernel, and is
> conceptually more correct (though negotiable)
> 

Either we can add a test with close(0) beforehand, but it
won't much help with new opcodes in the future. 

-- 
Pavel Begunkov


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [liburing PATCH] io_uring: invalid fd for file-less operations
  2019-11-13 21:27 [liburing PATCH] io_uring: invalid fd for file-less operations Pavel Begunkov
  2019-11-13 21:31 ` Pavel Begunkov
@ 2019-11-13 21:39 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2019-11-13 21:39 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring

On 11/13/19 2:27 PM, Pavel Begunkov wrote:
> If an operation doesn't need a file, set fd to an invalid value.
> This would help to spot an unwanted fdget() in the kernel, and is
> conceptually more correct (though negotiable)

I don't think that negotiable, if we don't need a valid fd, we should
just set it to -1. I've applied this patch, thanks.

-- 
Jens Axboe


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

end of thread, other threads:[~2019-11-13 21:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-13 21:27 [liburing PATCH] io_uring: invalid fd for file-less operations Pavel Begunkov
2019-11-13 21:31 ` Pavel Begunkov
2019-11-13 21:39 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox