public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Li Zhijian <lizhijian@fujitsu.com>
Cc: linux-rdma@vger.kernel.org, jgg@ziepe.ca
Subject: Re: [PATCH rdma-core] libibverbs/man/ibv_reg_mr.3: Document errno on failure
Date: Tue, 17 Oct 2023 10:01:41 +0200	[thread overview]
Message-ID: <874jipd6e2.fsf@pond.sub.org> (raw)
In-Reply-To: <20231017053738.226069-1-lizhijian@fujitsu.com> (Li Zhijian's message of "Tue, 17 Oct 2023 13:37:37 +0800")

Li Zhijian <lizhijian@fujitsu.com> writes:

> 'errno' is being widely used by applications when ibv_reg_mr returns NULL.
> They all believe errno indicates the error on failure, so let's document
> it explicitly.

Similar issue with ibv_open_device() .  Possibly more.

> Reported-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
> ---
>  libibverbs/man/ibv_reg_mr.3 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libibverbs/man/ibv_reg_mr.3 b/libibverbs/man/ibv_reg_mr.3
> index 8f323891..d43799c5 100644
> --- a/libibverbs/man/ibv_reg_mr.3
> +++ b/libibverbs/man/ibv_reg_mr.3
> @@ -103,7 +103,7 @@ deregisters the MR
>  .I mr\fR.
>  .SH "RETURN VALUE"
>  .B ibv_reg_mr() / ibv_reg_mr_iova() / ibv_reg_dmabuf_mr()
> -returns a pointer to the registered MR, or NULL if the request fails.
> +returns a pointer to the registered MR, or NULL if the request fails (and sets errno to indicate the failure reason).
>  The local key (\fBL_Key\fR) field
>  .B lkey
>  is used as the lkey field of struct ibv_sge when posting buffers with

We should double-check errno is set on all failures.  I doubt it is.

ibv_reg_mr() is a macro:

    #define ibv_reg_mr(pd, addr, length, access)                                   \
            __ibv_reg_mr(pd, addr, length, access,                                 \
                         __builtin_constant_p(				       \
                                 ((int)(access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))

__ibv_reg_mr() may call ibv_reg_mr_iova2():

    __attribute__((__always_inline__)) static inline struct ibv_mr *
    __ibv_reg_mr(struct ibv_pd *pd, void *addr, size_t length, unsigned int access,
                 int is_access_const)
    {
            if (is_access_const && (access & IBV_ACCESS_OPTIONAL_RANGE) == 0)
                    return ibv_reg_mr(pd, addr, length, (int)access);
            else
                    return ibv_reg_mr_iova2(pd, addr, length, (uintptr_t)addr,
                                            access);
    }

ibv_reg_mr_iova2() doesn't seem to set errno at --->:

    struct ibv_mr *ibv_reg_mr_iova2(struct ibv_pd *pd, void *addr, size_t length,
                                    uint64_t iova, unsigned int access)
    {
            struct verbs_device *device = verbs_get_device(pd->context->device);
            bool odp_mr = access & IBV_ACCESS_ON_DEMAND;
            struct ibv_mr *mr;

            if (!(device->core_support & IB_UVERBS_CORE_SUPPORT_OPTIONAL_MR_ACCESS))
                    access &= ~IBV_ACCESS_OPTIONAL_RANGE;

            if (!odp_mr && ibv_dontfork_range(addr, length))
--->                return NULL;

            mr = get_ops(pd->context)->reg_mr(pd, addr, length, iova, access);
            if (mr) {
                    mr->context = pd->context;
                    mr->pd      = pd;
                    mr->addr    = addr;
                    mr->length  = length;
            } else {
                    if (!odp_mr)
                            ibv_dofork_range(addr, length);
            }

            return mr;
    }


Thanks!


  reply	other threads:[~2023-10-17  8:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-17  5:37 [PATCH rdma-core] libibverbs/man/ibv_reg_mr.3: Document errno on failure Li Zhijian
2023-10-17  8:01 ` Markus Armbruster [this message]
2023-10-18  1:11   ` Zhijian Li (Fujitsu)
2023-10-18  4:45     ` Markus Armbruster
2023-10-18  6:14       ` Zhijian Li (Fujitsu)

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=874jipd6e2.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-rdma@vger.kernel.org \
    --cc=lizhijian@fujitsu.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