[Devel] [PATCH VZ9 v2 1/3] fs/fuse kio: return msg completion error properly to userspace on kRPC

Alexey Kuznetsov kuznet at virtuozzo.com
Wed Jan 22 13:05:16 MSK 2025


Ack all 3 patches

On Wed, Jan 22, 2025 at 5:56 PM Liu Kui <kui.liu at virtuozzo.com> wrote:
>
> Currently if a msg is completed in error, the error is not properly
> returned to userspace making userspace unable to process such error
> correctly. Thus userspace has to abort the connection whenever there's
> a msg completing in error. Even non-fatal error such as the response
> timeout error would result in abortion of the connecion, which is just
> a wrong behaivor.
>
> By passing the response timeout error to userspace, it allows userspace
> to solely rely on the kill timer in kernel rpc for waiting for response.
> Acting this way can remove the possibility that a userpsace request is
> completed before its corresponding request completes in kernel space,
> thus addressing two issues that could otherwise happen, 1) userspace
> receives a stale response from kernel. 2) kernel access buffs that have
> been released in userspace.
>
> Related to #VSTOR-97762
> Signed-off-by: Liu Kui <kui.liu at virtuozzo.com>
> ---
>  fs/fuse/kio/pcs/pcs_krpc.c      | 10 +++-------
>  fs/fuse/kio/pcs/pcs_krpc_prot.h | 10 +++++++---
>  2 files changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/fs/fuse/kio/pcs/pcs_krpc.c b/fs/fuse/kio/pcs/pcs_krpc.c
> index 45ec3cb3207c..2ab1450a0005 100644
> --- a/fs/fuse/kio/pcs/pcs_krpc.c
> +++ b/fs/fuse/kio/pcs/pcs_krpc.c
> @@ -279,21 +279,17 @@ static int pcs_krpc_ioctl_recv_msg(struct pcs_krpc *krpc, struct pcs_krpc_ioc_re
>         krpc->nr_completion--;
>         spin_unlock(&krpc->lock);
>
> -       if (comp->result) {
> -               res -= comp->result;
> -               goto out;
> -       }
> -
>         res = 1;
>         iocmsg->xid = comp->xid;
> -       if (comp->xid == 0) {
> +       if (comp->xid == 0) { /* request */
>                 BUG_ON(!comp->data_len);
>                 BUG_ON(iocmsg->buf.len < comp->data_len);
>                 if (copy_to_user((void __user *)iocmsg->buf.addr, comp->_data_buf, comp->data_len))
>                         res = -EFAULT;
> +       } else { /* response */
> +               iocmsg->result = comp->result;
>         }
>
> -out:
>         krpc_completion_free(comp);
>         return res;
>  }
> diff --git a/fs/fuse/kio/pcs/pcs_krpc_prot.h b/fs/fuse/kio/pcs/pcs_krpc_prot.h
> index 81caa1d53669..812f778a6a06 100644
> --- a/fs/fuse/kio/pcs/pcs_krpc_prot.h
> +++ b/fs/fuse/kio/pcs/pcs_krpc_prot.h
> @@ -7,8 +7,9 @@
>   * kRPC version:
>   * v1: Initial krpc support
>   * v2: Support zerocopy read
> + * v3: Return error code to userspace
>   */
> -#define PCS_KRPC_VERSION 2
> +#define PCS_KRPC_VERSION 3
>
>  /* Device ioctls: */
>  #define PCS_KRPC_IOC_MAGIC  255
> @@ -50,14 +51,17 @@ struct pcs_krpc_ioc_sendmsg {
>         u64             xid;                            /* context id */
>         u32             msg_size;                       /* total size of the msg */
>         u16             timeout;                        /* timeout */
> -       u8              flags;                          /* alignment,  */
> +       u8              flags;                          /* alignment */
>         u8              nr_data_chunks;         /* total number of data chunks */
>         struct pcs_krpc_buf_desc hdr_chunk;     /* the buf holding msg header */
>  };
>
>  struct pcs_krpc_ioc_recvmsg {
>         u64             xid;    /* context id */
> -       struct pcs_krpc_buf_desc buf;   /* for cs congestion notification and rpc keep waiting msg.*/
> +       union {
> +               u32     result; /* for response msg */
> +               struct pcs_krpc_buf_desc buf;   /* for request msg */
> +       };
>  };
>
>  #endif
> --
> 2.39.5 (Apple Git-154)



More information about the Devel mailing list