netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vhost_net: Use fdget() and fdput()
@ 2023-05-05  6:24 ye.xingchen
  2023-05-05  6:45 ` Jason Wang
  2023-05-11  5:31 ` Al Viro
  0 siblings, 2 replies; 5+ messages in thread
From: ye.xingchen @ 2023-05-05  6:24 UTC (permalink / raw)
  To: mst; +Cc: jasowang, kvm, virtualization, netdev, linux-kernel

From: Ye Xingchen <ye.xingchen@zte.com.cn>

convert the fget()/fput() uses to fdget()/fdput().

Signed-off-by: Ye Xingchen <ye.xingchen@zte.com.cn>
---
 drivers/vhost/net.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index ae2273196b0c..5b3fe4805182 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -1466,17 +1466,17 @@ static struct ptr_ring *get_tap_ptr_ring(struct file *file)

 static struct socket *get_tap_socket(int fd)
 {
-	struct file *file = fget(fd);
+	struct fd f = fdget(fd);
 	struct socket *sock;

-	if (!file)
+	if (!f.file)
 		return ERR_PTR(-EBADF);
-	sock = tun_get_socket(file);
+	sock = tun_get_socket(f.file);
 	if (!IS_ERR(sock))
 		return sock;
-	sock = tap_get_socket(file);
+	sock = tap_get_socket(f.file);
 	if (IS_ERR(sock))
-		fput(file);
+		fdput(f);
 	return sock;
 }

-- 
2.25.1

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

* Re: [PATCH] vhost_net: Use fdget() and fdput()
  2023-05-05  6:24 [PATCH] vhost_net: Use fdget() and fdput() ye.xingchen
@ 2023-05-05  6:45 ` Jason Wang
  2023-05-05  8:41   ` ye xingchen
  2023-05-11  5:31 ` Al Viro
  1 sibling, 1 reply; 5+ messages in thread
From: Jason Wang @ 2023-05-05  6:45 UTC (permalink / raw)
  To: ye.xingchen; +Cc: mst, kvm, virtualization, netdev, linux-kernel

On Fri, May 5, 2023 at 2:24 PM <ye.xingchen@zte.com.cn> wrote:
>
> From: Ye Xingchen <ye.xingchen@zte.com.cn>
>
> convert the fget()/fput() uses to fdget()/fdput().

What's the advantages of this?

Thanks

>
> Signed-off-by: Ye Xingchen <ye.xingchen@zte.com.cn>
> ---
>  drivers/vhost/net.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
> index ae2273196b0c..5b3fe4805182 100644
> --- a/drivers/vhost/net.c
> +++ b/drivers/vhost/net.c
> @@ -1466,17 +1466,17 @@ static struct ptr_ring *get_tap_ptr_ring(struct file *file)
>
>  static struct socket *get_tap_socket(int fd)
>  {
> -       struct file *file = fget(fd);
> +       struct fd f = fdget(fd);
>         struct socket *sock;
>
> -       if (!file)
> +       if (!f.file)
>                 return ERR_PTR(-EBADF);
> -       sock = tun_get_socket(file);
> +       sock = tun_get_socket(f.file);
>         if (!IS_ERR(sock))
>                 return sock;
> -       sock = tap_get_socket(file);
> +       sock = tap_get_socket(f.file);
>         if (IS_ERR(sock))
> -               fput(file);
> +               fdput(f);
>         return sock;
>  }
>
> --
> 2.25.1
>


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

* Re: [PATCH] vhost_net: Use fdget() and fdput()
  2023-05-05  6:45 ` Jason Wang
@ 2023-05-05  8:41   ` ye xingchen
  2023-05-05 14:59     ` Michael S. Tsirkin
  0 siblings, 1 reply; 5+ messages in thread
From: ye xingchen @ 2023-05-05  8:41 UTC (permalink / raw)
  To: jasowang; +Cc: kvm, linux-kernel, mst, netdev, virtualization, ye.xingchen

>>
>> From: Ye Xingchen <ye.xingchen@zte.com.cn>
>>
>> convert the fget()/fput() uses to fdget()/fdput().
>What's the advantages of this?
>
>Thanks
>>
>> Signed-off-by: Ye Xingchen <ye.xingchen@zte.com.cn>
>> ---
>>  drivers/vhost/net.c | 10 +++++-----
>>  1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
>> index ae2273196b0c..5b3fe4805182 100644
>> --- a/drivers/vhost/net.c
>> +++ b/drivers/vhost/net.c
>> @@ -1466,17 +1466,17 @@ static struct ptr_ring *get_tap_ptr_ring(struct file *file)
>>
>>  static struct socket *get_tap_socket(int fd)
>>  {
>> -       struct file *file = fget(fd);
>> +       struct fd f = fdget(fd);
>>         struct socket *sock;
>>
>> -       if (!file)
>> +       if (!f.file)
>>                 return ERR_PTR(-EBADF);
>> -       sock = tun_get_socket(file);
>> +       sock = tun_get_socket(f.file);
>>         if (!IS_ERR(sock))
>>                 return sock;
>> -       sock = tap_get_socket(file);
>> +       sock = tap_get_socket(f.file);
>>         if (IS_ERR(sock))
>> -               fput(file);
>> +               fdput(f);
>>         return sock;
>>  }
>>
>> --
>> 2.25.1
>>
fdget requires an integer type file descriptor as its parameter, 
and fget requires a pointer to the file structure as its parameter.

