lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YzGn7JkKsgNtmxiU@ZenIV>
Date:   Mon, 26 Sep 2022 14:23:56 +0100
From:   Al Viro <viro@...iv.linux.org.uk>
To:     Deming Wang <wangdeming@...pur.com>
Cc:     pbonzini@...hat.com, kvm@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] vfio: Use filp instead of fd

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@...pur.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.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