linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Deming Wang <wangdeming@inspur.com>
Cc: pbonzini@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] vfio: Use filp instead of fd
Date: Mon, 26 Sep 2022 14:23:56 +0100	[thread overview]
Message-ID: <YzGn7JkKsgNtmxiU@ZenIV> (raw)
In-Reply-To: <20220926065407.2389-1-wangdeming@inspur.com>

On Mon, Sep 26, 2022 at 02:54:07AM -0400, Deming Wang wrote:
> The function of kvm_vfio_group_set_spapr_tce and kvm_vfio_group_del
> use fd indirectly.But,it only be used for fd.file. So,we can directly
> use the struct of file instead.
> 
> Signed-off-by: Deming Wang <wangdeming@inspur.com>

NAK.  fget() is for the cases when we must keep the reference across the
syscall boundary/pass to another thread/etc.

If fdget() is applicable, it's a better alternative.  And I would suggest
you to look at the generated code - it pretty much turns into
	struct file *file;
	int need_fput;

	r = __fdget(fd);
	need_fput = r & 3;
	r &= ~3;
	file = (struct file *)r;

	....

	if (unlikely(need_fput))
		fput(file);

Note that we are *not* actually passing a structure out of a function, etc. -
fdget() is inlined and out-of-line part returns unsigned long.  Lower two bits
carry flags, the rest - file pointer.  Rearrangement into struct fd is done
in the caller and compiler manages to dissolve that struct into a couple of
local variables.

Incidentally, pretty much the only thing in struct fd besides struct file pointer
is that "have we failed to skip bumping the reference count?" flag.  Between
fdget() and fdput() only the file pointer is used - in all users.  fdput()
uses the flag to decide whether it needs to bother with refcount at all.

  reply	other threads:[~2022-09-26 14:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-26  6:54 [PATCH] vfio: Use filp instead of fd Deming Wang
2022-09-26 13:23 ` Al Viro [this message]
2022-09-26 17:07 ` Jason Gunthorpe
2022-09-26 19:38   ` Al Viro
2022-09-27  1:21 tomorrow Wang (王德明)
2022-09-27  1:37 ` Al Viro
2022-09-27  1:25 tomorrow Wang (王德明)

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=YzGn7JkKsgNtmxiU@ZenIV \
    --to=viro@zeniv.linux.org.uk \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=wangdeming@inspur.com \
    /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).