From: Simon Horman <horms@kernel.org>
To: Hannes Reinecke <hare@suse.de>
Cc: Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
Keith Busch <kbusch@kernel.org>,
linux-nvme@lists.infradead.org, Jakub Kicinski <kuba@kernel.org>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org
Subject: Re: [PATCH 14/17] nvmet-tcp: reference counting for queues
Date: Fri, 11 Aug 2023 12:30:05 +0200 [thread overview]
Message-ID: <ZNYNrYXSS02Qqlvn@vergenet.net> (raw)
In-Reply-To: <20230810150630.134991-15-hare@suse.de>
On Thu, Aug 10, 2023 at 05:06:27PM +0200, Hannes Reinecke wrote:
> The 'queue' structure is referenced from various places and
> used as an argument of asynchronous functions, so it's really
> hard to figure out if the queue is still valid when the
> asynchronous function triggers.
> So add reference counting to validate the queue structure.
>
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
> drivers/nvme/target/tcp.c | 73 ++++++++++++++++++++++++++++++---------
> 1 file changed, 56 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c
> index ce1d1c5f4e90..a79ede885865 100644
> --- a/drivers/nvme/target/tcp.c
> +++ b/drivers/nvme/target/tcp.c
> @@ -127,6 +127,7 @@ enum nvmet_tcp_queue_state {
> };
>
> struct nvmet_tcp_queue {
> + struct kref kref;
> struct socket *sock;
> struct nvmet_tcp_port *port;
> struct work_struct io_work;
> @@ -192,6 +193,8 @@ static struct workqueue_struct *nvmet_tcp_wq;
> static const struct nvmet_fabrics_ops nvmet_tcp_ops;
> static void nvmet_tcp_free_cmd(struct nvmet_tcp_cmd *c);
> static void nvmet_tcp_free_cmd_buffers(struct nvmet_tcp_cmd *cmd);
> +static int nvmet_tcp_get_queue(struct nvmet_tcp_queue *queue);
> +static void nvmet_tcp_put_queue(struct nvmet_tcp_queue *queue);
>
> static inline u16 nvmet_tcp_cmd_tag(struct nvmet_tcp_queue *queue,
> struct nvmet_tcp_cmd *cmd)
> @@ -1437,11 +1440,21 @@ static void nvmet_tcp_restore_socket_callbacks(struct nvmet_tcp_queue *queue)
> struct socket *sock = queue->sock;
>
> write_lock_bh(&sock->sk->sk_callback_lock);
> + /*
> + * Check if nvmet_tcp_set_queue_sock() has been called;
> + * if not the queue reference has not been increased
> + * and we're getting an refcount error on exit.
> + */
> + if (sock->sk->sk_data_ready != nvmet_tcp_data_ready) {
Hi Hannes,
it seems that nvmet_tcp_data_ready is used here,
but doesn't exist until patch 16/17.
> + write_unlock_bh(&sock->sk->sk_callback_lock);
> + return;
> + }
> sock->sk->sk_data_ready = queue->data_ready;
> sock->sk->sk_state_change = queue->state_change;
> sock->sk->sk_write_space = queue->write_space;
> sock->sk->sk_user_data = NULL;
> write_unlock_bh(&sock->sk->sk_callback_lock);
> + nvmet_tcp_put_queue(queue);
> }
...
next prev parent reply other threads:[~2023-08-11 10:30 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-10 15:06 [PATCHv7 00/17] nvme: In-kernel TLS support for TCP Hannes Reinecke
2023-08-10 15:06 ` [PATCH 01/17] nvme-keyring: register '.nvme' keyring Hannes Reinecke
2023-08-10 15:06 ` [PATCH 02/17] nvme-keyring: define a 'psk' keytype Hannes Reinecke
2023-08-10 15:06 ` [PATCH 03/17] nvme: add TCP TSAS definitions Hannes Reinecke
2023-08-10 15:06 ` [PATCH 04/17] nvme-tcp: add definitions for TLS cipher suites Hannes Reinecke
2023-08-10 15:06 ` [PATCH 05/17] nvme-keyring: implement nvme_tls_psk_default() Hannes Reinecke
2023-08-10 15:06 ` [PATCH 06/17] security/keys: export key_lookup() Hannes Reinecke
2023-08-10 15:06 ` [PATCH 07/17] nvme-tcp: allocate socket file Hannes Reinecke
2023-08-11 10:19 ` Simon Horman
2023-08-11 10:32 ` Hannes Reinecke
2023-08-10 15:06 ` [PATCH 08/17] nvme-tcp: enable TLS handshake upcall Hannes Reinecke
2023-08-10 15:06 ` [PATCH 09/17] nvme-tcp: control message handling for recvmsg() Hannes Reinecke
2023-08-10 15:06 ` [PATCH 10/17] nvme-fabrics: parse options 'keyring' and 'tls_key' Hannes Reinecke
2023-08-10 15:06 ` [PATCH 11/17] nvmet: make TCP sectype settable via configfs Hannes Reinecke
2023-08-11 10:24 ` Simon Horman
2023-08-11 10:32 ` Hannes Reinecke
2023-08-10 15:06 ` [PATCH 12/17] nvmet-tcp: make nvmet_tcp_alloc_queue() a void function Hannes Reinecke
2023-08-10 15:06 ` [PATCH 13/17] nvmet-tcp: allocate socket file Hannes Reinecke
2023-08-10 15:06 ` [PATCH 14/17] nvmet-tcp: reference counting for queues Hannes Reinecke
2023-08-11 10:30 ` Simon Horman [this message]
2023-08-11 10:33 ` Hannes Reinecke
2023-08-10 15:06 ` [PATCH 15/17] nvmet: Set 'TREQ' to 'required' when TLS is enabled Hannes Reinecke
2023-08-10 15:06 ` [PATCH 16/17] nvmet-tcp: enable TLS handshake upcall Hannes Reinecke
2023-08-10 15:06 ` [PATCH 17/17] nvmet-tcp: control messages for recvmsg() Hannes Reinecke
-- strict thread matches above, loose matches on Subject: below --
2023-08-11 12:17 [PATCHv8 00/17] nvme: In-kernel TLS support for TCP Hannes Reinecke
2023-08-11 12:17 ` [PATCH 14/17] nvmet-tcp: reference counting for queues Hannes Reinecke
2023-08-13 14:01 ` Sagi Grimberg
2023-08-13 14:38 ` Hannes Reinecke
2023-08-14 7:32 ` Sagi Grimberg
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=ZNYNrYXSS02Qqlvn@vergenet.net \
--to=horms@kernel.org \
--cc=edumazet@google.com \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sagi@grimberg.me \
/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