Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp439495rdh; Tue, 19 Dec 2023 03:47:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IHnNGUh8wdLvQl9QOQtbxS8i1hZIA5nVs9JEEyOSV5j/fkiCzbPhPWo2hdNOI1/Q6txHSot X-Received: by 2002:a17:90a:d484:b0:28b:a821:5f54 with SMTP id s4-20020a17090ad48400b0028ba8215f54mr1152644pju.1.1702986459993; Tue, 19 Dec 2023 03:47:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702986459; cv=none; d=google.com; s=arc-20160816; b=s9mrpCQG6VRV65M8hdbGmVpkiOjR0KBva8DSP8h/0j46LAmt0GPui/NM4dATebTNRj 6smh5CW8Ankje9vN3XX9PnWaRblqKSITgBMHysvu3hK38NXCl20H/KpRKvhwGgy46Pku X9GQLKATdawULSB8XjJ8qoVuA3oUWd8Tua+2vRMSeCp4Ynw3WEuVHkoAh6vJ76znpOfQ xVQjXRMrE6OkFAzwrV7lfwbJV6S9pZAUL7xctD/naOsawq9g9f/IWr9RIqF//Q1edEvl /RpJlUM6hDFmwCh6RtplYoRSuf7Lc+iSC9dYEN518dgkIfQvQviiiRxFZ/iIuFjNl6UQ fPeQ== 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=90Ov7f8WsCK7gMvEaqYj5UwgMSiF1IJBbf7h/BD7tOk=; fh=Ob8FspbdAv2lvfy9oyzcNqJb9FlG/MYewgbmONDw7dw=; b=XqpYlkQKS5LuKkoOHauY7vH0PHJF+sF/5EgWA6Twse9oPeqd9j/5G9jNn9fmXB2MOJ ol/K46aN2pIqVydSTg9jMnOU19uSg23Lr+zAqD91dYVrZnOu2JnKoMV10Pup5sF6BZFS pEYqUDl3gvw+Qail+Ytop4EkLwL6MkhFJBpiVY2fXr3rUHQtAkHDKxvjZerGDD9Zdlok XLYfRu3iTevm0h7BVeSjzSmX9lqiokfHEyguNJmf0OAgcTx/sKPZWlBCWA71Sze3AFzd CEQUQk9akcZXnD8wwi+Yg0v3VOz9YfDszhINeO1ZLMsSFpaBBVf2ZU8ioKsRDCD/Al4S GBPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-5102-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5102-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 f7-20020a17090aa78700b00280479459f7si1048143pjq.50.2023.12.19.03.47.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 03:47:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5102-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-5102-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5102-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 A30EE284729 for ; Tue, 19 Dec 2023 11:47:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4E8717752; Tue, 19 Dec 2023 11:47:15 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 D359E171CD for ; Tue, 19 Dec 2023 11:47:13 +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-out2.suse.de (Postfix) with ESMTPS id 0AF261F7C5; Tue, 19 Dec 2023 11:47:12 +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 8C48B1375D; Tue, 19 Dec 2023 11:47:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id l5XxHL+CgWUGOAAAD6G6ig (envelope-from ); Tue, 19 Dec 2023 11:47:11 +0000 Message-ID: <87f65f4d-0a3e-44af-ade8-c9326e5642f9@suse.de> Date: Tue, 19 Dec 2023 12:47: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 16/16] nvmet-fc: take ref count on tgtport before delete assoc 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-17-dwagner@suse.de> From: Hannes Reinecke In-Reply-To: <20231218153105.12717-17-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-out2.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: 0AF261F7C5 X-Spam-Flag: NO On 12/18/23 16:31, Daniel Wagner wrote: > We have to ensure that the tgtport is not going away > before be have remove all the associations. before we have removed all the associations. > > Signed-off-by: Daniel Wagner > --- > drivers/nvme/target/fc.c | 31 +++++++++++++++++++++++-------- > 1 file changed, 23 insertions(+), 8 deletions(-) > > diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c > index 30ba4ede333f..455d35ef97eb 100644 > --- a/drivers/nvme/target/fc.c > +++ b/drivers/nvme/target/fc.c > @@ -1092,13 +1092,28 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle) > } > > static void > -nvmet_fc_delete_assoc(struct work_struct *work) > +nvmet_fc_delete_assoc(struct nvmet_fc_tgt_assoc *assoc) > +{ > + nvmet_fc_delete_target_assoc(assoc); > + nvmet_fc_tgt_a_put(assoc); > +} > + > +static void > +nvmet_fc_delete_assoc_work(struct work_struct *work) > { > struct nvmet_fc_tgt_assoc *assoc = > container_of(work, struct nvmet_fc_tgt_assoc, del_work); > + struct nvmet_fc_tgtport *tgtport = assoc->tgtport; > > - nvmet_fc_delete_target_assoc(assoc); > - nvmet_fc_tgt_a_put(assoc); > + nvmet_fc_delete_assoc(assoc); > + nvmet_fc_tgtport_put(tgtport); > +} > + > +static void > +nvmet_fc_schedule_delete_assoc(struct nvmet_fc_tgt_assoc *assoc) > +{ > + nvmet_fc_tgtport_get(assoc->tgtport); > + queue_work(nvmet_wq, &assoc->del_work); Errm. That is dangerous, as it will leak a reference if 'del_work' is already queued. And we already took a reference from the caller. Why do we need two references here? 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