diff mbox series

io_uring: avoid implicit conversion to ktime_t

Message ID 20250214073954.3641025-1-dmantipov@yandex.ru (mailing list archive)
State New
Headers show
Series io_uring: avoid implicit conversion to ktime_t | expand

Commit Message

Dmitry Antipov Feb. 14, 2025, 7:39 a.m. UTC
In 'io_get_ext_arg()', do not assume that 'min_wait_usec' of 'struct
io_uring_getevents_arg' (which is '__u32') multiplied by NSEC_PER_USEC
may be implicitly converted to 'ktime_t' but use the convenient
'us_to_ktime()' helper instead. Compile tested only.

Suggested-by: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
I didn't add Fixes: as per Jeff's remark at
https://lore.kernel.org/io-uring/x49ed01lkso.fsf@segfault.usersys.redhat.com/T/#t;
if you think that it should be, most likely they are:

aa00f67adc2c ("io_uring: add support for fixed wait regions")
7ed9e09e2d13 ("io_uring: wire up min batch wake timeout")
---
 io_uring/io_uring.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

lizetao Feb. 14, 2025, 8:08 a.m. UTC | #1
Hi,

> -----Original Message-----
> From: Dmitry Antipov <dmantipov@yandex.ru>
> Sent: Friday, February 14, 2025 3:40 PM
> To: Jens Axboe <axboe@kernel.dk>
> Cc: Jeff Moyer <jmoyer@redhat.com>; io-uring@vger.kernel.org; Dmitry
> Antipov <dmantipov@yandex.ru>
> Subject: [PATCH] io_uring: avoid implicit conversion to ktime_t
> 
> In 'io_get_ext_arg()', do not assume that 'min_wait_usec' of 'struct
> io_uring_getevents_arg' (which is '__u32') multiplied by NSEC_PER_USEC may
> be implicitly converted to 'ktime_t' but use the convenient 'us_to_ktime()'
> helper instead. Compile tested only.
> 
> Suggested-by: Jeff Moyer <jmoyer@redhat.com>
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
> ---
> I didn't add Fixes: as per Jeff's remark at https://lore.kernel.org/io-
> uring/x49ed01lkso.fsf@segfault.usersys.redhat.com/T/#t;
> if you think that it should be, most likely they are:
> 
> aa00f67adc2c ("io_uring: add support for fixed wait regions")
> 7ed9e09e2d13 ("io_uring: wire up min batch wake timeout")
> ---
>  io_uring/io_uring.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index
> 7f2500aca95c..f73555e981fa 100644
> --- a/io_uring/io_uring.c
> +++ b/io_uring/io_uring.c
> @@ -3257,7 +3257,7 @@ static int io_get_ext_arg(struct io_ring_ctx *ctx,
> unsigned flags,
> 
>  		if (w->flags & ~IORING_REG_WAIT_TS)
>  			return -EINVAL;
> -		ext_arg->min_time = READ_ONCE(w->min_wait_usec) *
> NSEC_PER_USEC;
> +		ext_arg->min_time = us_to_ktime(READ_ONCE(w-
> >min_wait_usec));
>  		ext_arg->sig = u64_to_user_ptr(READ_ONCE(w->sigmask));
>  		ext_arg->argsz = READ_ONCE(w->sigmask_sz);
>  		if (w->flags & IORING_REG_WAIT_TS) {
> @@ -3286,7 +3286,7 @@ static int io_get_ext_arg(struct io_ring_ctx *ctx,
> unsigned flags,
>  	if (copy_from_user(&arg, uarg, sizeof(arg)))
>  		return -EFAULT;
>  #endif
> -	ext_arg->min_time = arg.min_wait_usec * NSEC_PER_USEC;
> +	ext_arg->min_time = us_to_ktime(arg.min_wait_usec);
>  	ext_arg->sig = u64_to_user_ptr(arg.sigmask);
>  	ext_arg->argsz = arg.sigmask_sz;
>  	if (arg.ts) {
> --
> 2.48.1
> 
> 

Reviewed-by: Li Zetao <lizetao1@huawei.com>

---
Li Zetao
Jens Axboe Feb. 14, 2025, 5:34 p.m. UTC | #2
On 2/14/25 12:39 AM, Dmitry Antipov wrote:
> In 'io_get_ext_arg()', do not assume that 'min_wait_usec' of 'struct
> io_uring_getevents_arg' (which is '__u32') multiplied by NSEC_PER_USEC
> may be implicitly converted to 'ktime_t' but use the convenient
> 'us_to_ktime()' helper instead. Compile tested only.
> 
> Suggested-by: Jeff Moyer <jmoyer@redhat.com>
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
> ---
> I didn't add Fixes: as per Jeff's remark at
> https://lore.kernel.org/io-uring/x49ed01lkso.fsf@segfault.usersys.redhat.com/T/#t;
> if you think that it should be, most likely they are:
> 
> aa00f67adc2c ("io_uring: add support for fixed wait regions")
> 7ed9e09e2d13 ("io_uring: wire up min batch wake timeout")

I don't think that's needed, as it's not really fixing anything.
Using us_to_ktime() is identical to the code that's already there.
diff mbox series

Patch

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 7f2500aca95c..f73555e981fa 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3257,7 +3257,7 @@  static int io_get_ext_arg(struct io_ring_ctx *ctx, unsigned flags,
 
 		if (w->flags & ~IORING_REG_WAIT_TS)
 			return -EINVAL;
-		ext_arg->min_time = READ_ONCE(w->min_wait_usec) * NSEC_PER_USEC;
+		ext_arg->min_time = us_to_ktime(READ_ONCE(w->min_wait_usec));
 		ext_arg->sig = u64_to_user_ptr(READ_ONCE(w->sigmask));
 		ext_arg->argsz = READ_ONCE(w->sigmask_sz);
 		if (w->flags & IORING_REG_WAIT_TS) {
@@ -3286,7 +3286,7 @@  static int io_get_ext_arg(struct io_ring_ctx *ctx, unsigned flags,
 	if (copy_from_user(&arg, uarg, sizeof(arg)))
 		return -EFAULT;
 #endif
-	ext_arg->min_time = arg.min_wait_usec * NSEC_PER_USEC;
+	ext_arg->min_time = us_to_ktime(arg.min_wait_usec);
 	ext_arg->sig = u64_to_user_ptr(arg.sigmask);
 	ext_arg->argsz = arg.sigmask_sz;
 	if (arg.ts) {