Re: [PATCH] vfio: Use filp instead of fd

From: Al Viro
Date: Mon Sep 26 2022 - 21:37:36 EST


On Tue, Sep 27, 2022 at 01:21:50AM +0000, tomorrow Wang (王德明) wrote:
> 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".

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