public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH] io_uring: avoid implicit conversion to ktime_t
@ 2025-02-14  7:39 Dmitry Antipov
  2025-02-14  8:08 ` lizetao
  2025-02-14 17:34 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Dmitry Antipov @ 2025-02-14  7:39 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Jeff Moyer, io-uring, Dmitry Antipov

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 <[email protected]>
Signed-off-by: Dmitry Antipov <[email protected]>
---
I didn't add Fixes: as per Jeff's remark at
https://lore.kernel.org/io-uring/[email protected]/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


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

* RE: [PATCH] io_uring: avoid implicit conversion to ktime_t
  2025-02-14  7:39 [PATCH] io_uring: avoid implicit conversion to ktime_t Dmitry Antipov
@ 2025-02-14  8:08 ` lizetao
  2025-02-14 17:34 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: lizetao @ 2025-02-14  8:08 UTC (permalink / raw)
  To: Dmitry Antipov, Jens Axboe; +Cc: Jeff Moyer, [email protected]

Hi,

> -----Original Message-----
> From: Dmitry Antipov <[email protected]>
> Sent: Friday, February 14, 2025 3:40 PM
> To: Jens Axboe <[email protected]>
> Cc: Jeff Moyer <[email protected]>; [email protected]; Dmitry
> Antipov <[email protected]>
> 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 <[email protected]>
> Signed-off-by: Dmitry Antipov <[email protected]>
> ---
> I didn't add Fixes: as per Jeff's remark at https://lore.kernel.org/io-
> uring/[email protected]/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 <[email protected]>

---
Li Zetao

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

* Re: [PATCH] io_uring: avoid implicit conversion to ktime_t
  2025-02-14  7:39 [PATCH] io_uring: avoid implicit conversion to ktime_t Dmitry Antipov
  2025-02-14  8:08 ` lizetao
@ 2025-02-14 17:34 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2025-02-14 17:34 UTC (permalink / raw)
  To: Dmitry Antipov; +Cc: Jeff Moyer, io-uring

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 <[email protected]>
> Signed-off-by: Dmitry Antipov <[email protected]>
> ---
> I didn't add Fixes: as per Jeff's remark at
> https://lore.kernel.org/io-uring/[email protected]/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.

-- 
Jens Axboe


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

end of thread, other threads:[~2025-02-14 17:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-14  7:39 [PATCH] io_uring: avoid implicit conversion to ktime_t Dmitry Antipov
2025-02-14  8:08 ` lizetao
2025-02-14 17:34 ` Jens Axboe

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