Received: by 2002:a05:7412:8d06:b0:f9:332d:97f1 with SMTP id bj6csp32701rdb; Mon, 18 Dec 2023 08:10:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFj8vDKpzZQzskycplIWlEq/DgH1i55r3wKvYJ8+Ky+/Egda8AvbHh329b1qJyLVGpMOI/W X-Received: by 2002:a25:c5c8:0:b0:dbc:e421:a25 with SMTP id v191-20020a25c5c8000000b00dbce4210a25mr3850512ybe.56.1702915835527; Mon, 18 Dec 2023 08:10:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702915835; cv=none; d=google.com; s=arc-20160816; b=VQqvot0uZ53LK5O6/XM+zQdZxOB+/UsSD6m/WM6OEqxqY6FUlkUeYAzNz3QiRmDwOD kOx91vvAePENesbYNcMKsOUO52LHobTDwdPRT9lHCkbxRhQqGFyK9RLg11mc4N0Ub77U O0Sy2VdKNeOyTUJH0CT3Gvw8ioqb6PF6JNbBsdhtCt6qgtcUOnrxTB37cQTGfSWAOKRu XmZjIDFdH8I9Z2hSN5kVUaCTC4AQLdDK/zXAgXH3OyVo3NPWaQZnlGJmQuwRojmIRpm6 dmFT82o4Vf5M9rYUg2UsCD7a8efpk5xp71hX4PJxRztkLRw/zRwD0eMsbz+gae/0atw1 kFAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-signature :dkim-signature:dkim-signature; bh=pT1da3yYKXyrC7sy+ZTSZeuGrK+DTVOGLpaUNBqQiAI=; fh=3QIVKsEmsld8rvcEkMSr/XDw53o2lrGJeYcvS7FhzFk=; b=Th8P9OI0GAtURgxcRinBUJnphOHJfxz0xlxhXUtpv0DHhV2E2GYfCXFZscVnFp3iCc 4fb2NKY3BZuD/jbrZ93FdJ7sn5mezAYBN9IrSjXndf2zMXmxN5qIYqLrZVfeNdKiWe/T tGuz3iFxMwtZBFCcOpfX1SuvlUj94ew/B46ALos2uD066DQjFemn28JUAPuK83aycmb1 EuZFZodJDoOo/hiLJFHOeSFmCA0m/mN+szUSUegkT6yKLe9qDvb/guRVZyUQPwcF7xYH m6ryyYeGOCnF+/DC4KJLT/cgqb9oJfhDrjMBCkVy8O0xHfTaLeZAkzWFWIwNdbuCtGEU YLaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=ImVs09QW; dkim=neutral (no key) header.i=@suse.de; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=ImVs09QW; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=ZcUJmiE4; spf=pass (google.com: domain of linux-kernel+bounces-4036-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4036-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id z62-20020a25c941000000b00dbd415a0046si512820ybf.73.2023.12.18.08.10.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 08:10:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4036-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=ImVs09QW; dkim=neutral (no key) header.i=@suse.de; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=ImVs09QW; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=ZcUJmiE4; spf=pass (google.com: domain of linux-kernel+bounces-4036-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4036-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 362621C25A51 for ; Mon, 18 Dec 2023 16:10:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 53D044FF94; Mon, 18 Dec 2023 16:09:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ImVs09QW"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="ZcUJmiE4"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ImVs09QW"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="ZcUJmiE4" 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 622E44FF7D for ; Mon, 18 Dec 2023 16:09:37 +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 imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 497601FD48; Mon, 18 Dec 2023 16:09:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702915775; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pT1da3yYKXyrC7sy+ZTSZeuGrK+DTVOGLpaUNBqQiAI=; b=ImVs09QWr+H5axHHqzsCSVZgrRo1wpONoUbGbLKn22emcN2DmK6RgxkqBojHlJwzKGiooR uM2ZqggbdV4evnTi6LwJrH3HwirHKzkeormRDNZPdTPHMTAJSimM4Bbytfuo4o8e59jClH LIm0WUOcUnO87dpAJ4nsxuK2mp44tuE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702915775; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pT1da3yYKXyrC7sy+ZTSZeuGrK+DTVOGLpaUNBqQiAI=; b=ZcUJmiE4ulqboLe1YEFNrEmJ+MiR1Mnwj0xVeJUZmpjtsg1mlvgnpWCyv2fIK4oAIvajku SD1vUzh2o6JWlzAg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702915775; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pT1da3yYKXyrC7sy+ZTSZeuGrK+DTVOGLpaUNBqQiAI=; b=ImVs09QWr+H5axHHqzsCSVZgrRo1wpONoUbGbLKn22emcN2DmK6RgxkqBojHlJwzKGiooR uM2ZqggbdV4evnTi6LwJrH3HwirHKzkeormRDNZPdTPHMTAJSimM4Bbytfuo4o8e59jClH LIm0WUOcUnO87dpAJ4nsxuK2mp44tuE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702915775; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pT1da3yYKXyrC7sy+ZTSZeuGrK+DTVOGLpaUNBqQiAI=; b=ZcUJmiE4ulqboLe1YEFNrEmJ+MiR1Mnwj0xVeJUZmpjtsg1mlvgnpWCyv2fIK4oAIvajku SD1vUzh2o6JWlzAg== Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 2F60613BD5; Mon, 18 Dec 2023 16:09:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id NeRiCb9ugGVzBAAAn2gu4w (envelope-from ); Mon, 18 Dec 2023 16:09:35 +0000 From: Daniel Wagner To: linux-nvme@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Sagi Grimberg , Keith Busch , James Smart , Hannes Reinecke , Daniel Wagner Subject: [PATCH v3 16/16] nvmet-fc: take ref count on tgtport before delete assoc Date: Mon, 18 Dec 2023 16:31:04 +0100 Message-ID: <20231218153105.12717-17-dwagner@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231218153105.12717-1-dwagner@suse.de> References: <20231218153105.12717-1-dwagner@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Level: X-Spam-Level: X-Spamd-Result: default: False [0.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.00)[32.84%] Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 0.90 X-Spam-Flag: NO We have to ensure that the tgtport is not going away before be have remove 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); } static struct nvmet_fc_tgt_assoc * @@ -1129,7 +1144,7 @@ nvmet_fc_alloc_target_assoc(struct nvmet_fc_tgtport *tgtport, void *hosthandle) assoc->a_id = idx; INIT_LIST_HEAD(&assoc->a_list); kref_init(&assoc->ref); - INIT_WORK(&assoc->del_work, nvmet_fc_delete_assoc); + INIT_WORK(&assoc->del_work, nvmet_fc_delete_assoc_work); atomic_set(&assoc->terminating, 0); while (needrandom) { @@ -1489,7 +1504,7 @@ __nvmet_fc_free_assocs(struct nvmet_fc_tgtport *tgtport) list_for_each_entry_rcu(assoc, &tgtport->assoc_list, a_list) { if (!nvmet_fc_tgt_a_get(assoc)) continue; - queue_work(nvmet_wq, &assoc->del_work); + nvmet_fc_schedule_delete_assoc(assoc); nvmet_fc_tgt_a_put(assoc); } rcu_read_unlock(); @@ -1542,7 +1557,7 @@ nvmet_fc_invalidate_host(struct nvmet_fc_target_port *target_port, continue; assoc->hostport->invalid = 1; noassoc = false; - queue_work(nvmet_wq, &assoc->del_work); + nvmet_fc_schedule_delete_assoc(assoc); nvmet_fc_tgt_a_put(assoc); } spin_unlock_irqrestore(&tgtport->lock, flags); @@ -1587,7 +1602,7 @@ nvmet_fc_delete_ctrl(struct nvmet_ctrl *ctrl) nvmet_fc_tgtport_put(tgtport); if (found_ctrl) { - queue_work(nvmet_wq, &assoc->del_work); + nvmet_fc_schedule_delete_assoc(assoc); nvmet_fc_tgt_a_put(assoc); return; } @@ -1894,7 +1909,7 @@ nvmet_fc_ls_disconnect(struct nvmet_fc_tgtport *tgtport, nvmet_fc_xmt_ls_rsp(tgtport, oldls); } - queue_work(nvmet_wq, &assoc->del_work); + nvmet_fc_schedule_delete_assoc(assoc); nvmet_fc_tgt_a_put(assoc); return false; -- 2.43.0