By using the fdget function, the socket object, can be quickly 
obtained from the process's file descriptor table without 
the need to obtain the file descriptor first before passing it 
as a parameter to the fget function. This reduces unnecessary 
operations, improves system efficiency and performance.

Best Regards
Ye

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

* Re: [PATCH] vhost_net: Use fdget() and fdput()
  2023-05-05  8:41   ` ye xingchen
@ 2023-05-05 14:59     ` Michael S. Tsirkin
  0 siblings, 0 replies; 5+ messages in thread
From: Michael S. Tsirkin @ 2023-05-05 14:59 UTC (permalink / raw)
  To: ye xingchen
  Cc: jasowang, kvm, linux-kernel, netdev, virtualization, ye.xingchen

On Fri, May 05, 2023 at 04:41:55PM +0800, ye xingchen wrote:
> >>
> >> From: Ye Xingchen <ye.xingchen@zte.com.cn>
> >>
> >> convert the fget()/fput() uses to fdget()/fdput().
> >What's the advantages of this?
> >
> >Thanks
> >>
> >> Signed-off-by: Ye Xingchen <ye.xingchen@zte.com.cn>
> >> ---
> >>  drivers/vhost/net.c | 10 +++++-----
> >>  1 file changed, 5 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
> >> index ae2273196b0c..5b3fe4805182 100644
> >> --- a/drivers/vhost/net.c
> >> +++ b/drivers/vhost/net.c
> >> @@ -1466,17 +1466,17 @@ static struct ptr_ring *get_tap_ptr_ring(struct file *file)
> >>
> >>  static struct socket *get_tap_socket(int fd)
> >>  {
> >> -       struct file *file = fget(fd);
> >> +       struct fd f = fdget(fd);
> >>         struct socket *sock;
> >>
> >> -       if (!file)
> >> +       if (!f.file)
> >>                 return ERR_PTR(-EBADF);
> >> -       sock = tun_get_socket(file);
> >> +       sock = tun_get_socket(f.file);
> >>         if (!IS_ERR(sock))
> >>                 return sock;
> >> -       sock = tap_get_socket(file);
> >> +       sock = tap_get_socket(f.file);
> >>         if (IS_ERR(sock))
> >> -               fput(file);
> >> +               fdput(f);
> >>         return sock;
> >>  }
> >>
> >> --
> >> 2.25.1
> >>
> fdget requires an integer type file descriptor as its parameter, 
> and fget requires a pointer to the file structure as its parameter.

In which kernel?

include/linux/file.h:extern struct file *fget(unsigned int fd);


> By using the fdget function, the socket object, can be quickly 
> obtained from the process's file descriptor table without 
> the need to obtain the file descriptor first before passing it 
> as a parameter to the fget function. This reduces unnecessary 
> operations, improves system efficiency and performance.
> 
> Best Regards
> Ye


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

* Re: [PATCH] vhost_net: Use fdget() and fdput()
  2023-05-05  6:24 [PATCH] vhost_net: Use fdget() and fdput() ye.xingchen
  2023-05-05  6:45 ` Jason Wang
@ 2023-05-11  5:31 ` Al Viro
  1 sibling, 0 replies; 5+ messages in thread
From: Al Viro @ 2023-05-11  5:31 UTC (permalink / raw)
  To: ye.xingchen; +Cc: mst, jasowang, kvm, virtualization, netdev, linux-kernel

On Fri, May 05, 2023 at 02:24:04PM +0800, ye.xingchen@zte.com.cn wrote:
> From: Ye Xingchen <ye.xingchen@zte.com.cn>
> 
> convert the fget()/fput() uses to fdget()/fdput().
> 
> Signed-off-by: Ye Xingchen <ye.xingchen@zte.com.cn>
> ---
>  drivers/vhost/net.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
> index ae2273196b0c..5b3fe4805182 100644
> --- a/drivers/vhost/net.c
> +++ b/drivers/vhost/net.c
> @@ -1466,17 +1466,17 @@ static struct ptr_ring *get_tap_ptr_ring(struct file *file)
> 
>  static struct socket *get_tap_socket(int fd)
>  {
> -	struct file *file = fget(fd);
> +	struct fd f = fdget(fd);
>  	struct socket *sock;
> 
> -	if (!file)
> +	if (!f.file)
>  		return ERR_PTR(-EBADF);
> -	sock = tun_get_socket(file);
> +	sock = tun_get_socket(f.file);
>  	if (!IS_ERR(sock))
>  		return sock;
> -	sock = tap_get_socket(file);
> +	sock = tap_get_socket(f.file);
>  	if (IS_ERR(sock))
> -		fput(file);
> +		fdput(f);
>  	return sock;

NAK.  For the same reason why the sockfd_lookup() counterpart of that
patch is broken.  After your change there's no way for the caller
to tell whether we have bumped the refcount of file in question;
this can't possibly work.

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

end of thread, other threads:[~2023-05-11  5:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-05  6:24 [PATCH] vhost_net: Use fdget() and fdput() ye.xingchen
2023-05-05  6:45 ` Jason Wang
2023-05-05  8:41   ` ye xingchen
2023-05-05 14:59     ` Michael S. Tsirkin
2023-05-11  5:31 ` Al Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).