netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: yajun.deng@linux.dev
To: "Jakub Kicinski" <kuba@kernel.org>
Cc: davem@davemloft.net, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next] net: socket: integrate sockfd_lookup() and sockfd_lookup_light()
Date: Fri, 24 Sep 2021 02:39:49 +0000	[thread overview]
Message-ID: <d03a2c604913430c8f83c84f02868e6d@linux.dev> (raw)
In-Reply-To: <20210923082453.42096cc7@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com>

September 23, 2021 11:24 PM, "Jakub Kicinski" <kuba@kernel.org> wrote:

> On Wed, 22 Sep 2021 14:31:06 +0800 Yajun Deng wrote:
> 
>> As commit 6cb153cab92a("[NET]: use fget_light() in net/socket.c") said,
>> sockfd_lookup_light() is lower load than sockfd_lookup(). So we can
>> remove sockfd_lookup() but keep the name. As the same time, move flags
>> to sockfd_put().
> 
> You just assume that each caller of sockfd_lookup() already meets the
> criteria under which sockfd_lookup_light() can be used? Am I reading
> this right?
> 
Yes, this patch means each caller of sockfd_lookup() can used sockfd_lookup_light() instead.
> Please extend the commit message clearly walking us thru why this is
> safe now (and perhaps why it wasn't in the past).
>
The sockfd_lookup() and  sockfd_lookup_light() are both safe. The fact that they have been around for so long is the best proof. sockfd_lookup_light() is just lower load than sockfd_lookup(). so we can used the lower load helper function.

>> static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer,
>> size_t size)
>> @@ -1680,9 +1659,9 @@ int __sys_bind(int fd, struct sockaddr __user *umyaddr, int addrlen)
>> {
>> struct socket *sock;
>> struct sockaddr_storage address;
>> - int err, fput_needed;
>> + int err;
>> 
>> - sock = sockfd_lookup_light(fd, &err, &fput_needed);
>> + sock = sockfd_lookup(fd, &err);
>> if (sock) {
>> err = move_addr_to_kernel(umyaddr, addrlen, &address);
>> if (!err) {
>> @@ -1694,7 +1673,7 @@ int __sys_bind(int fd, struct sockaddr __user *umyaddr, int addrlen)
>> (struct sockaddr *)
>> &address, addrlen);
>> }
>> - fput_light(sock->file, fput_needed);
>> + sockfd_put(sock);
> 
> And we just replace fput_light() with fput() even tho the reference was
> taken with fdget()? fdget() == __fget_light().
> 
> Maybe you missed fget() vs fdget()?

In fact, the sockfd_put() already changed in this patch. Here is the modified:
#define                     sockfd_put(sock)             \
do {                                              \
       struct fd *fd = (struct fd *)&sock->file; \
                                                 \
       if (fd->flags & FDPUT_FPUT)               \
               fput(sock->file);                 \
}

> 
> All these changes do not immediately strike me as correct.
> 
This is the information of this patch:
 include/linux/net.h |   8 +++-
 net/socket.c        | 101 +++++++++++++++++---------------------------
 2 files changed, 46 insertions(+), 63 deletions(-)

>> }
>> return err;
>> }

  reply	other threads:[~2021-09-24  2:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-22  6:31 [PATCH net-next] net: socket: integrate sockfd_lookup() and sockfd_lookup_light() Yajun Deng
2021-09-23 15:24 ` Jakub Kicinski
2021-09-24  2:39   ` yajun.deng [this message]
2021-09-23 16:49 ` Eric Dumazet
2021-09-24  2:49   ` yajun.deng
2021-09-24  2:56 ` Al Viro
2021-09-24  3:39   ` yajun.deng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d03a2c604913430c8f83c84f02868e6d@linux.dev \
    --to=yajun.deng@linux.dev \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).