From patchwork Fri Feb 28 21:17:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Zakharov X-Patchwork-Id: 1248141 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=delphix.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=delphix.com header.i=@delphix.com header.a=rsa-sha256 header.s=google header.b=clkGHsQg; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48WqFT22dHz9sRY; Tue, 3 Mar 2020 19:00:42 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1j92Th-0002dp-9M; Tue, 03 Mar 2020 08:00:33 +0000 Received: from mail-pf1-f196.google.com ([209.85.210.196]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1j7n1E-0002kA-A0 for kernel-team@lists.ubuntu.com; Fri, 28 Feb 2020 21:18:00 +0000 Received: by mail-pf1-f196.google.com with SMTP id 2so2327391pfg.12 for ; Fri, 28 Feb 2020 13:18:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=delphix.com; s=google; h=from:content-transfer-encoding:mime-version:subject:date:references :to:in-reply-to:message-id; bh=+nnUIReXhLXwepcvfQwjOyksa7TLIZOcVqNxbVlxdv8=; b=clkGHsQgv+ytsdSwVS3evBPATmNI5BEWA8FM5UVBgSUBdinHlmaMwyAotuxlIcLV0J zfHRdQMq5Bhz9Txt6b84ntWTAFIq5VHfDzhryxBqgaTl3oFHKUTU11FjD/10hBbkR9lC 2xauFACqXYTSo0OkS4cQFUQtP7xIFT8VE1FqE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:date:references:to:in-reply-to:message-id; bh=+nnUIReXhLXwepcvfQwjOyksa7TLIZOcVqNxbVlxdv8=; b=JsvMUaYZTK3dFz4nZ2x5qrkx6TIfgZCCl0ECoC6UT1nMRYd2ly5qvdzeMMz+oIZpX/ W0mZz3KW4CxF6+HjmLdL23u5gIrkUzQoioCVX3ahgLt5CWaBhynY+J3qgS/wr5IkmrNx SdF7CNU4YgBC2lnnUNtr2uPiGIQO5iXWHaFblQKv79Iwp5C5rZDVM8jCEDoeoMHa5T4g +2n7jJB1wEvJd3dBQjgszvX9ohYp42tvKMWau/APSbwsriGao83smMTsqsPLUQ264Eu9 9RnwS5S5CCamH+97gZhhahK/EvWyLzcyW2UP5F5keHiyGYvffAPrXbVjsz8DUBiHYe8V jRXA== X-Gm-Message-State: APjAAAXGz3LwOh3Bo37LsBPQh13ZjQXykzq7SW/+xXAHqMSqtw+scEGD N7OUz7jDoiYr0ylMCe3Ib4M2nes4s9P5t9hYh8cuZcLmUKqkutrQnrs78xs4Mi0y8dLEGfl+CML jJj8Hcrm6jqCuzp/IdfisUu9A87484LQnUyNi+/2cp4m7NstdqLt087JmbXlCyYbsGimqfUhgXF prAu9dQg== X-Google-Smtp-Source: APXvYqwWwVLtJWHf0e+fDAYk0irHKvZ2dRZNpbkGSEHXh7NBXS3+dKEDcKcDWokHuUJUBgfn5SVo1A== X-Received: by 2002:a63:257:: with SMTP id 84mr6336225pgc.304.1582924678534; Fri, 28 Feb 2020 13:17:58 -0800 (PST) Received: from [192.168.0.102] (modemcable127.167-81-70.mc.videotron.ca. [70.81.167.127]) by smtp.gmail.com with ESMTPSA id 1sm8264791pff.11.2020.02.28.13.17.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Feb 2020 13:17:57 -0800 (PST) From: Pavel Zakharov Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) Subject: [PATCH 1/1] [bionic hwe kernel] scsi: Revert "target/core: Inline transport_lun_remove_cmd()" Date: Fri, 28 Feb 2020 16:17:56 -0500 References: To: kernel-team@lists.ubuntu.com In-Reply-To: Message-Id: <0C7C69F2-1753-46CE-BC8B-7959CE2962F1@delphix.com> X-Mailer: Apple Mail (2.3608.60.0.2.5) X-Mailman-Approved-At: Tue, 03 Mar 2020 08:00:30 +0000 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/ubuntu/+source/linux-hwe/+bug/1862682 scsi: Revert "target/core: Inline transport_lun_remove_cmd()" Commit 83f85b8ec305 postponed the percpu_ref_put(&se_cmd->se_lun->lun_ref) call from command completion to the time when the final command reference is dropped. That approach is not compatible with the iSCSI target driver because the iSCSI target driver keeps the command with the highest stat_sn after it has completed until the next command is received (see also iscsit_ack_from_expstatsn()). Fix this regression by reverting commit 83f85b8ec305. Fixes: 83f85b8ec305 ("scsi: target/core: Inline transport_lun_remove_cmd()") Cc: Pavel Zakharov Cc: Mike Christie Cc: Link: https://lore.kernel.org/r/20200210051202.12934-1-bvanassche@acm.org Reported-by: Pavel Zakharov Signed-off-by: Bart Van Assche Signed-off-by: Martin K. Petersen Acked-by: Andrea Righi Acked-by: Seth Forshee --- drivers/target/target_core_transport.c | 31 +++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index eda8b4736c15..d542e26ca56a 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -666,6 +666,11 @@ static int transport_cmd_check_stop_to_fabric(struct se_cmd *cmd) target_remove_from_state_list(cmd); + /* + * Clear struct se_cmd->se_lun before the handoff to FE. + */ + cmd->se_lun = NULL; + spin_lock_irqsave(&cmd->t_state_lock, flags); /* * Determine if frontend context caller is requesting the stopping of @@ -693,6 +698,17 @@ static int transport_cmd_check_stop_to_fabric(struct se_cmd *cmd) return cmd->se_tfo->check_stop_free(cmd); } +static void transport_lun_remove_cmd(struct se_cmd *cmd) +{ + struct se_lun *lun = cmd->se_lun; + + if (!lun) + return; + + if (cmpxchg(&cmd->lun_ref_active, true, false)) + percpu_ref_put(&lun->lun_ref); +} + static void target_complete_failure_work(struct work_struct *work) { struct se_cmd *cmd = container_of(work, struct se_cmd, work); @@ -783,6 +799,8 @@ static void target_handle_abort(struct se_cmd *cmd) WARN_ON_ONCE(kref_read(&cmd->cmd_kref) == 0); + transport_lun_remove_cmd(cmd); + transport_cmd_check_stop_to_fabric(cmd); } @@ -1695,6 +1713,7 @@ static void target_complete_tmr_failure(struct work_struct *work) se_cmd->se_tmr_req->response = TMR_LUN_DOES_NOT_EXIST; se_cmd->se_tfo->queue_tm_rsp(se_cmd); + transport_lun_remove_cmd(se_cmd); transport_cmd_check_stop_to_fabric(se_cmd); } @@ -1885,6 +1904,7 @@ void transport_generic_request_failure(struct se_cmd *cmd, goto queue_full; check_stop: + transport_lun_remove_cmd(cmd); transport_cmd_check_stop_to_fabric(cmd); return; @@ -2182,6 +2202,7 @@ static void transport_complete_qf(struct se_cmd *cmd) transport_handle_queue_full(cmd, cmd->se_dev, ret, false); return; } + transport_lun_remove_cmd(cmd); transport_cmd_check_stop_to_fabric(cmd); } @@ -2276,6 +2297,7 @@ static void target_complete_ok_work(struct work_struct *work) if (ret) goto queue_full; + transport_lun_remove_cmd(cmd); transport_cmd_check_stop_to_fabric(cmd); return; } @@ -2301,6 +2323,7 @@ static void target_complete_ok_work(struct work_struct *work) if (ret) goto queue_full; + transport_lun_remove_cmd(cmd); transport_cmd_check_stop_to_fabric(cmd); return; } @@ -2336,6 +2359,7 @@ static void target_complete_ok_work(struct work_struct *work) if (ret) goto queue_full; + transport_lun_remove_cmd(cmd); transport_cmd_check_stop_to_fabric(cmd); return; } @@ -2371,6 +2395,7 @@ static void target_complete_ok_work(struct work_struct *work) break; } + transport_lun_remove_cmd(cmd); transport_cmd_check_stop_to_fabric(cmd); return; @@ -2697,6 +2722,9 @@ int transport_generic_free_cmd(struct se_cmd *cmd, int wait_for_tasks) */ if (cmd->state_active) target_remove_from_state_list(cmd); + + if (cmd->se_lun) + transport_lun_remove_cmd(cmd); } if (aborted) cmd->free_compl = &compl; @@ -2768,9 +2796,6 @@ static void target_release_cmd_kref(struct kref *kref) struct completion *abrt_compl = se_cmd->abrt_compl; unsigned long flags; - if (se_cmd->lun_ref_active) - percpu_ref_put(&se_cmd->se_lun->lun_ref); - if (se_sess) { spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); list_del_init(&se_cmd->se_cmd_list);