Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751574AbdFGBNi (ORCPT ); Tue, 6 Jun 2017 21:13:38 -0400 Received: from mail-bl2nam02on0067.outbound.protection.outlook.com ([104.47.38.67]:52544 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751533AbdFGBNf (ORCPT ); Tue, 6 Jun 2017 21:13:35 -0400 From: "Tran, Quinn" To: "Nicholas A. Bellinger" , target-devel CC: linux-scsi , lkml , "Madhani, Himanshu" , Mike Christie , Hannes Reinecke , Christoph Hellwig Subject: Re: [PATCH 1/3] target: Add support for TMR percpu reference counting Thread-Topic: [PATCH 1/3] target: Add support for TMR percpu reference counting Thread-Index: AQHS3LXA4nPXq287nEyePHL7wXCjiKIYJ8mA Date: Wed, 7 Jun 2017 01:13:32 +0000 Message-ID: <386D71C4-353C-4237-8345-3043E8773EAF@cavium.com> References: <1496527808-28789-1-git-send-email-nab@linux-iscsi.org> <1496527808-28789-2-git-send-email-nab@linux-iscsi.org> In-Reply-To: <1496527808-28789-2-git-send-email-nab@linux-iscsi.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: linux-iscsi.org; dkim=none (message not signed) header.d=none;linux-iscsi.org; dmarc=none action=none header.from=cavium.com; x-originating-ip: [198.186.0.2] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;CY4PR07MB3445;7:EzaXeW9sT51AfgOSy/iZVZQmJQ1e1UGHAjsHLp+g8SbpJ6oQSbLqNKyKjJxN8Tmf+tYfxBwaK5E/5fzRx020nMGfgA8BKR+Hz/c11/jjcHmc/NZEfXfFHA1NrWVt9V3E26e4hk8M54AyBPer80tuVeboju3xFhqGEDw7rJIATSp5yvjHAyZgWelDfAv+mzabfBINXIGQnw/i1szD8VcZw8JVHQ6w6m99UMbXEgti8dH59nn2P+ybVXo5zjcUwKn2DW44eUNXSWfzrJG/MQk5QeO98jcJ1vRQPiH1lTy39JrBgKbC7czvPZ0/RKx27aHofzrIk9aLpieGk1062O107w== x-forefront-antispam-report: SFV:SKI;SCL:-1SFV:NSPM;SFS:(10009020)(6009001)(39400400002)(39410400002)(39450400003)(39840400002)(39850400002)(377454003)(13464003)(50986999)(72206003)(189998001)(3660700001)(2906002)(76176999)(8936002)(81166006)(478600001)(33656002)(6506006)(14454004)(2900100001)(8676002)(36756003)(83716003)(3280700002)(54356999)(82746002)(6116002)(25786009)(4326008)(53936002)(53546009)(3846002)(2950100002)(6436002)(66066001)(122556002)(86362001)(54906002)(575784001)(6512007)(6486002)(38730400002)(77096006)(7736002)(305945005)(99286003)(229853002)(6246003)(5660300001)(21314002);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR07MB3445;H:SN1PR07MB2413.namprd07.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; x-ms-traffictypediagnostic: CY4PR07MB3445: x-ms-office365-filtering-correlation-id: 4c2767ad-1331-4445-a2a9-08d4ad426a08 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254075)(201703131423075)(201703031133081);SRVR:CY4PR07MB3445; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(100000703101)(100105400095)(93006095)(93001095)(6041248)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123555025)(20161123564025)(20161123558100)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CY4PR07MB3445;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CY4PR07MB3445; x-forefront-prvs: 03319F6FEF spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="utf-8" Content-ID: <746EC59593ECE143AA45857A96AAED99@namprd07.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Jun 2017 01:13:32.2168 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR07MB3445 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id v571Dggf025600 Content-Length: 4376 Lines: 111 Looks good. Regards, Quinn Tran -----Original Message----- From: Nicholas Bellinger Date: Saturday, June 3, 2017 at 3:10 PM To: target-devel Cc: linux-scsi , lkml , Nicholas Bellinger , "Madhani, Himanshu" , "Tran, Quinn" , Mike Christie , Hannes Reinecke , Christoph Hellwig Subject: [PATCH 1/3] target: Add support for TMR percpu reference counting From: Nicholas Bellinger This patch introduces TMR percpu reference counting using se_lun->lun_ref in transport_lookup_tmr_lun(), following how existing non TMR per se_lun reference counting works within transport_lookup_cmd_lun(). It also adds explicit transport_lun_remove_cmd() calls to drop the reference in the three tmr related locations that invoke transport_cmd_check_stop_to_fabric(); - target_tmr_work() during normal ->queue_tm_rsp() - target_complete_tmr_failure() during error ->queue_tm_rsp() - transport_generic_handle_tmr() during early failure Also, note the exception paths in transport_generic_free_cmd() and transport_cmd_finish_abort() already check SCF_SE_LUN_CMD, and will invoke transport_lun_remove_cmd() when necessary. Cc: Himanshu Madhani Cc: Quinn Tran Cc: Mike Christie Cc: Hannes Reinecke Cc: Christoph Hellwig Signed-off-by: Nicholas Bellinger --- drivers/target/target_core_device.c | 14 ++++++++++---- drivers/target/target_core_transport.c | 3 +++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c index 8f0e0e3..11c80c4 100644 --- a/drivers/target/target_core_device.c +++ b/drivers/target/target_core_device.c @@ -168,11 +168,20 @@ int transport_lookup_tmr_lun(struct se_cmd *se_cmd, u64 unpacked_lun) rcu_read_lock(); deve = target_nacl_find_deve(nacl, unpacked_lun); if (deve) { - se_cmd->se_lun = rcu_dereference(deve->se_lun); se_lun = rcu_dereference(deve->se_lun); + + if (!percpu_ref_tryget_live(&se_lun->lun_ref)) { + se_lun = NULL; + goto out_unlock; + } + + se_cmd->se_lun = rcu_dereference(deve->se_lun); se_cmd->pr_res_key = deve->pr_res_key; se_cmd->orig_fe_lun = unpacked_lun; + se_cmd->se_cmd_flags |= SCF_SE_LUN_CMD; + se_cmd->lun_ref_active = true; } +out_unlock: rcu_read_unlock(); if (!se_lun) { @@ -182,9 +191,6 @@ int transport_lookup_tmr_lun(struct se_cmd *se_cmd, u64 unpacked_lun) unpacked_lun); return -ENODEV; } - /* - * XXX: Add percpu se_lun->lun_ref reference count for TMR - */ se_cmd->se_dev = rcu_dereference_raw(se_lun->lun_se_dev); se_tmr->tmr_dev = rcu_dereference_raw(se_lun->lun_se_dev); diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index f16a789..83bfc97 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -1588,6 +1588,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); } @@ -3199,6 +3200,7 @@ static void target_tmr_work(struct work_struct *work) cmd->se_tfo->queue_tm_rsp(cmd); check_stop: + transport_lun_remove_cmd(cmd); transport_cmd_check_stop_to_fabric(cmd); } @@ -3221,6 +3223,7 @@ int transport_generic_handle_tmr( pr_warn_ratelimited("handle_tmr caught CMD_T_ABORTED TMR %d" "ref_tag: %llu tag: %llu\n", cmd->se_tmr_req->function, cmd->se_tmr_req->ref_task_tag, cmd->tag); + transport_lun_remove_cmd(cmd); transport_cmd_check_stop_to_fabric(cmd); return 0; } -- 1.9.1