All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Md Haris Iqbal <haris.iqbal@ionos.com>
Cc: linux-rdma@vger.kernel.org, bvanassche@acm.org, jgg@ziepe.ca,
	jinpu.wang@ionos.com,
	Grzegorz Prajsner <grzegorz.prajsner@ionos.com>
Subject: Re: [PATCH for-next 01/13] RDMA/rtrs-srv: Make rtrs_srv_open fail if its a second call
Date: Sun, 11 Aug 2024 11:38:30 +0300	[thread overview]
Message-ID: <20240811083830.GB5925@unreal> (raw)
In-Reply-To: <20240809131538.944907-2-haris.iqbal@ionos.com>

On Fri, Aug 09, 2024 at 03:15:26PM +0200, Md Haris Iqbal wrote:
> Do not allow opening RTRS server if it is already in use and print
> proper error message.

1. How is it even possible? I see only one call to rtrs_srv_open() and
it is happening when the driver is loaded.
2. You already print an error message, why do you need to add another
one?

Thanks

> 
> Signed-off-by: Md Haris Iqbal <haris.iqbal@ionos.com>
> Signed-off-by: Jack Wang <jinpu.wang@ionos.com>
> Signed-off-by: Grzegorz Prajsner <grzegorz.prajsner@ionos.com>
> ---
>  drivers/infiniband/ulp/rtrs/rtrs-srv.c | 27 +++++++++++++++++++++++---
>  drivers/infiniband/ulp/rtrs/rtrs-srv.h |  1 +
>  2 files changed, 25 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv.c b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
> index 1d33efb8fb03..fb67b58a7f62 100644
> --- a/drivers/infiniband/ulp/rtrs/rtrs-srv.c
> +++ b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
> @@ -2174,9 +2174,18 @@ struct rtrs_srv_ctx *rtrs_srv_open(struct rtrs_srv_ops *ops, u16 port)
>  	struct rtrs_srv_ctx *ctx;
>  	int err;
>  
> +	mutex_lock(&ib_ctx.rtrs_srv_ib_mutex);
> +	if (ib_ctx.srv_ctx) {
> +		pr_err("%s: Already in use.\n", __func__);
> +		ctx = ERR_PTR(-EEXIST);
> +		goto out;
> +	}
> +
>  	ctx = alloc_srv_ctx(ops);
> -	if (!ctx)
> -		return ERR_PTR(-ENOMEM);
> +	if (!ctx) {
> +		ctx = ERR_PTR(-ENOMEM);
> +		goto out;
> +	}
>  
>  	mutex_init(&ib_ctx.ib_dev_mutex);
>  	ib_ctx.srv_ctx = ctx;
> @@ -2185,9 +2194,11 @@ struct rtrs_srv_ctx *rtrs_srv_open(struct rtrs_srv_ops *ops, u16 port)
>  	err = ib_register_client(&rtrs_srv_client);
>  	if (err) {
>  		free_srv_ctx(ctx);
> -		return ERR_PTR(err);
> +		ctx = ERR_PTR(err);
>  	}
>  
> +out:
> +	mutex_unlock(&ib_ctx.rtrs_srv_ib_mutex);
>  	return ctx;
>  }
>  EXPORT_SYMBOL(rtrs_srv_open);
> @@ -2221,10 +2232,16 @@ static void close_ctx(struct rtrs_srv_ctx *ctx)
>   */
>  void rtrs_srv_close(struct rtrs_srv_ctx *ctx)
>  {
> +	mutex_lock(&ib_ctx.rtrs_srv_ib_mutex);
> +	WARN_ON(ib_ctx.srv_ctx != ctx);
> +
>  	ib_unregister_client(&rtrs_srv_client);
>  	mutex_destroy(&ib_ctx.ib_dev_mutex);
>  	close_ctx(ctx);
>  	free_srv_ctx(ctx);
> +
> +	ib_ctx.srv_ctx = NULL;
> +	mutex_unlock(&ib_ctx.rtrs_srv_ib_mutex);
>  }
>  EXPORT_SYMBOL(rtrs_srv_close);
>  
> @@ -2282,6 +2299,9 @@ static int __init rtrs_server_init(void)
>  		goto out_dev_class;
>  	}
>  
> +	mutex_init(&ib_ctx.rtrs_srv_ib_mutex);
> +	ib_ctx.srv_ctx = NULL;
> +
>  	return 0;
>  
>  out_dev_class:
> @@ -2292,6 +2312,7 @@ static int __init rtrs_server_init(void)
>  
>  static void __exit rtrs_server_exit(void)
>  {
> +	mutex_destroy(&ib_ctx.rtrs_srv_ib_mutex);
>  	destroy_workqueue(rtrs_wq);
>  	class_unregister(&rtrs_dev_class);
>  	rtrs_rdma_dev_pd_deinit(&dev_pd);
> diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv.h b/drivers/infiniband/ulp/rtrs/rtrs-srv.h
> index 5e325b82ff33..4924dde0a708 100644
> --- a/drivers/infiniband/ulp/rtrs/rtrs-srv.h
> +++ b/drivers/infiniband/ulp/rtrs/rtrs-srv.h
> @@ -127,6 +127,7 @@ struct rtrs_srv_ib_ctx {
>  	u16			port;
>  	struct mutex            ib_dev_mutex;
>  	int			ib_dev_count;
> +	struct mutex		rtrs_srv_ib_mutex;
>  };
>  
>  extern const struct class rtrs_dev_class;
> -- 
> 2.25.1
> 

  reply	other threads:[~2024-08-11  8:38 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-09 13:15 [PATCH for-next 00/13] Misc patches for RTRS Md Haris Iqbal
2024-08-09 13:15 ` [PATCH for-next 01/13] RDMA/rtrs-srv: Make rtrs_srv_open fail if its a second call Md Haris Iqbal
2024-08-11  8:38   ` Leon Romanovsky [this message]
2024-08-12 10:16     ` Haris Iqbal
2024-08-12 10:34       ` Leon Romanovsky
2024-08-12 10:39         ` Haris Iqbal
2024-08-12 10:59           ` Leon Romanovsky
2024-08-12 11:17             ` Haris Iqbal
2024-08-12 12:15               ` Leon Romanovsky
2024-08-13  9:42                 ` Haris Iqbal
2024-08-09 13:15 ` [PATCH for-next 02/13] RDMA/rtrs-srv: Fix use-after-free during session establishment Md Haris Iqbal
2024-08-11  8:41   ` Leon Romanovsky
2024-08-12 10:52     ` Jinpu Wang
2024-08-12 11:00       ` Leon Romanovsky
2024-08-13 10:54         ` Jinpu Wang
2024-08-09 13:15 ` [PATCH for-next 03/13] RDMA/rtrs: For HB error add additional clt/srv specific logging Md Haris Iqbal
2024-08-09 13:15 ` [PATCH for-next 04/13] RDMA/rtrs-clt: Fix need_inv setting in error case Md Haris Iqbal
2024-08-09 13:15 ` [PATCH for-next 05/13] RDMA/rtrs-clt: Rate limit errors in IO path Md Haris Iqbal
2024-08-09 13:15 ` [PATCH for-next 06/13] RDMA/rtrs: Reset hb_missed_cnt after receiving other traffic from peer Md Haris Iqbal
2024-08-09 13:15 ` [PATCH for-next 07/13] RDMA/rtrs-clt: Reuse need_inval from mr Md Haris Iqbal
2024-08-09 13:15 ` [PATCH for-next 08/13] RDMA/rtrs-clt: Reset cid to con_num - 1 to stay in bounds Md Haris Iqbal
2024-08-09 13:15 ` [PATCH for-next 09/13] RDMA/rtrs-clt: Print request type for errors Md Haris Iqbal
2024-08-09 13:15 ` [PATCH for-next 10/13] RDMA/rtrs-srv: Avoid null pointer deref during path establishment Md Haris Iqbal
2024-08-09 13:15 ` [PATCH for-next 11/13] RDMA/rtrs: register ib event handler Md Haris Iqbal
2024-08-09 13:15 ` [PATCH for-next 12/13] RDMA/rtrs-clt: Do local invalidate after write io completion Md Haris Iqbal
2024-08-09 13:15 ` [PATCH for-next 13/13] RDMA/rtrs-clt: Remove an extra space Md Haris Iqbal
2024-08-11  8:43   ` Leon Romanovsky
2024-08-12  4:10     ` Jinpu Wang
2024-08-12  9:48       ` Zhu Yanjun

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=20240811083830.GB5925@unreal \
    --to=leon@kernel.org \
    --cc=bvanassche@acm.org \
    --cc=grzegorz.prajsner@ionos.com \
    --cc=haris.iqbal@ionos.com \
    --cc=jgg@ziepe.ca \
    --cc=jinpu.wang@ionos.com \
    --cc=linux-rdma@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.