public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH] io_uring/rsrc: use rq_data_dir() to compute bvec dir
@ 2025-02-28 22:30 Caleb Sander Mateos
  2025-03-01  1:24 ` Pavel Begunkov
  2025-03-01  2:23 ` Jens Axboe
  0 siblings, 2 replies; 5+ messages in thread
From: Caleb Sander Mateos @ 2025-02-28 22:30 UTC (permalink / raw)
  To: Jens Axboe, Pavel Begunkov; +Cc: Caleb Sander Mateos, io-uring, linux-kernel

The macro rq_data_dir() already computes a request's data direction.
Use it in place of the if-else to set imu->dir.

Signed-off-by: Caleb Sander Mateos <[email protected]>
---
 io_uring/rsrc.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 45bfb37bca1e..3107a03d56b8 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -957,15 +957,11 @@ int io_buffer_register_bvec(struct io_uring_cmd *cmd, struct request *rq,
 	imu->nr_bvecs = nr_bvecs;
 	refcount_set(&imu->refs, 1);
 	imu->release = release;
 	imu->priv = rq;
 	imu->is_kbuf = true;
-
-	if (op_is_write(req_op(rq)))
-		imu->dir = IO_IMU_SOURCE;
-	else
-		imu->dir = IO_IMU_DEST;
+	imu->dir = 1 << rq_data_dir(rq);
 
 	bvec = imu->bvec;
 	rq_for_each_bvec(bv, rq, rq_iter)
 		*bvec++ = bv;
 
-- 
2.45.2


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

* Re: [PATCH] io_uring/rsrc: use rq_data_dir() to compute bvec dir
  2025-02-28 22:30 [PATCH] io_uring/rsrc: use rq_data_dir() to compute bvec dir Caleb Sander Mateos
@ 2025-03-01  1:24 ` Pavel Begunkov
  2025-03-01  1:42   ` Caleb Sander Mateos
  2025-03-01  2:23 ` Jens Axboe
  1 sibling, 1 reply; 5+ messages in thread
From: Pavel Begunkov @ 2025-03-01  1:24 UTC (permalink / raw)
  To: Caleb Sander Mateos, Jens Axboe; +Cc: io-uring, linux-kernel

On 2/28/25 22:30, Caleb Sander Mateos wrote:
> The macro rq_data_dir() already computes a request's data direction.
> Use it in place of the if-else to set imu->dir.
> 
> Signed-off-by: Caleb Sander Mateos <[email protected]>
> ---
>   io_uring/rsrc.c | 6 +-----
>   1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
> index 45bfb37bca1e..3107a03d56b8 100644
> --- a/io_uring/rsrc.c
> +++ b/io_uring/rsrc.c
> @@ -957,15 +957,11 @@ int io_buffer_register_bvec(struct io_uring_cmd *cmd, struct request *rq,
>   	imu->nr_bvecs = nr_bvecs;
>   	refcount_set(&imu->refs, 1);
>   	imu->release = release;
>   	imu->priv = rq;
>   	imu->is_kbuf = true;
> -
> -	if (op_is_write(req_op(rq)))
> -		imu->dir = IO_IMU_SOURCE;
> -	else
> -		imu->dir = IO_IMU_DEST;
> +	imu->dir = 1 << rq_data_dir(rq);

rq_data_dir returns READ/WRITE, which should be fine, but it'd
be nicer to be more explicit unless it's already enforced
somewhere else

BUILD_BUG_ON(WRITE ==  ITER_SOURCE);
ditto for READ


>   
>   	bvec = imu->bvec;
>   	rq_for_each_bvec(bv, rq, rq_iter)
>   		*bvec++ = bv;
>   

-- 
Pavel Begunkov


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

* Re: [PATCH] io_uring/rsrc: use rq_data_dir() to compute bvec dir
  2025-03-01  1:24 ` Pavel Begunkov
@ 2025-03-01  1:42   ` Caleb Sander Mateos
  2025-03-01  2:01     ` Pavel Begunkov
  0 siblings, 1 reply; 5+ messages in thread
From: Caleb Sander Mateos @ 2025-03-01  1:42 UTC (permalink / raw)
  To: Pavel Begunkov; +Cc: Jens Axboe, io-uring, linux-kernel

On Fri, Feb 28, 2025 at 5:23 PM Pavel Begunkov <[email protected]> wrote:
>
> On 2/28/25 22:30, Caleb Sander Mateos wrote:
> > The macro rq_data_dir() already computes a request's data direction.
> > Use it in place of the if-else to set imu->dir.
> >
> > Signed-off-by: Caleb Sander Mateos <[email protected]>
> > ---
> >   io_uring/rsrc.c | 6 +-----
> >   1 file changed, 1 insertion(+), 5 deletions(-)
> >
> > diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
> > index 45bfb37bca1e..3107a03d56b8 100644
> > --- a/io_uring/rsrc.c
> > +++ b/io_uring/rsrc.c
> > @@ -957,15 +957,11 @@ int io_buffer_register_bvec(struct io_uring_cmd *cmd, struct request *rq,
> >       imu->nr_bvecs = nr_bvecs;
> >       refcount_set(&imu->refs, 1);
> >       imu->release = release;
> >       imu->priv = rq;
> >       imu->is_kbuf = true;
> > -
> > -     if (op_is_write(req_op(rq)))
> > -             imu->dir = IO_IMU_SOURCE;
> > -     else
> > -             imu->dir = IO_IMU_DEST;
> > +     imu->dir = 1 << rq_data_dir(rq);
>
> rq_data_dir returns READ/WRITE, which should be fine, but it'd
> be nicer to be more explicit unless it's already enforced
> somewhere else
>
> BUILD_BUG_ON(WRITE ==  ITER_SOURCE);
> ditto for READ

The definitions of ITER_SOURCE and ITER_DEST seem pretty clear that
they are aliases for WRITE/READ:
#define ITER_SOURCE 1 // == WRITE
#define ITER_DEST 0 // == READ

So I assume other code is already relying on this equivalence.

Best,
Caleb

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

* Re: [PATCH] io_uring/rsrc: use rq_data_dir() to compute bvec dir
  2025-03-01  1:42   ` Caleb Sander Mateos
@ 2025-03-01  2:01     ` Pavel Begunkov
  0 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2025-03-01  2:01 UTC (permalink / raw)
  To: Caleb Sander Mateos; +Cc: Jens Axboe, io-uring, linux-kernel

On 3/1/25 01:42, Caleb Sander Mateos wrote:
> On Fri, Feb 28, 2025 at 5:23 PM Pavel Begunkov <[email protected]> wrote:
>>
>> On 2/28/25 22:30, Caleb Sander Mateos wrote:
>>> The macro rq_data_dir() already computes a request's data direction.
>>> Use it in place of the if-else to set imu->dir.
>>>
>>> Signed-off-by: Caleb Sander Mateos <[email protected]>
>>> ---
>>>    io_uring/rsrc.c | 6 +-----
>>>    1 file changed, 1 insertion(+), 5 deletions(-)
>>>
>>> diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
>>> index 45bfb37bca1e..3107a03d56b8 100644
>>> --- a/io_uring/rsrc.c
>>> +++ b/io_uring/rsrc.c
>>> @@ -957,15 +957,11 @@ int io_buffer_register_bvec(struct io_uring_cmd *cmd, struct request *rq,
>>>        imu->nr_bvecs = nr_bvecs;
>>>        refcount_set(&imu->refs, 1);
>>>        imu->release = release;
>>>        imu->priv = rq;
>>>        imu->is_kbuf = true;
>>> -
>>> -     if (op_is_write(req_op(rq)))
>>> -             imu->dir = IO_IMU_SOURCE;
>>> -     else
>>> -             imu->dir = IO_IMU_DEST;
>>> +     imu->dir = 1 << rq_data_dir(rq);
>>
>> rq_data_dir returns READ/WRITE, which should be fine, but it'd
>> be nicer to be more explicit unless it's already enforced
>> somewhere else
>>
>> BUILD_BUG_ON(WRITE ==  ITER_SOURCE);
>> ditto for READ
> 
> The definitions of ITER_SOURCE and ITER_DEST seem pretty clear that
> they are aliases for WRITE/READ:
> #define ITER_SOURCE 1 // == WRITE
> #define ITER_DEST 0 // == READ
> 
> So I assume other code is already relying on this equivalence.

And it'll be left a mystery they weren't defined through
WRITE/READ in the first place. but the patch should be fine
then.

-- 
Pavel Begunkov


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

* Re: [PATCH] io_uring/rsrc: use rq_data_dir() to compute bvec dir
  2025-02-28 22:30 [PATCH] io_uring/rsrc: use rq_data_dir() to compute bvec dir Caleb Sander Mateos
  2025-03-01  1:24 ` Pavel Begunkov
@ 2025-03-01  2:23 ` Jens Axboe
  1 sibling, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2025-03-01  2:23 UTC (permalink / raw)
  To: Pavel Begunkov, Caleb Sander Mateos; +Cc: io-uring, linux-kernel


On Fri, 28 Feb 2025 15:30:56 -0700, Caleb Sander Mateos wrote:
> The macro rq_data_dir() already computes a request's data direction.
> Use it in place of the if-else to set imu->dir.
> 
> 

Applied, thanks!

[1/1] io_uring/rsrc: use rq_data_dir() to compute bvec dir
      commit: 2fced37638a897be4e0ac724d93a23a4e38633a6

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2025-03-01  2:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-28 22:30 [PATCH] io_uring/rsrc: use rq_data_dir() to compute bvec dir Caleb Sander Mateos
2025-03-01  1:24 ` Pavel Begunkov
2025-03-01  1:42   ` Caleb Sander Mateos
2025-03-01  2:01     ` Pavel Begunkov
2025-03-01  2:23 ` Jens Axboe

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