From patchwork Wed Jan 31 08:51:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 194608 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1758712dyb; Wed, 31 Jan 2024 01:02:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IFpqqbeD24rBI/IN/LnKWrDjmgiPzvkQ2pG5X9nJXIbntH8L1haYnF/24e9SGWwGhX4+FkF X-Received: by 2002:a05:6808:2227:b0:3bd:d9b7:3539 with SMTP id bd39-20020a056808222700b003bdd9b73539mr1030088oib.58.1706691746102; Wed, 31 Jan 2024 01:02:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706691746; cv=pass; d=google.com; s=arc-20160816; b=NCUZGUU3hYjsbhw/u2+Fi+Zs00pE4Ud7JP8dDj1hKGRVrRTOCesfcXwmKSdQ/jyaTj 0Pjqvb3L4pC0HrXP080OOR+y6O6OdJAh0+IJhOXziZUPOqAlN2Err6yMM4m3F9wKF7Lb KMdWS2hfaM8z/QCPmL/o2FvOzRQVA0IzDWHm3SoQwNzWfY3dCBeuOTnxLkqZTYnyeGVc PszPL2M/TnBoXmQZsCHPXXp/wwp80kQhzNdgkhmmZCx1L+maSHR7tNL9KQhvaaYPxh// 35qpMoyxMpJwG+HnnQBcfDp71SU0yJ79Yu2juxtRpD8aCFxxJCv7ehgBoNAo0ZaWq1jp UWGQ== ARC-Message-Signature: i=2; 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=1RccLVPeuDGJShj+itd22iKKYBOPrPLhet0mwFJk8h8=; fh=16TvTpakM7tV02SPF07H6OjI0iHnR2CfvMlkKiQbJ8E=; b=K6ZO7m8kabvuDUMwFj2S3QrkiZ+klfKMYs5oSWCTrNq8RObEhDlwAeKV2o69vLLOQG 73BZA5Iby5CUviCowrFsYepWFi0Y1KOAoB8D7izaQ4ECT9ixJSoUc2fc2Bn3pIqlbwe+ eY8OS6wkQ9J0PbHiNBYmZIy/WkAWtF/4ti4AnJua66gC4o0zy+F7iW+lvLHNizQdOEp5 2a9CmG5W0GAc7r2PrNmFkFcjd4a17zdSPni6aMy9KLgkrY5utQ/FST5K30tF9hdz5tL+ gmRuLZL8ZrzNvTChi9/XKX/I1PjemDWeuSKMHCY0FONOTBwoWH9QCwMpZ2tujldVDZvn Kxfw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=BD6Uap8i; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=BD6Uap8i; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-46078-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46078-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=1; AJvYcCUlLgAi+7EEO045FkTcAZRKGe4W2ZrAicVAcAA8dxa3S/+7yZuUPGgt7EHD7LHsdxLyx8s+LulOl5aNXyoy89w3NfzgmQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id p10-20020a05622a048a00b0042a74f7bb28si11606434qtx.255.2024.01.31.01.02.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 01:02:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46078-ouuuleilei=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=BD6Uap8i; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=BD6Uap8i; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-46078-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46078-ouuuleilei=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 CF77F1C21039 for ; Wed, 31 Jan 2024 09:02:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 09C0683CA2; Wed, 31 Jan 2024 08:51:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="BD6Uap8i"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="+yQqcfwl"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="BD6Uap8i"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="+yQqcfwl" 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 02CAF7BB01 for ; Wed, 31 Jan 2024 08:51:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706691092; cv=none; b=nz6ennUwR8IdLEIxj22UCg+N47PVkr14SfzgwMTPwHi2kfthlw55ZReKdNfoWPBlm1C/faPkPR0d2d9K4rw+towW4mjOELemtU10jIvX29v/2Y7w3xAzDneJ3z/LJl0FTB6bQfwKrUKfs/KG0RKHi804tt/IDWhXDASfbCta+78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706691092; c=relaxed/simple; bh=DBT5Bd1JyMH+5VSIGkjF0+xBscgyzH9ln98uX9KLatU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tC3VFVO/h5Z9BgyHGofHR9eefCjDa3Xaf831auPljaUoVUvdEVCx316ybAjoIqIfFS31ndbQSz89tYENlpS1jex+f/Ov92Rh0Bwglx7xlFgeXojp5PceIkILqRXJ+NNiLiv6gu3kn0/BYPHy4QcIUcsG9avZj8jfS3Q9mO1O2qY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=BD6Uap8i; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=+yQqcfwl; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=BD6Uap8i; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=+yQqcfwl; arc=none smtp.client-ip=195.135.223.130 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 [IPv6:2a07:de40:b281:104: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-out1.suse.de (Postfix) with ESMTPS id 409D02219B; Wed, 31 Jan 2024 08:51:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706691088; 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=1RccLVPeuDGJShj+itd22iKKYBOPrPLhet0mwFJk8h8=; b=BD6Uap8iGbTzE6Ba9pKHy63KcBEpLugprHgyNIg+6imuCoy5nPIQXWzNMl2cH6aM4/StXe ntqx4Xn0W69BB3Y0jCzlx3nDykywZIoRQ4P4nd385OqcaB2jv2w4G96jgzIRZjZXVZ9uPB p3NotjkWIJqiGPwynm2emqIAdxe5PnQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706691088; 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=1RccLVPeuDGJShj+itd22iKKYBOPrPLhet0mwFJk8h8=; b=+yQqcfwlM5VeEIzObJr+Vn9YNpOBZ5P1Du4iYnX8B96PSbwwE5lu9DCaErMdXrd+Jr6gSf FjhQCAdk3sLqkqDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706691088; 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=1RccLVPeuDGJShj+itd22iKKYBOPrPLhet0mwFJk8h8=; b=BD6Uap8iGbTzE6Ba9pKHy63KcBEpLugprHgyNIg+6imuCoy5nPIQXWzNMl2cH6aM4/StXe ntqx4Xn0W69BB3Y0jCzlx3nDykywZIoRQ4P4nd385OqcaB2jv2w4G96jgzIRZjZXVZ9uPB p3NotjkWIJqiGPwynm2emqIAdxe5PnQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706691088; 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=1RccLVPeuDGJShj+itd22iKKYBOPrPLhet0mwFJk8h8=; b=+yQqcfwlM5VeEIzObJr+Vn9YNpOBZ5P1Du4iYnX8B96PSbwwE5lu9DCaErMdXrd+Jr6gSf FjhQCAdk3sLqkqDA== 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 2CCA4132FA; Wed, 31 Jan 2024 08:51:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id ylF+CRAKumWdHAAAn2gu4w (envelope-from ); Wed, 31 Jan 2024 08:51:28 +0000 From: Daniel Wagner To: James Smart Cc: Keith Busch , Christoph Hellwig , Hannes Reinecke , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Daniel Wagner Subject: [PATCH v5 11/12] nvmet-fc: take ref count on tgtport before delete assoc Date: Wed, 31 Jan 2024 09:51:11 +0100 Message-ID: <20240131085112.21668-12-dwagner@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131085112.21668-1-dwagner@suse.de> References: <20240131085112.21668-1-dwagner@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=BD6Uap8i; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=+yQqcfwl X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-2.86 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; 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]; DWL_DNSWL_HI(-3.50)[suse.de:dkim]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_RATELIMIT(0.00)[to_ip_from(RLpnha4b14dfhn8rk8ih15dcuu)]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-2.85)[99.34%] X-Spam-Score: -2.86 X-Rspamd-Queue-Id: 409D02219B X-Spam-Flag: NO X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789596004549120881 X-GMAIL-MSGID: 1789596004549120881 We have to ensure that the tgtport is not going away before be have remove all the associations. Reviewed-by: Christoph Hellwig 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 3e0d391e631b..671d096745a5 100644 --- a/drivers/nvme/target/fc.c +++ b/drivers/nvme/target/fc.c @@ -1090,13 +1090,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 * @@ -1127,7 +1142,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) { @@ -1483,7 +1498,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(); @@ -1536,7 +1551,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); @@ -1581,7 +1596,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; } @@ -1888,7 +1903,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;