Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751304AbdFEP5f (ORCPT ); Mon, 5 Jun 2017 11:57:35 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:52342 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751077AbdFEP5d (ORCPT ); Mon, 5 Jun 2017 11:57:33 -0400 X-IronPort-AV: E=Sophos;i="5.39,300,1493654400"; d="scan'208";a="22971896" From: Bart Van Assche To: "target-devel@vger.kernel.org" , "nab@linux-iscsi.org" CC: "linux-scsi@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "mchristi@redhat.com" , "himanshu.madhani@cavium.com" , "quinn.tran@cavium.com" , "hare@suse.com" , "hch@lst.de" Subject: Re: [PATCH 2/3] target: Add TARGET_SCF_LOOKUP_LUN_FROM_TAG support for ABORT_TASK Thread-Topic: [PATCH 2/3] target: Add TARGET_SCF_LOOKUP_LUN_FROM_TAG support for ABORT_TASK Thread-Index: AQHS3LXGqsnyunHB1EO8NM1JQGhLhKIWb24A Date: Mon, 5 Jun 2017 15:57:30 +0000 Message-ID: <1496678246.2623.5.camel@sandisk.com> References: <1496527808-28789-1-git-send-email-nab@linux-iscsi.org> <1496527808-28789-3-git-send-email-nab@linux-iscsi.org> In-Reply-To: <1496527808-28789-3-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: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=sandisk.com; x-originating-ip: [63.163.107.100] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;CY1PR0401MB1535;7:jXUpy0Oc4bVgMcK7M+IGR89ZixgU/9UQ6xa12PnqCFHOsWy1HUuT231ykwd264K5+9pNmyl0Kuy9TvMfYHB4OD+gmGGnzlTMNPmaV9wpWRAZjj8WcmEHPovMbSDlCMrrZEFQDiCmu3iBmkVUnAs6rykR34JzmxPeq+HHDAj0aigZ9SJoIixf0+OFH/DQo/vosBdnO/uOBplvF5UTOUjV63zQLBhJMi/T5WfvOnOKpiEmMZ/vCDRJE62VA5xMW24JPSdPeG4R7JaK0rjOi41h9fVL3i2w40AmmNsZwzhnkPjZgCLGoem0VGCXEkWOVC4CPYNooaZFsr60OKqxWQvFrQ==;20:mvhoTTUpAI3rZhcK47fT2bcP8Owwn07MNx1p7cK/QU0FzgEiTjZGR0U7AELJuGrvvZyS+Lp8sGcmKYtFvUOc8SWdyjdB8nd4xcMWfAci9AJq68XPq5WNLTPjf+k4a7Tsy6sC6dceIHZ+/E1cuKs4ohc7wI9Pf9MRydeRinXb8M4= x-ms-traffictypediagnostic: CY1PR0401MB1535: x-ms-office365-filtering-correlation-id: 7e642ce6-7d13-41b9-729d-08d4ac2b9225 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254075)(48565401081)(201703131423075)(201703031133081);SRVR:CY1PR0401MB1535; wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(10201501046)(93006095)(93001095)(3002001)(6055026)(6041248)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123560025)(20161123562025)(20161123564025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CY1PR0401MB1535;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CY1PR0401MB1535; x-forefront-prvs: 0329B15C8A x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39410400002)(39400400002)(39850400002)(39450400003)(39860400002)(39840400002)(24454002)(377424004)(229853002)(189998001)(3846002)(102836003)(6116002)(103116003)(4326008)(6512007)(86362001)(38730400002)(50986999)(53936002)(6436002)(54906002)(99286003)(25786009)(2950100002)(6486002)(77096006)(66066001)(6506006)(76176999)(5660300001)(54356999)(305945005)(2501003)(7736002)(478600001)(3280700002)(2906002)(3660700001)(72206003)(14454004)(33646002)(36756003)(122556002)(2900100001)(8936002)(8676002)(81166006);DIR:OUT;SFP:1102;SCL:1;SRVR:CY1PR0401MB1535;H:CY1PR0401MB1536.namprd04.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-ID: <062FB2E66570AE488DA94364C5B48DDE@namprd04.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: sandisk.com X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Jun 2017 15:57:30.0800 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0401MB1535 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 quoted-printable to 8bit by mail.home.local id v55Fvi2Q002066 Content-Length: 2219 Lines: 67 On Sat, 2017-06-03 at 22:10 +0000, Nicholas A. Bellinger wrote: > +static bool target_lookup_lun_from_tag(struct se_session *se_sess, u64 tag, > + u64 *unpacked_lun) > +{ > + struct se_cmd *se_cmd; > + unsigned long flags; > + bool ret = false; > + > + spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); > + list_for_each_entry(se_cmd, &se_sess->sess_cmd_list, se_cmd_list) { > + if (se_cmd->se_cmd_flags & SCF_SCSI_TMR_CDB) > + continue; > + > + if (se_cmd->tag == tag) { > + *unpacked_lun = se_cmd->orig_fe_lun; > + ret = true; > + break; > + } > + } > + spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); > + > + return ret; > +} > + > /** > * target_submit_tmr - lookup unpacked lun and submit uninitialized se_cmd > * for TMR CDBs > @@ -1639,19 +1662,31 @@ int target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess, > core_tmr_release_req(se_cmd->se_tmr_req); > return ret; > } > + /* > + * If this is ABORT_TASK with no explicit fabric provided LUN, > + * go ahead and search active session tags for a match to figure > + * out unpacked_lun for the original se_cmd. > + */ > + if (tm_type == TMR_ABORT_TASK && (flags & TARGET_SCF_LOOKUP_LUN_FROM_TAG)) { > + if (!target_lookup_lun_from_tag(se_sess, tag, &unpacked_lun)) > + goto failure; > + } > > ret = transport_lookup_tmr_lun(se_cmd, unpacked_lun); > - if (ret) { > - /* > - * For callback during failure handling, push this work off > - * to process context with TMR_LUN_DOES_NOT_EXIST status. > - */ > - INIT_WORK(&se_cmd->work, target_complete_tmr_failure); > - schedule_work(&se_cmd->work); > - return 0; > - } > + if (ret) > + goto failure; > + > transport_generic_handle_tmr(se_cmd); > return 0; Hello Nic, So after LUN lookup has finished sess_cmd_lock lock is dropped, a context switch occurs due to the queue_work() call in transport_generic_handle_tmr() and next core_tmr_abort_task() reacquires that lock? Sorry but I'm afraid that if after that lock is dropped and before it is reacquired a command finishes and the initiator reuses the same tag for another command for the same LUN that this may result in the wrong command being aborted. Bart.