Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp343586rdh; Tue, 19 Dec 2023 00:01:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGzDfRp11cTlIaP7o5AH9MDPQPQY4ZSdLe4zKq+mNzMVukUOaFGNKiZxJHbmF8MxAow1FkT X-Received: by 2002:a05:6870:4f01:b0:203:a55e:3ecc with SMTP id xi1-20020a0568704f0100b00203a55e3eccmr4809114oab.2.1702972876685; Tue, 19 Dec 2023 00:01:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702972876; cv=none; d=google.com; s=arc-20160816; b=xDRdqoifnCAzML1oKvg28mCWlVSjpwSYuL2Tv550Th2n7w8LEk/vYD1eiZHYEztxsG CkQ768pOrHNqGOvyLInH2DJm26RzhgDpxQI9LHea3yi1xTV2ACF8lUPg0Q0lh8c0FvxQ EjjeyzFOA+bRUQrdifAHN0/VQXXS+n+iH/Np9oZw5fXsY37rUdw2UzyWfJt9nM/xbKww kza1+jgftOwwaybeBes2ilsXzyTNhXMVNosLQXEXip7DFxXHz8heBz6cltiGWArKPHBU /S+kFyDgTFjGTQN/B4/+htoQ+ZwqaanLsOwgefEI4gwrL43zrZmgtf1SxDEqLWgntWnR PX8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=x0lkzN84DRIDmQOAtWoiQADrqRlGqZHQ/ALgaZqXTqA=; fh=Ob8FspbdAv2lvfy9oyzcNqJb9FlG/MYewgbmONDw7dw=; b=YMpSyj1m5L9oxZzEgJ+bQ3arNZfwIANUvLF9I6p2ciAQtMJLz7gFKXlZqO0UWoOwX2 XivNSQYOA3ewgG42hyoPVow83ZsI7pLbNHekgE12BgrqOkbttTTi8XBbSdOlc8RTn/lz 9th9RaeKX1+tWXGFdd7L4H41YN1W4wvi5WlOwGIUSt0Dn1+1TQ7X6GlzTYwhNLO/ZtC1 GYbT40o+VPeXm3+zhKTjXhL9XnHEz7oJE+uC5IjLV9vIgLV3l1Dtej+Y7pvk1e59dpy2 Z4l4p/SMHo2MNke+JXuKw5gWhjaiuYknv/FNhbC2drQm2iHUojOobaDiWhyLtmkXbFcW VCeQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-4850-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4850-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k1-20020a63d841000000b005bd039e5a04si19243945pgj.622.2023.12.19.00.01.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 00:01:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4850-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-4850-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4850-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 29E13286C9D for ; Tue, 19 Dec 2023 08:00:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 80F0312B96; Tue, 19 Dec 2023 07:59:20 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C1BA11725 for ; Tue, 19 Dec 2023 07:59:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8395021E5A; Tue, 19 Dec 2023 07:59:11 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2F8EE13AA6; Tue, 19 Dec 2023 07:59:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id FI3uCE9NgWWyegAAD6G6ig (envelope-from ); Tue, 19 Dec 2023 07:59:11 +0000 Message-ID: <725ba59a-68b3-471c-b88c-4515c0415209@suse.de> Date: Tue, 19 Dec 2023 08:59:10 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 08/16] nvmet-fc: untangle cross refcounting objects Content-Language: en-US To: Daniel Wagner , linux-nvme@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Sagi Grimberg , Keith Busch , James Smart References: <20231218153105.12717-1-dwagner@suse.de> <20231218153105.12717-9-dwagner@suse.de> From: Hannes Reinecke In-Reply-To: <20231218153105.12717-9-dwagner@suse.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Level: X-Spam-Level: Authentication-Results: smtp-out1.suse.de; none X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 8395021E5A X-Spam-Flag: NO On 12/18/23 16:30, Daniel Wagner wrote: > Associations take a refcount on queues, queues take a refcount on > associations. > > The existing code lead to the situation that the target executes a > disconnect and the host triggers a reconnect immediately. The reconnect > command still finds an existing association and uses this. Though the > reconnect crashes later on because nvmet_fc_delete_target_assoc() > blindly goes ahead and removes resources while the reconnect code wants > to use it. The problem is that nvmet_fc_find_target_assoc() is able to > lookup an association which is being removed. > > So the first thing to address nvmet_fc_find_target_queue() is to remove > the association out of the list and wait a RCU cycle and free resources > in the free function callback of the kref_put(). > > The live time of the queues are strictly bound to the lifetime of an > association. Thus we don't need to take reverse refcounts (queue -> > association). > > Furthermore, streamline the cleanup code by using the workqueue for > delete the association in nvmet_fc_ls_disconnect. This ensures, that we > run through the same shutdown path in all non error cases. > > Reproducer: nvme/003 > > Signed-off-by: Daniel Wagner > --- > drivers/nvme/target/fc.c | 83 +++++++++++++++++++--------------------- > 1 file changed, 40 insertions(+), 43 deletions(-) > > diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c > index 28e432e62361..db992df13c73 100644 > --- a/drivers/nvme/target/fc.c > +++ b/drivers/nvme/target/fc.c > @@ -166,6 +166,7 @@ struct nvmet_fc_tgt_assoc { > struct nvmet_fc_hostport *hostport; > struct nvmet_fc_ls_iod *rcv_disconn; > struct list_head a_list; > + struct nvmet_fc_tgt_queue *_queues[NVMET_NR_QUEUES + 1]; > struct nvmet_fc_tgt_queue __rcu *queues[NVMET_NR_QUEUES + 1]; > struct kref ref; > struct work_struct del_work; > @@ -803,14 +804,11 @@ nvmet_fc_alloc_target_queue(struct nvmet_fc_tgt_assoc *assoc, > if (!queue) > return NULL; > > - if (!nvmet_fc_tgt_a_get(assoc)) > - goto out_free_queue; > - > queue->work_q = alloc_workqueue("ntfc%d.%d.%d", 0, 0, > assoc->tgtport->fc_target_port.port_num, > assoc->a_id, qid); > if (!queue->work_q) > - goto out_a_put; > + goto out_free_queue; > > queue->qid = qid; > queue->sqsize = sqsize; > @@ -831,7 +829,8 @@ nvmet_fc_alloc_target_queue(struct nvmet_fc_tgt_assoc *assoc, > if (ret) > goto out_fail_iodlist; > > - WARN_ON(assoc->queues[qid]); > + WARN_ON(assoc->_queues[qid]); > + assoc->_queues[qid] = queue; > rcu_assign_pointer(assoc->queues[qid], queue); > Is it really worth is using an rcu pointer here? In the end, creating and deleting queues for an association don't happen that often, and involve some synchronization points anyway. IE the lifetime of the queue is actually bounded by the lifetime of the association itself, so if the association is valid the queues will be valid, too. With that reasoning can't we drop rcu above and use the array directly, delegating any synchronization to the association itself? Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.de +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), GF: Ivo Totev, Andrew McDonald, Werner Knoblich