Skip to contentSkip to conversation

vfio: Use filp instead of fd

PATCH tomorrow Wang (王德明) 2 participants 2 messages Sep 27, 2022 KVM

lore
Share & tools
lore
#0 lore raw

Hi

Why kvm_vfio_group_add use file.

  struct file *filp;
  .....
  filp = fget(fd);

  .....
  kvg->file = filp;
  ......
  fput(filp);
Quoted 17 lines

from: Al Viro <[email protected]> 代表 Al Viro
time: 2022-9-22 3:38
to: Jason Gunthorpe <[email protected]>
[email protected]; [email protected]; [email protected]
sub: Re: [PATCH] vfio: Use filp instead of fd

Quoted 10 lines · Jason Gunthorpe
Quoted 8 lines · Deming Wang

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.

---
 virt/kvm/vfio.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
Quoted 6 lines
Quoted 3 lines

I thought about changing this too when I was looking at this. fdget/fdput includes a tiny micro-optimization that is legal here, however I doubt anyone cares about performance on this path.

Microoptimization or not, I'd rather keep fget() limited to cases where we really need it. There are non-trivial cases and having them easy to find

is a

Quoted 3 lines

good thing.

Again, the preferred way to do descriptor lookups is fdget() family, not

fget()

Quoted 1 line

one.

#1 lore raw
Quoted 10 lines · tomorrow Wang (王德明)

Hi

Why kvm_vfio_group_add use file.

  struct file *filp;
  .....
  filp = fget(fd);

  .....
  kvg->file = filp;

This is why. Note that you've slightly misquoted it - it's actually either "stick into kvg->file" or "fput() it".

Quoted 2 lines
  ......
  fput(filp);

The reference we are getting here is non-transient one; it will be retained in shared data structures after we return from function - hell, after we return to userland.