From patchwork Wed Jan 31 08:51:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 194609 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1758753dyb; Wed, 31 Jan 2024 01:02:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IGeeZLaKtv62/z8+6ykZ09pGSyXUVBtZZJvmK3WGQaRZqbRK9vF2e6ple15h/1q2ExgDQC+ X-Received: by 2002:a2e:87da:0:b0:2cd:10be:cf14 with SMTP id v26-20020a2e87da000000b002cd10becf14mr655824ljj.19.1706691749799; Wed, 31 Jan 2024 01:02:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706691749; cv=pass; d=google.com; s=arc-20160816; b=R5NIQkuqQrGbq5YsaF9zXpWrf0wiLbo1BzvOfv3AeefHU7xpSyBrpN2744UaOILuGE 7RyamxiFXMLT5KF/R9P0pDSz50SuNaeXDiNtKGO6O5HBzzG+9MP3/81beWcbLDwqXUBE qIUmOO/axJB/UCMPaIWDbajtjXtWjoZdqTT5WEpI0oe6AivENtiyJ07OkzMbyM7akeNA zLHBLEYzNJCbZEkWGnF9WKO2HVPm4lktxJp//7ClOTnOKO9VIwuQ7G98jWaH8OMkr6uG BR2FIkQ5HnlpHdbCXODCOj516vwGg5nbjq9qJG+xcLJtcHL79+vMGxbB6gpS4Ql86eaR +mow== 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=0WJCIq9El8S03OfhOtOXy9wpk3gzPO/oiT1fajRv6tE=; fh=WeooRxVrpfIxs1JQc+ohNzZouvXgnNeERSqVLSCWoX4=; b=Pze2GJ8CG3+ZcUpbs7e7YeXSVx5pjr9ggOnw+mqUZBN5wcd1Xc/OTZ9o+MtGu1B4ui nZ4u/kSKPNryCup0AfAEdYU8F16E3QD0VGxhzfbvseQ+3/KEVVlXoWV2XEL1XeN0kZ3B dUBs7W6AXRtlvCZ/QP6KyespmCOHjA/kSQIUzKpdrK8HNKdI1MRbxgmo+ocwmuyIqUgA knRsojOlDMfOjVv/DB+dU5SYFfyc6CNifAncc1EWmFpfs34XtXyJ4kSI5ZSzgDl0MsXB IXvZU/pS1zUnDlhN2KB/IG+cMWwwjxu+xSP0HlwCJYOEL6hFr8dL10UqAUpvwUawh9zr UhrQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=OBXC8oQP; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=OBXC8oQP; 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-46079-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46079-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=1; AJvYcCURTbHJtdGuXN5rqDGGyQjEoDzXheT2Eq2PTzvwvRW5OikhlGp4Hqr/3nY6bBqrhRxCktdwg+tyjRe7nT3ixTFEqMdq5Q== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id eg42-20020a05640228aa00b0055f85a0eca9si444884edb.649.2024.01.31.01.02.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 01:02:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46079-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=OBXC8oQP; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=OBXC8oQP; 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-46079-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46079-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 355391F2F0C3 for ; Wed, 31 Jan 2024 09:02:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5420383CAB; 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="OBXC8oQP"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="6obWJHvi"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="OBXC8oQP"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="6obWJHvi" 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 B72287D3EE for ; Wed, 31 Jan 2024 08:51:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706691092; cv=none; b=qi1uvE7FRCApFsneBTSqfLsPXhNw4PtC7xDCA2r72yl/1nhpFEaPsm7v1u51zzs7DnkEWRjCECBfutEri1SB8MLggSk/ydR8Tp+ihcqfPXF5uNVA+0y5wHKQBu1qYB+ITHPvnyTxTZVR3jOxJSgmrjRP0BKskJcLZYRDfmTev3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706691092; c=relaxed/simple; bh=Z9gWC2G25hCWGCl47+YRayYU2N/Ai94DE14vEa8Sbcs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kSXEXmraJjcGVeMosz8dp///MQsv8fFlH/l3Qkbs70Zyp1SuV10JaG5Q0FrmoGA/5/yYp2diBTijr/r9Y9Fdz9YynB6DcJkiuXzG/jzPnyFSj9S5/KbTAKni+SmBYWvJWzlCbtUk97cD5/K4KYxwqx313Z43Ws6/jhKAztuvBDg= 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=OBXC8oQP; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=6obWJHvi; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=OBXC8oQP; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=6obWJHvi; arc=none smtp.client-ip=195.135.223.131 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 DB16C1FD0B; 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=0WJCIq9El8S03OfhOtOXy9wpk3gzPO/oiT1fajRv6tE=; b=OBXC8oQPr6ZF0lYYOWW6O0jhMCGW57QX750Z990q/UulyRcUaIKSe40O09i53JAPsYJ77u Z2r/MqGPjzBDi7FGkkdEEstlGHwxATon3cPcFRtRKNvvPH0OrovLIdI4pRiZg/an4Sr+Cm ERoozcOyGvyKLvucAuvDktLqKIEA/Lk= 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=0WJCIq9El8S03OfhOtOXy9wpk3gzPO/oiT1fajRv6tE=; b=6obWJHviNgPTc5jV/mxydkQyiR4M9kuwUWGO7nG1tgF5cy5rF5tFgg0TOvx9WYmza1mE9N vgUnqp0mQaL5wKCw== 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=0WJCIq9El8S03OfhOtOXy9wpk3gzPO/oiT1fajRv6tE=; b=OBXC8oQPr6ZF0lYYOWW6O0jhMCGW57QX750Z990q/UulyRcUaIKSe40O09i53JAPsYJ77u Z2r/MqGPjzBDi7FGkkdEEstlGHwxATon3cPcFRtRKNvvPH0OrovLIdI4pRiZg/an4Sr+Cm ERoozcOyGvyKLvucAuvDktLqKIEA/Lk= 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=0WJCIq9El8S03OfhOtOXy9wpk3gzPO/oiT1fajRv6tE=; b=6obWJHviNgPTc5jV/mxydkQyiR4M9kuwUWGO7nG1tgF5cy5rF5tFgg0TOvx9WYmza1mE9N vgUnqp0mQaL5wKCw== 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 C90DA132FA; 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 dtunLxAKumWfHAAAn2gu4w (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 12/12] nvmet-fc: use RCU list iterator for assoc_list Date: Wed, 31 Jan 2024 09:51:12 +0100 Message-ID: <20240131085112.21668-13-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 Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: ** X-Spam-Score: 2.26 X-Spamd-Result: default: False [2.26 / 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]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_RATELIMIT(0.00)[to_ip_from(RL7u6ok1g4a6hhe6aduz96x8er)]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-1.44)[91.26%] X-Spam-Flag: NO X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789596008034041340 X-GMAIL-MSGID: 1789596008034041340 The assoc_list is a RCU protected list, thus use the RCU flavor of list functions. Let's use this opportunity and refactor this code and move the lookup into a helper and give it a descriptive name. Signed-off-by: Daniel Wagner Reviewed-by: Christoph Hellwig --- drivers/nvme/target/fc.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c index 671d096745a5..fd229f310c93 100644 --- a/drivers/nvme/target/fc.c +++ b/drivers/nvme/target/fc.c @@ -1114,14 +1114,27 @@ nvmet_fc_schedule_delete_assoc(struct nvmet_fc_tgt_assoc *assoc) queue_work(nvmet_wq, &assoc->del_work); } +static bool +nvmet_fc_assoc_exits(struct nvmet_fc_tgtport *tgtport, u64 association_id) +{ + struct nvmet_fc_tgt_assoc *a; + + list_for_each_entry_rcu(a, &tgtport->assoc_list, a_list) { + if (association_id == a->association_id) + return true; + } + + return false; +} + static struct nvmet_fc_tgt_assoc * nvmet_fc_alloc_target_assoc(struct nvmet_fc_tgtport *tgtport, void *hosthandle) { - struct nvmet_fc_tgt_assoc *assoc, *tmpassoc; + struct nvmet_fc_tgt_assoc *assoc; unsigned long flags; + bool done; u64 ran; int idx; - bool needrandom = true; if (!tgtport->pe) return NULL; @@ -1145,24 +1158,21 @@ nvmet_fc_alloc_target_assoc(struct nvmet_fc_tgtport *tgtport, void *hosthandle) INIT_WORK(&assoc->del_work, nvmet_fc_delete_assoc_work); atomic_set(&assoc->terminating, 0); - while (needrandom) { + done = false; + do { get_random_bytes(&ran, sizeof(ran) - BYTES_FOR_QID); ran = ran << BYTES_FOR_QID_SHIFT; spin_lock_irqsave(&tgtport->lock, flags); - needrandom = false; - list_for_each_entry(tmpassoc, &tgtport->assoc_list, a_list) { - if (ran == tmpassoc->association_id) { - needrandom = true; - break; - } - } - if (!needrandom) { + rcu_read_lock(); + if (!nvmet_fc_assoc_exits(tgtport, ran)) { assoc->association_id = ran; list_add_tail_rcu(&assoc->a_list, &tgtport->assoc_list); + done = true; } + rcu_read_unlock(); spin_unlock_irqrestore(&tgtport->lock, flags); - } + } while (!done); return assoc;