From patchwork Tue Jul 19 02:07:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 592417 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2B5BC433EF for ; Tue, 19 Jul 2022 02:07:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236824AbiGSCHL (ORCPT ); Mon, 18 Jul 2022 22:07:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236794AbiGSCHK (ORCPT ); Mon, 18 Jul 2022 22:07:10 -0400 Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70A273CBED; Mon, 18 Jul 2022 19:07:03 -0700 (PDT) Received: from pps.filterd (m0297266.ppops.net [127.0.0.1]) by mx0a-00230701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26IMdcaV011679; Mon, 18 Jul 2022 19:07:01 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h=date : message-id : in-reply-to : references : from : subject : to : cc; s=pfptdkimsnps; bh=SNxVebTkJtrdJ3jPqQRlMFu+48h4yZEszNJ0G8H3mvI=; b=pNqwmCjJtKSUiwJS1UODYPs+NbyPA2F3nFj+F7IOfR4kQaPDDxR6lJnKLWCgYXSSHf2s V8SFM1glTQ5unHGNzwfGL5iEw1/HZsoPaUBJoow6GfFWhSebz8e21iVr0lOQclwP2VWZ h5tcKlF89UZuanhmf7phv3sdyZsszDYbHpo5T7hbcIqMQGOcbYdsgTOeHZnVJfxMIW5P ysd31Ns13y19DUx+MjoodJb6ioM1zYXk/GIwL5bPoUcvMHI70oPh3NA9b8SyXcwVBNWz p4aO7tVNEzVwLol1cpi/MvKUm2seDIVXR6DcrwoaY9t6RF7d0tCRfX8ueJYgNhFn0xto 1w== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hbvk5wnv6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 19:07:01 -0700 Received: from mailhost.synopsys.com (sv1-mailhost1.synopsys.com [10.205.2.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 82DF040097; Tue, 19 Jul 2022 02:07:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658196421; bh=stlln6nZ9iLk2UzcbhO1hBFrRMvJ8sq1R2eq5f9T1nc=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=TqTlAcYKEZJO+gN3fr7knjYGL+FY7LBxECmn8cvzJtSH+BvZHd7sGrvpwIvSVJdIE u4WvrM2V5BIGIz9AFWrvx4huJmUprMlElQjv8YeUTW/G8mpI4VJXDncbJAiu58ASDX EHLRFqti3F1ezw1U49sp09jrOSudILZRx9b/bljUENqlwl2/tpyK/VBPdSgLqx99UY XhZ8Qtl15CASDVP1DiDpFsQbJmRhvoyJFKlix9ax2tSarDBEH2kDxSRfujT9bzpVNi wGLVSTQl6E8DCQXM6GDB+sOF2ZyGrXsAmRzvByHtTRDnc6AIDFJKHi9J2pL0VLGjq9 CdWaC91n6j6Gw== Received: from te-lab16-v2 (nanobot.internal.synopsys.com [10.204.48.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id 6477CA0062; Tue, 19 Jul 2022 02:07:00 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 19:07:00 -0700 Date: Mon, 18 Jul 2022 19:07:00 -0700 Message-Id: <41806206e78812afe97101a11881f5a33092a93b.1658195608.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 1/4] target: Handle MI_REPORT_SUPPORTED_OPERATION_CODES To: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, "Martin K. Petersen" Cc: John Youn , Thinh Nguyen , linux-usb@vger.kernel.org X-Proofpoint-GUID: ipO6XqndCbxzJR7rx7-FAIMM4N6Oc3iW X-Proofpoint-ORIG-GUID: ipO6XqndCbxzJR7rx7-FAIMM4N6Oc3iW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 mlxscore=0 phishscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=999 malwarescore=0 clxscore=1015 bulkscore=0 impostorscore=0 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190006 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Microsoft Windows checks for MI_REPORT_SUPPORTED_OPERATION_CODES. Let's handle this MAINTENANCE_IN command and report supported commands. Signed-off-by: Thinh Nguyen --- Changes in v2: - Fix spec section number - Fix potential invalid "buf" access on error drivers/target/target_core_alua.c | 70 +++++++++++++++++++++++++++++++ drivers/target/target_core_alua.h | 2 + drivers/target/target_core_spc.c | 14 ++++++- 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c index b56ef8af66e7..881e04ce8544 100644 --- a/drivers/target/target_core_alua.c +++ b/drivers/target/target_core_alua.c @@ -259,6 +259,76 @@ target_emulate_report_target_port_groups(struct se_cmd *cmd) return 0; } +/* + * REPORT_SUPPORTED_OPERATION_CODES + * + * See spc4r37 section 6.35 + */ +sense_reason_t +target_emulate_report_supported_opcodes(struct se_cmd *cmd) +{ + unsigned char *cdb = cmd->t_task_cdb; + unsigned char *buf; + + /* + * Only supports reporting option 1. + * i.e. one command parameter with no service action. + */ + if ((cdb[2] & 0x7) != 1) { + pr_warn("Unsupported reporting op code %d\n", cdb[2]); + return TCM_UNSUPPORTED_SCSI_OPCODE; + } + + buf = transport_kmap_data_sg(cmd); + if (!buf) + return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; + + switch (cdb[3]) { + case INQUIRY: + case MODE_SENSE: + case MODE_SENSE_10: + case READ_CAPACITY: + case SERVICE_ACTION_IN_16: + case REPORT_LUNS: + case REQUEST_SENSE: + case SYNCHRONIZE_CACHE: + case REZERO_UNIT: + case SEEK_6: + case SEEK_10: + case TEST_UNIT_READY: + case SEND_DIAGNOSTIC: + case MAINTENANCE_IN: + case READ_6: + case READ_10: + case READ_16: + case WRITE_6: + case WRITE_10: + case WRITE_16: + case VERIFY_16: + case MODE_SELECT: + case MODE_SELECT_10: + case START_STOP: + case SECURITY_PROTOCOL_IN: + case SECURITY_PROTOCOL_OUT: + /* Supported */ + buf[1] = 3; + break; + case ATA_12: + case ATA_16: + case VERIFY: + case ZBC_IN: + case ZBC_OUT: + default: + /* Not supported */ + buf[1] = 1; + break; + } + + transport_kunmap_data_sg(cmd); + target_complete_cmd(cmd, SAM_STAT_GOOD); + return 0; +} + /* * SET_TARGET_PORT_GROUPS for explicit ALUA operation. * diff --git a/drivers/target/target_core_alua.h b/drivers/target/target_core_alua.h index fc9637cce825..7941e4dd4f97 100644 --- a/drivers/target/target_core_alua.h +++ b/drivers/target/target_core_alua.h @@ -82,6 +82,8 @@ extern struct kmem_cache *t10_alua_tg_pt_gp_cache; extern struct kmem_cache *t10_alua_lba_map_cache; extern struct kmem_cache *t10_alua_lba_map_mem_cache; +extern sense_reason_t +target_emulate_report_supported_opcodes(struct se_cmd *cmd); extern sense_reason_t target_emulate_report_target_port_groups(struct se_cmd *); extern sense_reason_t target_emulate_set_target_port_groups(struct se_cmd *); extern sense_reason_t target_emulate_report_referrals(struct se_cmd *); diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c index c14441c89bed..dd799158609d 100644 --- a/drivers/target/target_core_spc.c +++ b/drivers/target/target_core_spc.c @@ -1425,15 +1425,25 @@ spc_parse_cdb(struct se_cmd *cmd, unsigned int *size) break; case MAINTENANCE_IN: if (dev->transport->get_device_type(dev) != TYPE_ROM) { + u8 action = cdb[1] & 0x1f; + /* * MAINTENANCE_IN from SCC-2 * Check for emulated MI_REPORT_TARGET_PGS */ - if ((cdb[1] & 0x1f) == MI_REPORT_TARGET_PGS) { + if (action == MI_REPORT_TARGET_PGS) { cmd->execute_cmd = target_emulate_report_target_port_groups; + + *size = get_unaligned_be32(&cdb[6]); + } + + if (action == MI_REPORT_SUPPORTED_OPERATION_CODES) { + cmd->execute_cmd = + target_emulate_report_supported_opcodes; + + *size = get_unaligned_be16(&cdb[2]); } - *size = get_unaligned_be32(&cdb[6]); } else { /* * GPCMD_SEND_KEY from multi media commands From patchwork Tue Jul 19 02:07:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 591826 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85505CCA482 for ; Tue, 19 Jul 2022 02:07:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236840AbiGSCHT (ORCPT ); Mon, 18 Jul 2022 22:07:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236826AbiGSCHL (ORCPT ); Mon, 18 Jul 2022 22:07:11 -0400 Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 535703CBC1; Mon, 18 Jul 2022 19:07:09 -0700 (PDT) Received: from pps.filterd (m0098571.ppops.net [127.0.0.1]) by mx0a-00230701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26INZLSP002294; Mon, 18 Jul 2022 19:07:08 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h=date : message-id : in-reply-to : references : from : subject : to : cc; s=pfptdkimsnps; bh=WgGVOB8Ap/20zmrB/FXibF8XifuR+mhQyeOI03RIZ3E=; b=ZHkbnsgprY+5h2ry9sWFgkjFTFHCbhNooyxJ4IOfJJ5htPnY3rSAc9Tnz53RBpr7LZYS vm0zKHGSWORGrG30VgK70v0iRSU5xnZmXrcbQT/WTySFoxLSHbJHlxxYWm5X66UKr8JA lrV+rGmkkH4g914K+LwPbx4bqILvtNDafHfR05ATRVO8m9oisWpvEmfkSGsAbBAkEgcs JCcxCICnJVSbOd8RRW1xl3pjpxLM4mlH2upF2kjtpnBbjzqhHB9WDe5FETBORUV/G6f/ KxUeS9j3J+iUDiMRGnsTwxakDnmcoDBtrLwDp/CgYSM78iPKdO2mdMiXZCXoFs4MQKfK ug== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hbvbmwp3y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 19:07:07 -0700 Received: from mailhost.synopsys.com (sv2-mailhost2.synopsys.com [10.205.2.134]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 9C6CC4008A; Tue, 19 Jul 2022 02:07:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658196427; bh=YQOi3Xh6MI9X20tUJ2V6XY2RbBF8uzpSd/E7E0vuObc=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=D6x514FqWwBqzTosZ5OqADj/gJvU6JOnPCxoGgID+q4pAMT06F4t8gUd2Z8CrrbUY BuUpGwbhpa3icQe0vam3wZRpSsAibi4GEYWwrRfApZTp2uk38WVrVtKry7iBI0eAjj w5X6oeFqgdRGJ8DMtqfWN7U/DHXlPxqRjuB1h+SbuiRrqKM7ZVtiWgRLkscvKBMYdv TP7oDChBKljEanbsRCfhdHgNBV33VpL6pBWUMEPfusREwMt0cwMv2RhhL4q/mlfUUc FQHMz7cVjXj0mBXUeUsEZ29DyQHe5E2u1VoTZ1IuDiRW1SgC9qG+XvSyqKEdP0QMw0 U1PPdAsYww3+g== Received: from te-lab16-v2 (nanobot.internal.synopsys.com [10.204.48.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id 7BD1CA0096; Tue, 19 Jul 2022 02:07:06 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 19:07:06 -0700 Date: Mon, 18 Jul 2022 19:07:06 -0700 Message-Id: <7d31722a7e07bc24ea37b5841a17545003eeddb4.1658195608.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 2/4] target: Implement TMR_ABORT_TASK_SET To: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, "Martin K. Petersen" Cc: John Youn , Thinh Nguyen , linux-usb@vger.kernel.org X-Proofpoint-GUID: s81H--f_BuqU9qPK3droKXqHJNdkqXkT X-Proofpoint-ORIG-GUID: s81H--f_BuqU9qPK3droKXqHJNdkqXkT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 clxscore=1015 priorityscore=1501 impostorscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190006 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Task ABORT TASK SET function is required by SCSI transport protocol standards (SAM-4 r14 section 7.3). It is similar to ABORT TASK function, but it applies to all commands received on a specified I_T nexus rather than a specific referenced command. Modify core_tmr_abort_task() to support TMR_ABORT_TASK_SET. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/target/target_core_tmr.c | 16 +++++++++++----- drivers/target/target_core_transport.c | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c index bac111456fa1..1ea72e15f872 100644 --- a/drivers/target/target_core_tmr.c +++ b/drivers/target/target_core_tmr.c @@ -131,11 +131,13 @@ void core_tmr_abort_task( continue; ref_tag = se_cmd->tag; - if (tmr->ref_task_tag != ref_tag) - continue; + if (tmr->function == TMR_ABORT_TASK) { + if (tmr->ref_task_tag != ref_tag) + continue; - pr_err("ABORT_TASK: Found referenced %s task_tag: %llu\n", - se_cmd->se_tfo->fabric_name, ref_tag); + pr_err("ABORT_TASK: Found referenced %s task_tag: %llu\n", + se_cmd->se_tfo->fabric_name, ref_tag); + } spin_lock(&se_sess->sess_cmd_lock); rc = __target_check_io_state(se_cmd, se_sess, 0); @@ -158,7 +160,11 @@ void core_tmr_abort_task( ref_tag); tmr->response = TMR_FUNCTION_COMPLETE; atomic_long_inc(&dev->aborts_complete); - return; + + if (tmr->function == TMR_ABORT_TASK) + return; + + spin_lock_irqsave(&dev->queues[i].lock, flags); } spin_unlock_irqrestore(&dev->queues[i].lock, flags); } diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 7838dc20f713..8c386142ef90 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -3519,9 +3519,9 @@ static void target_tmr_work(struct work_struct *work) switch (tmr->function) { case TMR_ABORT_TASK: + case TMR_ABORT_TASK_SET: core_tmr_abort_task(dev, tmr, cmd->se_sess); break; - case TMR_ABORT_TASK_SET: case TMR_CLEAR_ACA: case TMR_CLEAR_TASK_SET: tmr->response = TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED; From patchwork Tue Jul 19 02:07:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 592416 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CCC0C43334 for ; Tue, 19 Jul 2022 02:07:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236813AbiGSCHd (ORCPT ); Mon, 18 Jul 2022 22:07:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236847AbiGSCH0 (ORCPT ); Mon, 18 Jul 2022 22:07:26 -0400 Received: from mx0b-00230701.pphosted.com (mx0b-00230701.pphosted.com [148.163.158.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA52E3CBF1; Mon, 18 Jul 2022 19:07:21 -0700 (PDT) Received: from pps.filterd (m0098572.ppops.net [127.0.0.1]) by mx0b-00230701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26IM6Jb6020769; Mon, 18 Jul 2022 19:07:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h=date : message-id : in-reply-to : references : from : subject : to : cc; s=pfptdkimsnps; bh=jfyPUay4vdlY2wbJjo0EIhVwHezxBiYRmPBUyNCQMIs=; b=eXS/TW8GnLLbEUPRg+W+gcvR4NTjzxx1CtQC918RjG/Y2HwiIWAu24x5R6fdDYy7mX+y AoJkb4gW2xIg+vfSqB2J25so/0o1tcQUz+fKRfAJvFVnqEKOO0Yz30wVqt+4kYXKqQDj da/AsaUG0ULuukmS0h6Bw2Dc024Sg2SRH745yUo1NM4pz5Wbd2vng5A4XU8K4ZNsEFnr zsgqjO/DTlBYZ8f+ZaQN3H+QseAJPv+iDeeXRG3JQ3suRbWT83A4z+7X9zndhSTWyVlh J2gAZROT9etAJI30xCC3DOmuUMIl9GWz7VOhPLJFXcagZXnVG5nFwHUNCbGTXqJv1nHl 7A== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by mx0b-00230701.pphosted.com (PPS) with ESMTPS id 3hc6c349ck-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 19:07:15 -0700 Received: from mailhost.synopsys.com (sv2-mailhost2.synopsys.com [10.205.2.134]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 465EBC0649; Tue, 19 Jul 2022 02:07:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658196434; bh=wiOq5LEF/yNaIM4h+LuNwuRf93wV7htfSQbdTsNLLyg=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Z1XaYkBFs3g/FYEzwsUTxUCCmXMNxhOCSmP1H56tt3uOqcW/n95EEAomVOOJ2wNAu eO6qS+t4i4T/oXMY0rUN0i41zyYGuESzXW32n+BaVxzxwx4QXH5QfttADo0v6cgOGJ y7DdIrKlm8sr7G97NQ3VpxSVNj92QLXaFsRmKO8WXU9aFUAJ7S4LbWi26ly0KuhfdK Cf9aqlwvWOpedu/EaVle2hz30oJ3EDn0+Z0Z92nkIUvKB8un4Gq+bM6IhkL6KWi3WT BbVKYlgXYMjVO5x4roxdA1ubLut114q/HbDioUuwox31DhFymSUO92uW/QMl2UmlE/ NmY/aAkNR0ftw== Received: from te-lab16-v2 (nanobot.internal.synopsys.com [10.204.48.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id 99686A0096; Tue, 19 Jul 2022 02:07:12 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 19:07:12 -0700 Date: Mon, 18 Jul 2022 19:07:12 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 3/4] target: Properly set Sense Data Length of CHECK CONDITION To: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, "Martin K. Petersen" Cc: John Youn , Felipe Balbi , Greg KH , Thinh Nguyen , linux-usb@vger.kernel.org X-Proofpoint-ORIG-GUID: DPVXNtbCoUv-U4kfT-KLS-yaWAx3-mPS X-Proofpoint-GUID: DPVXNtbCoUv-U4kfT-KLS-yaWAx3-mPS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=854 phishscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190006 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org CHECK CONDITION returns sense data, and sense data is minimum 8 bytes long plus additional sense data length in the data buffer. Don't just set the allocated buffer length to the cmd->scsi_sense_length and check the sense data for that. See SPC4-r37 section 4.5.2.1. Signed-off-by: Thinh Nguyen --- Changes in v2: - Make sure it doesn't overflow and properly pass TRANSPORT_SENSE_BUFFER to scsi_set_sense_information() drivers/target/target_core_transport.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 8c386142ef90..db53b326048d 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -3459,12 +3459,19 @@ static void translate_sense_reason(struct se_cmd *cmd, sense_reason_t reason) cmd->se_cmd_flags |= SCF_EMULATED_TASK_SENSE; cmd->scsi_status = SAM_STAT_CHECK_CONDITION; - cmd->scsi_sense_length = TRANSPORT_SENSE_BUFFER; + scsi_build_sense_buffer(desc_format, buffer, key, asc, ascq); if (sd->add_sense_info) WARN_ON_ONCE(scsi_set_sense_information(buffer, - cmd->scsi_sense_length, + TRANSPORT_SENSE_BUFFER, cmd->sense_info) < 0); + /* + * CHECK CONDITION returns sense data, and sense data is minimum 8 + * bytes long plus additional Sense Data Length. + * See SPC4-r37 section 4.5.2.1. + */ + cmd->scsi_sense_length = min_t(u16, buffer[7] + 8, + TRANSPORT_SENSE_BUFFER); } int From patchwork Tue Jul 19 02:07:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 591825 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F628C43334 for ; Tue, 19 Jul 2022 02:07:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236857AbiGSCHf (ORCPT ); Mon, 18 Jul 2022 22:07:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236859AbiGSCH3 (ORCPT ); Mon, 18 Jul 2022 22:07:29 -0400 Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 384DF3DF18; Mon, 18 Jul 2022 19:07:26 -0700 (PDT) Received: from pps.filterd (m0098571.ppops.net [127.0.0.1]) by mx0a-00230701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26J1JOY9002282; Mon, 18 Jul 2022 19:07:20 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h=date : message-id : in-reply-to : references : from : subject : to : cc; s=pfptdkimsnps; bh=SO+Ozr9/sPtknW4Dm2IkfjhqY8KkDi0uGbNsxMi0Luw=; b=DHfN+lJthYr91oMkuIQEI99WM+x8Kjt9GNqpYmE1Z/X5nEcBmgVC6ex4Ecpga7/Ilzvf aqCbKO9S8UDQZCCwQq8iQnqDvllKoGocuSpkJyqqAc2J7njw9Wgkd0S2HJnuzPnXFYR9 oEPQzJnaRhGhSWCWX3Fj1CgQIBRujKu2vBPLwtIRl27sf/8AXkXX1Tw/ZJ1K5kyx9xxY OM6CMcPOlolUNZnWFrZvoAgiI3by3ssQ4s8qlFVmiSR5TqfPLY0XyVqPDIbtVful+BRj 2D/N6FoaY2TFEQeu4oKRxbGC3VQtuNi/fxdhHm+0ANUaKzicMUKvLLE8ir4OosEVQf1n Rw== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hbvbmwp4s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 19:07:20 -0700 Received: from mailhost.synopsys.com (sv1-mailhost1.synopsys.com [10.205.2.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 432F34008A; Tue, 19 Jul 2022 02:07:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658196440; bh=12PH3KrZuQ0fN8QB633gu08Ms0Ej1Uos3YJGTPWL0BI=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=fPToFenfChGBl6tQA33x51J0+UMO+wVl8tr0rRWXYkHVKzEKVxsp15fLC5g6QHL4u 9KPOfQqJQIGbohI7HfXEaV3zvvjK+zMEKSsBlTBOf+DkY0jy0ffS552DNo5aiWx10j dEjH9CoMvBsITw5NpdCZcy2Amcz6l/LzxE0I51Ql870SmT+p0E5YgK83SMzeYLvcpz /CqzRByaB25zvMxhcCxDBi7tVrbGXDdfdPS7xTuuoGuw0qcjp6YD6f2Yx9kVsrmua7 8SKMjdTMZ2ztLBuovoDgAXTUIw3bYsloE992We3Nayq1hwduFeyStfUOoXcZG8Ju6A RK+29TWqRbQEQ== Received: from te-lab16-v2 (nanobot.internal.synopsys.com [10.204.48.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id 23754A0062; Tue, 19 Jul 2022 02:07:19 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 19:07:19 -0700 Date: Mon, 18 Jul 2022 19:07:19 -0700 Message-Id: <71ea0c365383e038b7eb6a638faf45a7345fcb33.1658195984.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 4/4] target: Properly set Sense data length when copy sense To: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, "Martin K. Petersen" Cc: John Youn , Felipe Balbi , Greg KH , Thinh Nguyen , linux-usb@vger.kernel.org X-Proofpoint-GUID: 82IDjKJFH3kYKSM0h1cE1uCoz1GHQyAA X-Proofpoint-ORIG-GUID: 82IDjKJFH3kYKSM0h1cE1uCoz1GHQyAA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 clxscore=1015 priorityscore=1501 impostorscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190006 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The transport_get_sense_buffer() sets sense data length to be the allocated sense buffer length TRANSPORT_SENSE_BUFFER. However, the sense data length is depending on the sense data description. Check the sense data for cmd->scsi_sense_length. See SPC4-R37 section 4.5.2.1. Signed-off-by: Thinh Nguyen --- Changes in v2: - Only memcpy sense data length rather than the entire TRANSPORT_SENSE_BUFFER. drivers/target/target_core_transport.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index db53b326048d..95b7788e7cbc 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -771,8 +771,6 @@ static unsigned char *transport_get_sense_buffer(struct se_cmd *cmd) if (cmd->se_cmd_flags & SCF_SENT_CHECK_CONDITION) return NULL; - cmd->scsi_sense_length = TRANSPORT_SENSE_BUFFER; - pr_debug("HBA_[%u]_PLUG[%s]: Requesting sense for SAM STATUS: 0x%02x\n", dev->se_hba->hba_id, dev->transport->name, cmd->scsi_status); return cmd->sense_buffer; @@ -791,6 +789,11 @@ void transport_copy_sense_to_cmd(struct se_cmd *cmd, unsigned char *sense) } cmd->se_cmd_flags |= SCF_TRANSPORT_TASK_SENSE; + + /* Sense data length = min sense data + additional sense data length */ + cmd->scsi_sense_length = min_t(u16, cmd_sense_buf[7] + 8, + TRANSPORT_SENSE_BUFFER); + memcpy(cmd_sense_buf, sense, cmd->scsi_sense_length); spin_unlock_irqrestore(&cmd->t_state_lock, flags); }