From patchwork Fri Jun 17 03:04:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 582955 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 5A7DBC43334 for ; Fri, 17 Jun 2022 03:04:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379942AbiFQDE5 (ORCPT ); Thu, 16 Jun 2022 23:04:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379924AbiFQDEx (ORCPT ); Thu, 16 Jun 2022 23:04:53 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF5E06622E; Thu, 16 Jun 2022 20:04:52 -0700 (PDT) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25H2C20M022339; Fri, 17 Jun 2022 03:04:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=G0dieYK4eQgE1JdoJzYibqzEQ4kpbttc6gg00fVgK/o=; b=VPCM0OKCIsppaD9NrldCXKzfMfr3sdgFnRAhyRk2CuewEdKZhJPJwwUM2fVUqQDwCbdu JsEpMLG7F+PlyywU43T+hf2PMl4ZWJjM3kXDpeN6TZM01BlRD7kerqGkP3CkpT75NZWr 5bLl2RYJqB3ep37DhWcPoQVJc5PlONbSX4Vphs308mRJahd2wVVHkmfHClv4rSZmyB/P 3QjnBn0j9EebEiqDee340OiJNPq/MJdX/W89LkdUfGstU2qr5BQasLQdel92xho64ChR g4cjYIC1DwPv32KtZXQYbP4mYay1DR0LqkRGMS++n3EVm6C3ku+iUJsXZlnZw2ZWDLKM UA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gmhfcvn78-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Jun 2022 03:04:50 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 25H2tlK9019489; Fri, 17 Jun 2022 03:04:50 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2048.outbound.protection.outlook.com [104.47.66.48]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gpqwcq8hg-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Jun 2022 03:04:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=apJ7/L7f7k3mpRcM4H45z5VdQzd4vvJ41z7Bzaq200caaVFLH+bGnSkIv/eqZuHjcX6qGylThQRJdwONcEBANLkvJraGNkMgGFAXMryEhl3y/76D78Ren2dRvukspFMQVqtPxyNzZAimrzLQWLzH0FJcvnwINIfsAq1lKSrQ6dut8CFusaIAro5J8h97x3tskEJ1xKZQZitRBWR6yYFW856V+zSpeDVgNkQTttzqscCDklejBUSiobpbwQkYVBKfNQuHKmJpXOo02Y6Iez18qiiyOALCgEDjSkLQK50aIZ4z3Ro9rvwkKx3H6GbTGLnXUFSH3S7AnaljxUGe9eo2zA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=G0dieYK4eQgE1JdoJzYibqzEQ4kpbttc6gg00fVgK/o=; b=gkFrVsXlcyv5jAKKgYZjpE2ffxk+Tc2xzBhbGm0pqB0ewqbBsgXLKET1oJbd6CnmK183SQs070O3byJWUtWN/dKRDXINXWht+rG9ids1OBz58qNKgJ6ALsPGMd3FL+tPzLkRywdypbhgWN/MuMkIsdV5pE8fYjT5KAPm9ogFKSB6maTGtn9KKKlDOlZal4GCC5dbNsXAsz1vWn/azdyeRIdhS1VdnSnTm8XdIorOZ+wbbgBQG8kT/WUQHFF/b0cPrXwydCTJDiiiKeHhSi8TtVQaYCZ1kmVzvx2RJW4OIQkrJXKhMBakoaCceA1JxSw/WThCc3g0sAErpblGqjwjWA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=G0dieYK4eQgE1JdoJzYibqzEQ4kpbttc6gg00fVgK/o=; b=Zr+oC0SuJxFD1vPWvHP5chCw7RUrLj/rgmDhmPb/sv2Wrfg9u8ayT4LshcK+3sFy2eoCEuobOmlal5nZThtGgw1KUQIBKSvwl6QlPGup5/AJmM+gqnH1wP46z+ioAe/RPB7QHVsyS7MSH8pOwJd43wpnQD/Xl0KBLxmNzOAxBC0= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by MWHPR10MB1280.namprd10.prod.outlook.com (2603:10b6:301:8::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.17; Fri, 17 Jun 2022 03:04:48 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::f81d:b8ef:c5a4:9c9b]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::f81d:b8ef:c5a4:9c9b%3]) with mapi id 15.20.5332.016; Fri, 17 Jun 2022 03:04:48 +0000 From: Mike Christie To: martin.petersen@oracle.com, james.bottomley@hansenpartnership.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Mike Christie Subject: [PATCH 1/4] scsi: target: Fix WRITE_SAME NDOB size check Date: Thu, 16 Jun 2022 22:04:36 -0500 Message-Id: <20220617030440.116427-2-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220617030440.116427-1-michael.christie@oracle.com> References: <20220617030440.116427-1-michael.christie@oracle.com> X-ClientProxiedBy: DM5PR20CA0034.namprd20.prod.outlook.com (2603:10b6:3:13d::20) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c2a32736-bda5-47e0-85cc-08da500e235b X-MS-TrafficTypeDiagnostic: MWHPR10MB1280:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FLPKgeTrL7hovu+boDVbfN2t27qjTUprbS6+J2ub75AaxdIXeG6WWhkTsVWzbpGKche3GVsWmr65xNckzbA8KqCZa0YS3q3cB+sqS3wOU3628j4lqk7pvGm8/Fw0gloUr7aSL6fNzLQ2fO6myGx71dQi/LiBTNtoMuTsPi6800VeFWxOYquVWn4w8U+L5lGk0eby/z16Rp52XFPmQGmY5p/6K/irY5RDTACOGuf2Q9Oxv+eeOnCYN4NDT5bKvqc8ZIIUuNfAozQM7lvVTmdTDEEhvtKYye/biuPwxZ9Fi1k8jcCfYcD6zBNeDWI6B6tpUMte5fHq81yhW2XOzroqD7sdFwRROsUknJaQHNP9PbM30oG996GWKb07a1P9GDDtARO4TFlyAW2Tw4X6EcZUFEZP3iwAz1N+d2BczcALLm/pcR5Ic9jpbHSyDX7MW1OEE4Dd5eN3McK1EOXPbmaHSW+WX+hpbjOCPJ1h2V7JMoEGilZ35KkdJCgJIt1KWgC1qFxVWMe3EjatcTJ6lLpLId0lKsfmMpODlGNOYKXGbWpg4fjax8YGglseZf8/KMwz0BEizeGRaapDVOALZJ+PcZ84L4SsGg39I6W/ijPjD08ZT1F19QquIBJqFoUnZw1Y6p2TJpM+TEanRIdVSHKrgLptER1wwZaQ5ad9kTfdB9h2djN+Z1LnwEHORKJ2wWdNhZE9d+umaWWkWXlE3fMt+w== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR10MB1466.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(366004)(8936002)(6666004)(6506007)(6486002)(6512007)(508600001)(186003)(26005)(66946007)(52116002)(38100700002)(2906002)(38350700002)(1076003)(86362001)(66556008)(36756003)(107886003)(8676002)(2616005)(4326008)(316002)(83380400001)(66476007)(5660300002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: c2PMIVCvRYqMbLH5L/hF6OIyTWjAB5clfc1taPEf7Nu6d+GD9p6mpMa4PNue+0kZyUqngVHsThVuUbHBuEUGrGStlsGKCj+lNEk+8bXdPjRaxj6+njMb0fhUOi+nomAb+7oueqpBLk8LId1kafTLhUH+ooEpfb3wpSHsHQiUDPQ+uYQU9QJeeOXuKbUoPbM1AynjrNwhe+MMoN+RjhZOgQxZ4cPJRuVIgL34oN0SMGnhIEppEcsxHaDpSFYr4Cqowkz6uiYvq2pmbs2/9j2nvhov/cPHDKem3ofZgdhKueaI60VeSqcd217W5ack8k8r0ZX3cAcwXZfQpm6eka/IW9lyK5H9JkOZIoUzSzMLBCultgitX8fAtip0a00GVlQkMivPCJmsOzyHFcyDoWSKtJVMlIOoJ4zI9YoiThO4BGocETXDbCQNjKTKpIpTeZ88fDPmL59hM5PY8gXL+D5DCG3PMlfbid/rboTyowTyvcFRDO4LomQbDCCNPbUi33Zxw0CY0fpSry3UN1KlRusCh41cmCKNHi2I2t6UloBGuoOVEzywtYJf0me+k+x/zw4cmQNl4EE9K48UbTrUXV+/4E9sUpU9GH29KDnKdRSRphEwY3FaelTs3y35d3bjFIANBMDZgKT8SutVjS6w5nRpHnNzb1tokmo/fEtMwzTW5mFMrDA5dOHHhx22jjYRLvDjXJg7BAzzQVU+NzjdQ8T8u8P6UpPS3WdtrKeBuflQ44HndNMqxErAD4d5rgfUel/ctOyH0xqJWI8j7cpDQ9BUGjaIYhS1H4umXqLv8rCbD4GnECuIlLKNeTTp31z8mu/lTCJay9E+NtWh47IdcdrL1nsITdfUohJedipPdMx+HlrOYDDCK3/0fTsFyDFR5iGSZL1QdkMNPBwMq1EVCtXwTHk53wsTegyqozFy58PdrckaopTS6BfQVYrlkYQd/xC/19XapcxDg4LfU4DdyA5j+V3N2i5XaNe/lCv+OBpYz6G7RtZZxMEcHiDctSWFxbzw1OlYmqkK3idjYhyZTMt4RWsQcnDGcAq/MyvpbsoSOB9fbmT9bHds2uVVnxJlRrD/7rF1FI+GfbEZJHXhDb1GkXJO8yjSgevPuNXSH8lKwiL0vaFzQFoCVqDQeliEQobZX/k0CDePtIgx6lx0cr0+OWKIblQvo9cmCTy2DeSsqEAR/R48QAgUl9bfGfME59VFZdRYA6FIOyDJm8pkncWH4Yc23hG+2RbiQ/aB3EJu05M87MSkMBtB1AIS350ecmaMHmJvX4ugHACrG8rraeHmlk4faxLUyomZCM2r6uQ/pt/u/zyfzjNFxMWfTU+izK3YDuv3rZGGB4A8HAcv6bbuYOKqBvfLo7Nzra+1LfQGsKNT+P+hZIssSSeGzPWDjLAJ9ivKL+ASgQOu0eCMgvFmf/Lgq5Rydw7CEmFyiPBs6SozIlpVrzkaPAlW3TC3E3gDSuvtO1Ve69YKfRnMiPrezhWQycsQGxscMKeAYt7EdcxhuiYbh63K4Glhz0mQIrc4G9nHXtIknJBE8F9si/oz8UTypY+7BACYk05AgHOZNdGt67pydSHZ97+qt5aeBVUF+bs7toOcNI77KUxQ0fdFJetja74FxFlaCIbMfDWc3uTxApX1ujOFNCz5buZPnP/dGnJBOXjSzfHUHX2+ccaIvAqL4aQvK+6bM43/9UFD0splmnxWyIWtq2pQnUcXFI4jsSjslz8YovY7G7N/NVssMNjlxhBqku2YEv3sZGOn704= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c2a32736-bda5-47e0-85cc-08da500e235b X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2022 03:04:48.1186 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lHacwmHPEXW/jkEM7suqUhkOgx4jHjVXHEfHz1/tveJRKZcMKb0mUu91VSvdjwBswPCt75Uhelq4zG8UBCdkIYl7NKYCQxep5VmQ4md8l5Y= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1280 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.883 definitions=2022-06-17_02:2022-06-16, 2022-06-17 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206170012 X-Proofpoint-ORIG-GUID: J0ovvXEkYUy9rmy-X3lSlTTlPJB9W3Zk X-Proofpoint-GUID: J0ovvXEkYUy9rmy-X3lSlTTlPJB9W3Zk Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org If the WRITE_SAME NDOB bit is set then there is not going to be a buffer. LIO core will then complain: TARGET_CORE[iSCSI]: Expected Transfer Length: 0 does not match SCSI CDB Length: 512 for SAM Opcode: 0x93 This fixes the issue by detecting when the bit is set and adjusting the size. Signed-off-by: Mike Christie --- drivers/target/target_core_sbc.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c index ca1b2312d6e7..6d98b016a942 100644 --- a/drivers/target/target_core_sbc.c +++ b/drivers/target/target_core_sbc.c @@ -976,7 +976,11 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) return TCM_INVALID_CDB_FIELD; } - size = sbc_get_size(cmd, 1); + /* If NDOB is set there will not be a Data-Out buffer */ + if (cdb[1] & 0x01) + size = 0; + else + size = sbc_get_size(cmd, 1); cmd->t_task_lba = get_unaligned_be64(&cdb[12]); ret = sbc_setup_write_same(cmd, cdb[10], ops); @@ -1075,7 +1079,11 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) return TCM_INVALID_CDB_FIELD; } - size = sbc_get_size(cmd, 1); + /* If NDOB is set there will not be a Data-Out buffer */ + if (cdb[1] & 0x01) + size = 0; + else + size = sbc_get_size(cmd, 1); cmd->t_task_lba = get_unaligned_be64(&cdb[2]); ret = sbc_setup_write_same(cmd, cdb[1], ops); From patchwork Fri Jun 17 03:04:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 582718 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 E6492CCA47E for ; Fri, 17 Jun 2022 03:04:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379945AbiFQDE4 (ORCPT ); Thu, 16 Jun 2022 23:04:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379582AbiFQDEx (ORCPT ); Thu, 16 Jun 2022 23:04:53 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A5396622B; Thu, 16 Jun 2022 20:04:52 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25H0SUL0009843; Fri, 17 Jun 2022 03:04:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=fxx25PYFNYfWuO28+FXL8z1NVFkW5iNbO/3p0+OEXd0=; b=miycjlwlG05O/+1g4eq1Vgd+2p1XTcb0jir7zWTc/eG34X87BTccgl5tDFevKh1I+KO8 sIMEdFAyXO/AKlpXKVA49CyqgdbGu6H+aF5HVgjwP2eubE3nLuY/u35PeIP/LqEYD/Fk gVs+ZKhtMDRP2PxK8jjjVHiOhysl8BHe8/l/QltAUdgj3zSBR5ARxq8fJ5ood53QIQ2e 5CdNXQ5DNZe69FcpDG+GgDYKX4+D1VQUd7Q3FhjwlY8SgAyBppYEI3nGQLh+zVKOz7ct gypGxBJtVgyyIZMDx+JrRREki1GaZQ4avMHJj5YCZ5evtKKSsXcnnp84a0ep0SRbpTGh JA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gmkktmt5d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Jun 2022 03:04:51 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 25H2tlKA019489; Fri, 17 Jun 2022 03:04:50 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2048.outbound.protection.outlook.com [104.47.66.48]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gpqwcq8hg-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Jun 2022 03:04:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HuzKc283dIeCvsjQlK/64ixZsGfnL8ymre0nW+lFoDsYeuWvgMq/jTuxGxOBpKwcDJstx7f3i73HVKpCAyQfbf+94SAzyxA1U7gTbXswvF9I9YgJZqK6TVDYdsAcgKIOUk30DPcTdMpFQgfc7X/rFdMBYg56xTxWoaXW8+ebU9OyWC3QlcbgMCsTeuWq/viMGqb1l+ZuUk2lUzGhXxdJpnj/qhi7fuIl5OS5a7p9k1qYi9kmT8rLTcwNALo5ad7SqpJpRwoPHkSbOetTmB9Te2NgC6NQmiVJ4DgnJTxhj362zf8z6MMszEowOiBtSY/hjV9wVBTRTO65nzys1Aoc2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fxx25PYFNYfWuO28+FXL8z1NVFkW5iNbO/3p0+OEXd0=; b=iL9z7T+KthAiHnN6c16M5LNylVdfFguk5S9CvRKCDmMlugcxD9sfII9WTN7YVpbHKiChBMWwIKu4qavGRwEOQ/wFaKDjLZE/qi5p7+kbqntj9DEEI5vD5ah9snuG38ThpI8dVr9EXe8bGiwAEkZWRLflcg1GDCJsSxX8jdEDXzB4u0HZFD0Pp1Z/smpqUQ/hrp5ieOFiLESbq6BHVabzxkTCXmeylWi71g49TrYcW3UzJE4v4tG30siksRo39TZpOmx51DFfcUi1UWAFLWwZTHzLJ4A9QTdBbXQA+L1oUjqWhp1WHk0ntK9bAJuKxA+xqGv3buE+R9s1H+xdxhFgBw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fxx25PYFNYfWuO28+FXL8z1NVFkW5iNbO/3p0+OEXd0=; b=Yecr6NZce9ZovFhYWsT53MJoCbQ3EcI2jTUCzQ1bGqhLAoAMTOo5hY8XzjYBKRNLOUoZXCNced5wYjE52nuxYhmfvEUjTV3syHEtXtjxKgOVQPyRplU3vp3LZvLA3B8izu9CMH33KeuYs1R4VuKfKToK1iIjFuA6GOm6QPs2V4k= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by MWHPR10MB1280.namprd10.prod.outlook.com (2603:10b6:301:8::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.17; Fri, 17 Jun 2022 03:04:48 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::f81d:b8ef:c5a4:9c9b]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::f81d:b8ef:c5a4:9c9b%3]) with mapi id 15.20.5332.016; Fri, 17 Jun 2022 03:04:48 +0000 From: Mike Christie To: martin.petersen@oracle.com, james.bottomley@hansenpartnership.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Mike Christie Subject: [PATCH 2/4] scsi: target: Fix WRITE_SAME NDOB handling in file Date: Thu, 16 Jun 2022 22:04:37 -0500 Message-Id: <20220617030440.116427-3-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220617030440.116427-1-michael.christie@oracle.com> References: <20220617030440.116427-1-michael.christie@oracle.com> X-ClientProxiedBy: DM5PR20CA0034.namprd20.prod.outlook.com (2603:10b6:3:13d::20) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 520d5d92-fdb2-4285-cd54-08da500e23c6 X-MS-TrafficTypeDiagnostic: MWHPR10MB1280:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J31xQr7WYC3wP5K6ZAHpavvPPt4BDH6p6/Qi6Dqy8luYzqAf2gPfX5vRem5P1zU4ZFGbGhEe2qp98BDkQ1cjp7FyoevOBkmWQoluVCg1Tlz3Ucq/7nBBzElY6FpCNH29a1jWUTgXGg5JJINIt6G1QCtR6kBCJI3rZyH9SlN0E7Vyew3G/P8yyUTn15iDDIY6lGsbbTVBYRq1cKYqIMPwcwqsdCBt2DZ+KiExel03Ymm7Lora6LbTBbkPo6hjKE7sYEELgZi0ayiUQ2uXSwYznqqMBw/NkI9viOQD40RWYAMiksioazVAAk7TRYxo7ssb8lrftmqHUQuctuS3fHCHP7NfuB4O7E5smrfRbZtuVzE8hGI571s019Krl5gjtF9+Weq1doYtWi6bDmSjMGc5tRhljIMOyiZmmP7h1nOrGR2AEmSgKLEtYeCSvGOeLgbhzeMLDfRyOIDsl1uSjO4U7AkhR495C2OVY1Q5ihAhSlROdcHXzRJ8B5CPAr0vt8OD8GGc1VbYgSlXqwjQcnyKIKOf2D8+iE9ecocdN+hE5BOG3ffoMPv+7ZzCQPmG5FnqEVpKdvPuzfa2jVnSpoCIwSFzS8pygdhpbv9WIjfEnZoCxNp748Yg3gmmN9G2IcWzwkWKrC6b3tVbwTA8v54hThRhfSdu9J44H5NuYWGLtYxf08Q/duNd+oPx4NDlIzTbCP5J9gDj7Q91SKci6mseMw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR10MB1466.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(366004)(8936002)(6666004)(6506007)(6486002)(6512007)(508600001)(186003)(26005)(66946007)(52116002)(38100700002)(2906002)(38350700002)(1076003)(86362001)(66556008)(36756003)(107886003)(8676002)(2616005)(4326008)(316002)(83380400001)(66476007)(5660300002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YOKL/V7p72wAgFQdlg+wxeFfSLkUl/WQMC2dp8AhQZobrNiQ8/s56su3k91kMZGCGugTbmO3E309N6z4skRNJGXh89IFCJXNHNM/LAD2inIJulDnjHv+aUWCxlc6mWXw8er74ZBOBfqXA0Prb4f0r9geMmYB/CyG+CypLwWq41uKcCWOrgEg2fb6hkX+op8uwR+vkxx1+uhT+FZZesl95gotL8cs1XLlwPm2jtmLEE3aWSDqUojiTzgMv0DzBbSR7G4mAqV3GKAsDap0WJ5zcQnjwHYN04xLkmQq5tDuZN1r4ez3Mzqtg8+dqmCDUBjulMjYPCZJ36mg2T2f7SzGUnebmTqIZPb0o9aLTRNBigc6xcmfsghXTjg/5t7avhP2xhBKKrH3ylMiWJbyP3e9bjrsUVzLXqJx4dj6ve1pjT4sqSO6CPJi43dfqW/D3xIOC/5twoL3L8arnaickqLKTBPEYHnyce409/dCx5cXrDzcoBGfJ0dAXiwyLV+BIeDmA8HFC14b7cByJstH9u7PTWSO5qO4ZWqXgtBPbFTdTsxz8+tEgOl5ZLHuHYVHzByU9gQzLQA4Ad6JHLySgD298VpB+JV4NWx8iPwrg7d0qI7Hz5pppi1ZnAq9jEo/KBLSXxD2nCsvytkGSpzgJJ9X3gD5ZLvEUa/eWvCtphmZVCuExKgl1vGfu6Rq3yPI344zmJ3qAdzcjytAop7rV31l+vOz123Ogx42x5HZ6R5rOEL+e2vuGq004U9+fDhj80VD5iw4CFzu9rZa3kf0aQKAEfTaTNWTvExQnm3vmwdpoEfh3FSWTmvgE3aZP+hX7f6dO8BJTgXUsDqkTVxnus9w5d+9zC8WKjsSIX7fJkILq0Tgv7Dw0T9dEnMqw9pgR8/e9Vt5D+Qy5Q0h6DtQZSsjFbVmWYZykKUxW+XXbVl8q09CJr0+7XdvOAcS0t9eju/4UdRXbbvEsIL4zLbIMBcyaJisrQSC4uN78XODvgzpPMyK+GVJ2mZyHVTVRr2w2znqemjY/MKVmmiR2Sv3lA3BS3EgNXo02xORumNMZ+43ENgA1pg9kcvZMtJRYM11xAJfoVsUjiz4zaLkd4WPWG8huiIDzIxWmWIQS1xiCK8zoG3cCG0R8EDuDsZr8z8o/fqJFFeosIA5nsJBCsDnnUewFzo0mF0fV880IT1mYj19Ni5Qguc713heZXxxjFy/leDgOcyLHBEFJmGJiwTlaWwwmUN8EM7yE+o4YtkfKhX3uXEu9ItzAK2JB3bpAmKRgIXpm6RJ4E9dQJOhcWycdKH++9ArWhWjr5U0fO50quK0qRn40T56fzjQ7Rurr7vh4Av6NLdMHgPp0gDsBaNJHoYZtM6ddA9/G3AY0kE0z+fCMCK3W888Sw9nqoWFSoKpntoL1iS466aIs58m0RLJsh+QYQujSEg135K6B3bRUWRWDCPUIsp0v8IOSTSLQx1NzHwNHJzrSCgwqHfk/MwL7F3ZupJTbZ37eBEC2+2pJlGho/aUPA4UlYY+bsuJIk12X7w03mlXGcjI5wgIP5a2kjD4yND+rUEo4hr0GpIye7N4cz6ViUzys4uIXQe9QyHZvmrxtlq5Uv43o69iMiKkh2p89UjBsRGJK6MuafTGLeO1kXUbn8byejZ/qoBxPIe0YmE2yyp5VL7bt0ejz7KoJ44FmXKfdfEJ6EVgIAwQERco6+7DOH+02DtdnTRmnAd2aJJIPQC2PoipHgqgjecfIXL5/1XEHO5lEPzgskBSvNE1cgc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 520d5d92-fdb2-4285-cd54-08da500e23c6 X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2022 03:04:48.7904 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rNEC3u0o4SeAeiCZje3/VLGEsxR0pQq2ooU6CvDdJEXmTknxGJ1Odbno9Bzzl1p1Oou9KGEq6s8bsUTFdYxoxOU/fgKETcw/G4el9eMVJD4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1280 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.883 definitions=2022-06-17_02:2022-06-16, 2022-06-17 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206170012 X-Proofpoint-GUID: M3moiWgjY6B5osBu-hWbNcDyCWn-p1Hy X-Proofpoint-ORIG-GUID: M3moiWgjY6B5osBu-hWbNcDyCWn-p1Hy Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org If NDOB is set we don't have a buffer. We will then crash when trying to access the t_data_sg. This has us allocate a page to use for the data buffer that gets passed to vfs_iter_write. Signed-off-by: Mike Christie --- drivers/target/target_core_file.c | 32 +++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c index e68f1cc8ef98..2011836ab7f4 100644 --- a/drivers/target/target_core_file.c +++ b/drivers/target/target_core_file.c @@ -433,6 +433,9 @@ fd_execute_write_same(struct se_cmd *cmd) struct fd_dev *fd_dev = FD_DEV(se_dev); loff_t pos = cmd->t_task_lba * se_dev->dev_attrib.block_size; sector_t nolb = sbc_get_write_same_sectors(cmd); + bool ndob = cmd->t_task_cdb[1] & 0x01; + struct scatterlist *sg, ndob_sg; + struct page *pg = NULL; struct iov_iter iter; struct bio_vec *bvec; unsigned int len = 0, i; @@ -447,13 +450,13 @@ fd_execute_write_same(struct se_cmd *cmd) " backends not supported\n"); return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; } + sg = &cmd->t_data_sg[0]; if (cmd->t_data_nents > 1 || - cmd->t_data_sg[0].length != cmd->se_dev->dev_attrib.block_size) { + (sg && sg->length != cmd->se_dev->dev_attrib.block_size)) { pr_err("WRITE_SAME: Illegal SGL t_data_nents: %u length: %u" " block_size: %u\n", - cmd->t_data_nents, - cmd->t_data_sg[0].length, + cmd->t_data_nents, sg->length, cmd->se_dev->dev_attrib.block_size); return TCM_INVALID_CDB_FIELD; } @@ -462,10 +465,23 @@ fd_execute_write_same(struct se_cmd *cmd) if (!bvec) return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; + if (ndob) { + pg = alloc_page(GFP_KERNEL | __GFP_ZERO); + if (!pg) { + kfree(bvec); + return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; + } + + sg_init_table(&ndob_sg, 1); + sg_set_page(&ndob_sg, pg, cmd->se_dev->dev_attrib.block_size, + 0); + sg = &ndob_sg; + } + for (i = 0; i < nolb; i++) { - bvec[i].bv_page = sg_page(&cmd->t_data_sg[0]); - bvec[i].bv_len = cmd->t_data_sg[0].length; - bvec[i].bv_offset = cmd->t_data_sg[0].offset; + bvec[i].bv_page = sg_page(sg); + bvec[i].bv_len = sg->length; + bvec[i].bv_offset = sg->offset; len += se_dev->dev_attrib.block_size; } @@ -474,6 +490,10 @@ fd_execute_write_same(struct se_cmd *cmd) ret = vfs_iter_write(fd_dev->fd_file, &iter, &pos, 0); kfree(bvec); + + if (pg) + __free_page(pg); + if (ret < 0 || ret != len) { pr_err("vfs_iter_write() returned %zd for write same\n", ret); return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; From patchwork Fri Jun 17 03:04:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 582717 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 9BB5ACCA47E for ; Fri, 17 Jun 2022 03:04:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379948AbiFQDE6 (ORCPT ); Thu, 16 Jun 2022 23:04:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379932AbiFQDEx (ORCPT ); Thu, 16 Jun 2022 23:04:53 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2898D66239; Thu, 16 Jun 2022 20:04:53 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25H2FfUh029754; Fri, 17 Jun 2022 03:04:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=VgHA/P94hSpyCMkBhq/zeRDLloxOsL+c1yH1W1x5ceY=; b=WexBLk1/4As+4ncImsIzZGOyT621FaqLNr4WW8WzmCq8MgFjE1j5/wvlSrECdH7nP0mE I/bmBN6gOs8lWo6EzK7qDE9six5ascW4c1L8XEmniW69g+PzX1kYiQ8UetseXoEX/rx7 M7KC/CiIlTdaqdIx6EJ16iX5PKdymm1wxbKe/YSIu/5K/zh8UfKwvYicypdGQwsON0hl dS8tbdxyfuia5RHSXqovrfxZWGYr4XJ0+U9yRnNxpNImC/MnNxwRNfVU1xRJyalW/3X4 yRVoWTn7DKMbESdmwOnTjtZiySsg/qg2DDv6Gomfs8onuU3NRmV5pXxQT8I56nNUylKW HA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gmjx9mgxy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Jun 2022 03:04:52 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 25H2tlKB019489; Fri, 17 Jun 2022 03:04:50 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2048.outbound.protection.outlook.com [104.47.66.48]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3gpqwcq8hg-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Jun 2022 03:04:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BVz7uXYAlu+xjpfQLpd2OeGOMgO6SiBpSgHb+34r1IR0XCRLOneNkcJXU7Zw+Y/63fjbAAZuDInoWI1uOdLz3b1faNSPyD91gogLpkbobpvgYqCOwYcgCNUYWs2JcftUj6OX11fxdxRNmogIqyiU5+JXuSl+Bngm4BALCP5k9kvPXNqGwhB8mjCHwaoaTcP28G9Bex2DmtQabI+nusrNRe/qNcjUFGRcR5PecByb9SlfE8TU28mrdMw1uXNVi0YKV6C7dyoy3/bAm8Omj+LDB0gMhdQjFlDgnINNeH6XmcZ5kUGl+00dgu69HAlyGfdIfVuzLImB0K34eo1gXE23tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VgHA/P94hSpyCMkBhq/zeRDLloxOsL+c1yH1W1x5ceY=; b=YM4l2JsJQHldPvYaL25YJrT5r8OLfEaWN3KeIFGEE+YlYUQIyn1gB81tDpMB8VZ55uXt2GQtFNE9s9VCZ8eJHjI/8HKyca4GLJhhi6DJRFGBk4biXbgxDCtOPpGpeUBOrea+1pNSRlM4fFlayYAU9/2unDBgTTf2Ls79ReNlK37CXZwo7We6D/Rx5oyhBlTkAyMRB4YLVSmymDYL1iJeq+oEayXGOfoGYMdQ95aOczl3+KWUnZk0GAN5OTKSdyDsUOOZgYKizPS70eGHG/+uC7g6WYhAj/3dG6zItvI9TI2bNQmlKTjzB1AFAHio0cj4msoKdweg/h74RxAXBL53Jw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VgHA/P94hSpyCMkBhq/zeRDLloxOsL+c1yH1W1x5ceY=; b=klMXkmjyrehaEvaGfm4xL5JT5f2W5uew6gyWpX8XYz8zS5F2symVIejRqyTRaPikMSUc8udjLm+aX3PsvJynzSO/o5/N2BGL70b0Y2tlhoGE6cHuz5CC4gf40x6iOIMxrk9z61oOf6dda0+F1CS6ohgKMLSES6lfayivFnn0VCs= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by MWHPR10MB1280.namprd10.prod.outlook.com (2603:10b6:301:8::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.17; Fri, 17 Jun 2022 03:04:49 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::f81d:b8ef:c5a4:9c9b]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::f81d:b8ef:c5a4:9c9b%3]) with mapi id 15.20.5332.016; Fri, 17 Jun 2022 03:04:49 +0000 From: Mike Christie To: martin.petersen@oracle.com, james.bottomley@hansenpartnership.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Mike Christie Subject: [PATCH 3/4] scsi: target: Fix WRITE_SAME NDOB handling in iblock Date: Thu, 16 Jun 2022 22:04:38 -0500 Message-Id: <20220617030440.116427-4-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220617030440.116427-1-michael.christie@oracle.com> References: <20220617030440.116427-1-michael.christie@oracle.com> X-ClientProxiedBy: DM5PR20CA0034.namprd20.prod.outlook.com (2603:10b6:3:13d::20) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 55d6bb49-a763-4e27-c723-08da500e2423 X-MS-TrafficTypeDiagnostic: MWHPR10MB1280:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4FV8bkN3KgC3KFpl6D4BGn7b5o9oELLEbTfloTmrH4fddmVS0CENmvSSdyTMgAhuVMsBcjddGjYZ1hOe82/zxMjPyzGD9S13KIUWWIre1xrIBIYowMmeHlL/Wf6S7/hbA6YBeV4sqh9ELAudytk36ucw6Vgh1Fopf5jMuZX3F3wMj9ccSiqvWDFy2bM58SNTBXoe3AHFsmH6d9a8ghuDALXvTkL03u0RkE3KAWITPiU+MBoGJnDAn2xbvR5hnGfBTjWdhH76t4dL8tsF1m8UiV43k82/UdKPbEAKYCiT9R2o8x9yVcvZGUG3YPOoUUoS+uQLouJo5io+WL1jxIQehEgjqFED+nB7C5M7wK+nPRSpREFFpZpwwyp/PZgCYiQ2f62TDqFdEromV7wqQzzKlfs53VILkFGLH/kY0R0INcvSQBtQgvF59xmlSFe9x1nsJgDHaFnOTGLD36jH+h3WGWGj2Ker44Huz2SJu8SQxtLp5XMQctpFXhoDRzfPZ9idEE5Fbr4HhQPStZS40+scZURy8IdqSuZTYA7d0OyV1jVeuNR32jdQzeSr42fdrXGsipRaaY8dhEHHcjsDrCBNaB6TlwalaKcGeq9ztde0AUekavyvdD1QgwFixHPsXUenmFw5AZmWY4TqtNucIO6qLN8bS/c9PQFFn6Syiqcfu+46jvNM5QFnACSUULfgLcTWNHz/tZDS0lm0phWR6Ridig== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR10MB1466.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(366004)(8936002)(6666004)(6506007)(6486002)(6512007)(508600001)(186003)(26005)(66946007)(52116002)(38100700002)(2906002)(38350700002)(1076003)(86362001)(66556008)(36756003)(107886003)(8676002)(2616005)(4326008)(316002)(83380400001)(66476007)(5660300002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bC1HBWDO2h7/5hfQsGcSgsl7Y5F+wtueQX625rSPg+9p57gcxBwa/CsXmrH+i7Z1fi8rZAyTibhdZB0Xn1Bs6x920pGL6rDITvcKX7K6Y3UvPRUyyl+jRge2ymufb+y03YYL3y7pJ1a82xdt9P630tMhWWd3duA8tBTiXWntC8Js/KV/I799r6x+be2LQ+3Uv5PsKPOMrGQe6vRW+MlysvLp9KOclh2de2xssCb4S0cmDNbGLIEuzQsrRW/B82DfO4x69el/F+RB/ggjXNvd3U+T94Ssb5WCKrT50l23Z7QyfQYWOileXs4M2J37rjBK9npS/z2V8iJGMnufxiOKKIWGtKDMZz+anaD4MApxLjWEYSBsEX5rWgK8UWbuj6UAW1dtIGffr05EDD6/3PaxvoH4mxMKcP/U7s+fCESjKoYVn4S6hQ4HAhEvslVIdq7cnKamgK+I2sqC/YfBBGD1Q2+//Eqk7dkvVD7ixu6DS4M9tZWBP1UufmmnM0hEPMw2BZG86cdmNxOyXrpncQy0deqqVrJ+8tfhNzgnQHvtn9uI1ZCA/n0P43sg6WqvHDenahcqyaURIjbyTF9mJZMinjrMdFFj0lvr9fWESs5isQsziJO5yFLeYOeC3IioQxTSPd5CbxdDje2gTDS7q7KgxYkonW373viQC2EaiEWiE8hO1r5wvVdG9xjDu3OCqimNi7vLHFG0enT9K5J/ifC+T0bTi0+2v/QQfrSuhYllOmJzgVfq7RCkn33uUhCtb6Jd13ECmgImfY9ZLMaan+Kmq8T+yJRrzsZgBa5QxhUGu8JiXMk7OPwf4FjZrHSqLaRspB91u/5FG90kfv83oxAT8aXE+GABo5PF9jOlvm5KA0cEOaINJi7cUHtd+z3hP1iBV4tZZc/FAWGOMxC2AOMgeEyLGuSTZUP5U2x16b76hPljWduYXbPITMePa4osHKoSDE8tCwV49CszKdTnZSyvBIXaOJ0tUMexE+EqFlSZZjp0/ZdCcz+GjM7b+8RkHK+LrdISGPX/eqpnKeXTvez6zLw30ryUksZeYOKK5ZzzGw+CSchix+g0FfPQwUzsJUIx2UVbmFwrH2vvkQgR/yKAfrVSiM7KPKcGy/1lOy5r0w10XrMAltvdi4XPQVis3MRc38ukic0cMpou4AA9+WM1e21ZmTbAiBGqcsearFB5CalT5yA8nrBC/pX0aVoarYvVzZtpB3UYJRhu4JC5+QLuGu0DIh6JamGKbQ1vKY6WgD2peQeCVuRVfKhEI+cum3Z9jb717epdKuxRCer2sorV1CchWuzilDWyfIRBXMG6T+N7ye+OS5gQ3boDxPn7WnYJtn9VPjCS6qO7LQjQroTd8yXf3Douue/ID4+bu2D8XfeqVG8Ng8YiQWV+qDmL6YDfdaFCKo3/M/zGfkZQ4LaafJekAw5s3UFp8ybJj87UrgRoMy8Jaz9QJOyuYeG5RiZFAaTWcBqwRkVj/N1Cv9lXaqZtZOcikv5/7SKEs4kv75zpWRzRGCoSxxiS6zseei+K8JxzCXojAKZIHyy0D8lgtvJ4OgIsriizNiCqsP84UR1G947vZQsctxcpJ87dY/2P2px28AmuJxSfiouVo3r8FA6wff8SGDA87xSFrzN4CaGyjWbgxEi3LSa1bJbAk3dWAsLRSqS3JH0mUH+QoEnI3MgFqo7zwEdtu/LZehMoK/rsGWWyLLQd88TI96KdbIw6l3XtvVV4lVvpmGMQVVKbCaOAFMIvBMxvoZ+8miidsu0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 55d6bb49-a763-4e27-c723-08da500e2423 X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2022 03:04:49.3997 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6mub2vr2B0W9o3/+KJtPgbvLoIHIHiIT1xKtf4n4brF0n9K6uFmvfEJlT1KQn5+T1FhOaxnGFet78CGaPhtQm+9tU5a92I3eZo30ahMkTwA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1280 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.883 definitions=2022-06-17_02:2022-06-16, 2022-06-17 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206170012 X-Proofpoint-ORIG-GUID: pmmAR1WZnNj052feGvRpsO6uF2UodMVj X-Proofpoint-GUID: pmmAR1WZnNj052feGvRpsO6uF2UodMVj Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org If NDOB is set we don't have a buffer and we will crash when we access the t_data_sg. This has us allocate a page to use for the data buffer that gets passed to the block layer. For the iblock_execute_zero_out case we just add a check for if NDOB was set. Signed-off-by: Mike Christie --- drivers/target/target_core_iblock.c | 36 ++++++++++++++++++++++++----- drivers/target/target_core_iblock.h | 1 + 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c index 378c80313a0f..767ed2e9474b 100644 --- a/drivers/target/target_core_iblock.c +++ b/drivers/target/target_core_iblock.c @@ -320,6 +320,9 @@ static void iblock_complete_cmd(struct se_cmd *cmd) status = SAM_STAT_GOOD; target_complete_cmd(cmd, status); + + if (ibr->pg) + __free_page(ibr->pg); kfree(ibr); } @@ -444,13 +447,17 @@ iblock_execute_unmap(struct se_cmd *cmd, sector_t lba, sector_t nolb) } static sense_reason_t -iblock_execute_zero_out(struct block_device *bdev, struct se_cmd *cmd) +iblock_execute_zero_out(struct block_device *bdev, struct se_cmd *cmd, + bool ndob) { struct se_device *dev = cmd->se_dev; struct scatterlist *sg = &cmd->t_data_sg[0]; unsigned char *buf, *not_zero; int ret; + if (ndob) + goto issue_zero; + buf = kmap(sg_page(sg)) + sg->offset; if (!buf) return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; @@ -464,6 +471,7 @@ iblock_execute_zero_out(struct block_device *bdev, struct se_cmd *cmd) if (not_zero) return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; +issue_zero: ret = blkdev_issue_zeroout(bdev, target_to_linux_sector(dev, cmd->t_task_lba), target_to_linux_sector(dev, @@ -481,13 +489,15 @@ iblock_execute_write_same(struct se_cmd *cmd) { struct block_device *bdev = IBLOCK_DEV(cmd->se_dev)->ibd_bd; struct iblock_req *ibr; - struct scatterlist *sg; + struct scatterlist *sg, ndob_sg; + struct page *pg = NULL; struct bio *bio; struct bio_list list; struct se_device *dev = cmd->se_dev; sector_t block_lba = target_to_linux_sector(dev, cmd->t_task_lba); sector_t sectors = target_to_linux_sector(dev, sbc_get_write_same_sectors(cmd)); + bool ndob = cmd->t_task_cdb[1] & 0x01; if (cmd->prot_op) { pr_err("WRITE_SAME: Protection information with IBLOCK" @@ -497,7 +507,7 @@ iblock_execute_write_same(struct se_cmd *cmd) sg = &cmd->t_data_sg[0]; if (cmd->t_data_nents > 1 || - sg->length != cmd->se_dev->dev_attrib.block_size) { + (sg && sg->length != cmd->se_dev->dev_attrib.block_size)) { pr_err("WRITE_SAME: Illegal SGL t_data_nents: %u length: %u" " block_size: %u\n", cmd->t_data_nents, sg->length, cmd->se_dev->dev_attrib.block_size); @@ -505,14 +515,26 @@ iblock_execute_write_same(struct se_cmd *cmd) } if (bdev_write_zeroes_sectors(bdev)) { - if (!iblock_execute_zero_out(bdev, cmd)) + if (!iblock_execute_zero_out(bdev, cmd, ndob)) return 0; } + if (ndob) { + pg = alloc_page(GFP_KERNEL | __GFP_ZERO); + if (!pg) + return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; + + sg_init_table(&ndob_sg, 1); + sg_set_page(&ndob_sg, pg, cmd->se_dev->dev_attrib.block_size, + 0); + sg = &ndob_sg; + } + ibr = kzalloc(sizeof(struct iblock_req), GFP_KERNEL); if (!ibr) - goto fail; + goto fail_free_pg; cmd->priv = ibr; + ibr->pg = pg; bio = iblock_get_bio(cmd, block_lba, 1, REQ_OP_WRITE); if (!bio) @@ -548,7 +570,9 @@ iblock_execute_write_same(struct se_cmd *cmd) bio_put(bio); fail_free_ibr: kfree(ibr); -fail: +fail_free_pg: + if (pg) + __free_page(pg); return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; } diff --git a/drivers/target/target_core_iblock.h b/drivers/target/target_core_iblock.h index 8c55375d2f75..0f3cf72b544b 100644 --- a/drivers/target/target_core_iblock.h +++ b/drivers/target/target_core_iblock.h @@ -14,6 +14,7 @@ struct iblock_req { refcount_t pending; atomic_t ib_bio_err_cnt; + struct page *pg; } ____cacheline_aligned; #define IBDF_HAS_UDEV_PATH 0x01 From patchwork Fri Jun 17 03:04:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 582954 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 D7C8CC43334 for ; Fri, 17 Jun 2022 03:05:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379953AbiFQDFA (ORCPT ); Thu, 16 Jun 2022 23:05:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379936AbiFQDEy (ORCPT ); Thu, 16 Jun 2022 23:04:54 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B1EE6623A; Thu, 16 Jun 2022 20:04:53 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25H02WDO009842; Fri, 17 Jun 2022 03:04:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=xIu5h/HmVTkWDVmbEAPyG75RBdj+A8sdJYJ42jy/P7Q=; b=JtHTcAiaOGQz7AkjSiJ5TuIAQe/ztEW+a8qgRBqm6cYrCMEcN3bfNr61OD7fchL1BH4r 2uMo5VuZfaZYXo0t2EW80mdpflvZnEdjOQ2ZStqms1dojMDAL/NttxN6KRQ6llhJhD0E r3JyuI7ERQsonjXmEpKsNSH9ozdvdd8vPj6xjfjZ5Uek7U3ZIW4bZI7Dr9daFzKLvRbu R5EzRzwDGkgSzKM4nguwWToIWZ2vChmKDKfllBErKO6hoEZtnwO2qIXZdu8nx+rqUqOt bgko+Kf9qsHD3sj7lqQOk6FqCmBgQrKSq6Lk7S0oG4QefJtcDUVND57bzRAmdBqiRUoM cg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3gmkktmt5e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Jun 2022 03:04:52 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 25H2u1Xf016838; Fri, 17 Jun 2022 03:04:52 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2043.outbound.protection.outlook.com [104.47.66.43]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3gpr7qrnv2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Jun 2022 03:04:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xclupv3WQrHEjZWn7vybsUJbSh1/VJpM043S5HufyUntma7DpvJwlI3JfwZbWj0eQ+rnbqQ0osLVPiCGEuIvlAmCBT63R92CoMXnxjV92+ZFAszXfmtGzQaSXufIIO57V20Z/xNM9f6cY9WMY6gADjNUxPGkm4q4pyBukSpm71xE/He3F8QpCVpKk9+5ilRoVR7ChcMT98AjZQP7XIpyJpFUbj3k3796Lg28K0zi2xX+LoNZeWv7nXQkQD8uk4qdCkK88+jx2oU2xeildFjkjk1mr1XT/+qywYiC3aI9uS1TC7ab3ublQCvGU2fOkiWMxByYfWOmdACdTq/iP9jO8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xIu5h/HmVTkWDVmbEAPyG75RBdj+A8sdJYJ42jy/P7Q=; b=ZLYvBkgOjKATuSkOWPY79qVzirFLMYxC0BoeLqzJ5U9Vc4kLUrE/Ppi5ZpZe6OjAuZN5te83F/LwdQ8GP4X9wzVBdcuj4MeHg/LZnzVEnTRZmUJM3oKcBXbVnxrAt/Gw8XKbC1TBjHyvGZOp8p0IE6csQdISGtFfZYSNJEVAawVTpxwDnSgCxi19mOz3PhRZb8xKT0LH49SXxfxgAd+d35miwe0Qz5D+ubngDAF+QV5KyTfTVxM12DvANh9TGF4i/cFCwrZUqzKIA76a3bB8LOEXAxJEPxc58oZ+NNDmdHNEypwtSonOJZODTfabrvRk6Jo6AdFLDOIOaHjc18tGcQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xIu5h/HmVTkWDVmbEAPyG75RBdj+A8sdJYJ42jy/P7Q=; b=gx3LRKqNkXCX6g+YAC9ppMkGdOw0Y3FG2fhg0UbS3q3Mztx3JUx5twT10Np4ybeqFHwIXJjxGo5UaJa4id/VB4NzrSRk5jstuCUrc8qkYXNNkrY6VJ/AU2N8VMyfuSXG2ehqjJGKywbFH/f5IjxukUKZ88cvmSREUsT2ZTs4XlY= Received: from DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) by MWHPR10MB1280.namprd10.prod.outlook.com (2603:10b6:301:8::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.17; Fri, 17 Jun 2022 03:04:50 +0000 Received: from DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::f81d:b8ef:c5a4:9c9b]) by DM5PR10MB1466.namprd10.prod.outlook.com ([fe80::f81d:b8ef:c5a4:9c9b%3]) with mapi id 15.20.5332.016; Fri, 17 Jun 2022 03:04:50 +0000 From: Mike Christie To: martin.petersen@oracle.com, james.bottomley@hansenpartnership.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Cc: Mike Christie Subject: [PATCH 4/4] scsi: target: Detect unmap support post configuration Date: Thu, 16 Jun 2022 22:04:39 -0500 Message-Id: <20220617030440.116427-5-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220617030440.116427-1-michael.christie@oracle.com> References: <20220617030440.116427-1-michael.christie@oracle.com> X-ClientProxiedBy: DM5PR20CA0034.namprd20.prod.outlook.com (2603:10b6:3:13d::20) To DM5PR10MB1466.namprd10.prod.outlook.com (2603:10b6:3:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 11596f7e-6448-4aa1-2334-08da500e2483 X-MS-TrafficTypeDiagnostic: MWHPR10MB1280:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: g6+7mU9udZR0mbVT9/b6rgkUd6T3AAgU5Q/HdbGqbZPPxLPb++zW0UtLtSr1/7ip+WbQZNXss/6faVhxhWWfrcGNbkH8O3h+Z27Ym+36+qFvlvk+KqvsftYJ9krrDqMKde2aOsnXSDqZEiX/zgycsBXniyWGhKMWltp9qoxSqfpTNMCOh2uFMvjv6zDG3S6JNybD3nLkZ030cHruBbuJWme89NXQcaBkcNIvQV50pDrigJX+9JqmrK4DGjvFcSXZN0UdeVMjAT1QSvFv7/SBNZ4sWgxdn+PiwcBckvGr250LTKp6N8FSYSUuI5PNj4UCSBdm4jI9xJ9fg3u54FO9fXu9y3w9/I42N9MfLrIRqRwsOJmBmSXWe9+YpvfgraTbJFwcNo5ouLLf8a81LjyuNOnZTPM4zFUwMU1kKLuCBrwQnSM54cc3G1Vw6SHr/+WS7dwzvZ7P+f9j+rTfSZQB9UmD+xxlBErFWQ6M9wvhp7jMVnrmK7WfxAhyT1qGHJDqOEBZGx+WPh+lRrjfsbaBTcAW5UEZl7eyaKEDJyUIjS4mGDuF97wDD7kdo9/YHuq4GO41uRrAlSYb1hlm1KJek5o4BZ8r/t01/eU9/TZfP4Du+gOwUeYZ6w20t5kgu/KLBQC8C6+m1CL37U9hNd16OpfZkZuU8rX0abhbhkN9ppX7qOGfdmP3WDU5881jdFQLJVJE+S8NWEIvAxPxoxpTbA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR10MB1466.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(366004)(8936002)(6666004)(6506007)(6486002)(6512007)(508600001)(186003)(26005)(66946007)(52116002)(38100700002)(2906002)(38350700002)(1076003)(86362001)(66556008)(36756003)(107886003)(8676002)(2616005)(4326008)(316002)(83380400001)(66476007)(5660300002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 50Uv3WMgmdAdErZb5avdhaC7VQ79U/3TAB2pto6pKIeNZpeiIoulyEveBTPL+sCqjv2lCDOzO4HzWsAw4WDEK29Uf3IWjaFyh+cjiXQkuEMt497mxoAcIYZrsQUuVMRo0H2OeSPepwHmSuT9NmkxYAemlKdD2C+rXc/PBku3HwL1xp54fFsE92oF1U9lLQkD95T0PPHuppFztU1f/q4Ogig9bKxZzHAnJ+8HBMt0whLlqxfwlw3Ckj/l/uGPSgRb1znQpLGF/6/ojjV+YctHYcaY1YQMr2F10jIPVqJEm2PhKzvPha9K+uv55XEocrtcPToiD7jYn8yNJHqNvg5fQHRFdw3dnYcNZTb7krsIDuVJL/I53vMY4DHWUgZ0PbgJUYpNQuBpfvbfFHG6JTfFN7w12NtZeDQENH8dIjIUa/Mmu6/gNAG/nzf7mnqXB1tw+Mxln3zG+NV2X18rXy+xKTQk7JpInQUeEgX7Mh6MB/GcqzlU8mRrYYajiFgBVL6TUqGhXBoGC5j/Mffu12140bEXMU4qVpjOV2N7SpmmHYDr2Tl1hh4mLmyeKXLii+ABBqDtqmOhGoIVYQSciehdDVlZuBUExZJsH+ZCgj646ZaiwpPZuTPlof6LuzAa/5hpuc44t0eUw4YL/O+IiDO4e6wNuZBRofPNpU/8KP6ZIDmPUDiNiFwXXtP16SJ5PNwDzw9oP93KHQNJGhNfhmY4sDxGhlf7KB0Wjk/fQqWSGDt6T+/ccgxUX9XungSV9cxK1LvOEBmlObvdZ23Tt2Rbtd5ipmOv9xcAK+xbMih0G7X11nAbidIJplZgdxO9yhtZmakehWsolSimvMgGTKvh1koeAAzt0bgXE5RDo685HMKbFQ+xssMNPKCmNFhkoM66zf3/FlhPZzrgckXC9pODXSvBWL7n1GM+hXfZL/DDVbl/3k4imJgmmsBGLmWZXVbj2pZA8XTkmg3qyMfM90WmuPWlR8efiIp34BAv3kG7qz2g6bZxUfS6yZm12z7oVkbx232bDJKkpTmxtBqkyfJ0wHpUfnVvkzO3SZ8rFhgi76mO/Y60XLhGqPjSx0SmrvLEqHZlFalUkyYO4iGagoaQmojTGtQDaJ10+0rVYoTVajabgdtApaRCU2Bf2fH86e8W8EwJpuQ86sTEzzBKWRoYQ06vGEzP+ZTQfLrGan2iPHkorDpBNSMwaaftaoARKRR4NTX+ixeKY6c1sIllNYbjNrwWu3PHypWyv5PYX3V3wJkMKcqz2Wfhf7lsTDmPnVjCfjfBD+uJcAuTE3igSPUVgeOCODiONoY+4G5O9q2q+JrWcmR+zQgd5ZScO0Nrur438Mtzz+CNlG9tuBpzvxad47V6Gmp0ywKURfxHoUc3w4xMSFOrOxdymhezsItbBbcoYAVcmplE7rABRSALgrolDr9SA1c3mgZdOXUQCkIHsyYRo/n47vQpXb2AYL9fHp2DmNq54Om0cR6QviFaTxqnQFV5Zi4HqV0SSIz19nS3zJ67cgIR7CUdGGUoP3qolOkPYNBelPZVD1UORbelNXIiSghwko8trw5rw2K+Q5SLvEDmWktTdPkXgyeHip9Pa0/3RfNWDnbaYBxFHTIe+YGxEt51jbNXRcQCVEKUnlQyAZpR7E40wKpdooysnxxY6mt9tnn4kx2DBtLzqaZYXgloNsxL1JrmEXSfNa+MdyT97RLTDMCDbQYnc8ZMwmk95bKFAYqbJgL/PAfppkcgJKHVdjv2Z31epfrNM3etzUp57Vo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 11596f7e-6448-4aa1-2334-08da500e2483 X-MS-Exchange-CrossTenant-AuthSource: DM5PR10MB1466.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2022 03:04:50.0403 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: H6PnYW3esgbAg4YDbkk7ec16PSXF7KFLoC2c7bz7rI4OBK8yDLX64RyxF4YFFEF5tfCaPPkanAj8MUYXuKRlKQ1IzlpsinpYs3XMYL4C7xk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1280 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.883 definitions=2022-06-17_02:2022-06-16, 2022-06-17 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 mlxscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206170012 X-Proofpoint-GUID: 7-lSe4UmzGAWKiEu_Trd6iK3W4oJ3XXY X-Proofpoint-ORIG-GUID: 7-lSe4UmzGAWKiEu_Trd6iK3W4oJ3XXY Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org On our backend we can do something similar to LIO where we can enable and disable unmap support on the fly. In the scsi/block layer we can detect this by just doing a rescan. However, LIO cannot detect this change because we only check during the initial configuration. This patch allows unmap detection to also happen when the user tries to turn it on. Signed-off-by: Mike Christie --- drivers/target/target_core_configfs.c | 27 +++++++++++++++++++-------- drivers/target/target_core_file.c | 15 ++++++++++++++- drivers/target/target_core_iblock.c | 11 ++++++++++- include/target/target_core_backend.h | 1 + 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c index bbcbbfa72b07..416514c5c7ac 100644 --- a/drivers/target/target_core_configfs.c +++ b/drivers/target/target_core_configfs.c @@ -732,6 +732,7 @@ static ssize_t emulate_tpu_store(struct config_item *item, const char *page, size_t count) { struct se_dev_attrib *da = to_attrib(item); + struct se_device *dev = da->da_dev; bool flag; int ret; @@ -744,8 +745,11 @@ static ssize_t emulate_tpu_store(struct config_item *item, * Discard supported is detected iblock_create_virtdevice(). */ if (flag && !da->max_unmap_block_desc_count) { - pr_err("Generic Block Discard not supported\n"); - return -ENOSYS; + if (!dev->transport->configure_unmap || + !dev->transport->configure_unmap(dev)) { + pr_err("Generic Block Discard not supported\n"); + return -ENOSYS; + } } da->emulate_tpu = flag; @@ -758,6 +762,7 @@ static ssize_t emulate_tpws_store(struct config_item *item, const char *page, size_t count) { struct se_dev_attrib *da = to_attrib(item); + struct se_device *dev = da->da_dev; bool flag; int ret; @@ -770,8 +775,11 @@ static ssize_t emulate_tpws_store(struct config_item *item, * Discard supported is detected iblock_create_virtdevice(). */ if (flag && !da->max_unmap_block_desc_count) { - pr_err("Generic Block Discard not supported\n"); - return -ENOSYS; + if (!dev->transport->configure_unmap || + !dev->transport->configure_unmap(dev)) { + pr_err("Generic Block Discard not supported\n"); + return -ENOSYS; + } } da->emulate_tpws = flag; @@ -964,6 +972,7 @@ static ssize_t unmap_zeroes_data_store(struct config_item *item, const char *page, size_t count) { struct se_dev_attrib *da = to_attrib(item); + struct se_device *dev = da->da_dev; bool flag; int ret; @@ -982,10 +991,12 @@ static ssize_t unmap_zeroes_data_store(struct config_item *item, * Discard supported is detected iblock_configure_device(). */ if (flag && !da->max_unmap_block_desc_count) { - pr_err("dev[%p]: Thin Provisioning LBPRZ will not be set" - " because max_unmap_block_desc_count is zero\n", - da->da_dev); - return -ENOSYS; + if (!dev->transport->configure_unmap || + !dev->transport->configure_unmap(dev)) { + pr_err("dev[%p]: Thin Provisioning LBPRZ will not be set because max_unmap_block_desc_count is zero\n", + da->da_dev); + return -ENOSYS; + } } da->unmap_zeroes_data = flag; pr_debug("dev[%p]: SE Device Thin Provisioning LBPRZ bit: %d\n", diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c index 2011836ab7f4..a7c6df01d554 100644 --- a/drivers/target/target_core_file.c +++ b/drivers/target/target_core_file.c @@ -86,6 +86,18 @@ static struct se_device *fd_alloc_device(struct se_hba *hba, const char *name) return &fd_dev->dev; } +static bool fd_configure_unmap(struct se_device *dev) +{ + struct file *file = FD_DEV(dev)->fd_file; + struct inode *inode = file->f_mapping->host; + + if (!S_ISBLK(inode->i_mode)) + return true; + + return target_configure_unmap_from_queue(&dev->dev_attrib, + I_BDEV(inode)); +} + static int fd_configure_device(struct se_device *dev) { struct fd_dev *fd_dev = FD_DEV(dev); @@ -150,7 +162,7 @@ static int fd_configure_device(struct se_device *dev) dev_size, div_u64(dev_size, fd_dev->fd_block_size), fd_dev->fd_block_size); - if (target_configure_unmap_from_queue(&dev->dev_attrib, bdev)) + if (fd_configure_unmap(dev)) pr_debug("IFILE: BLOCK Discard support available," " disabled by default\n"); /* @@ -944,6 +956,7 @@ static const struct target_backend_ops fileio_ops = { .configure_device = fd_configure_device, .destroy_device = fd_destroy_device, .free_device = fd_free_device, + .configure_unmap = fd_configure_unmap, .parse_cdb = fd_parse_cdb, .set_configfs_dev_params = fd_set_configfs_dev_params, .show_configfs_dev_params = fd_show_configfs_dev_params, diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c index 767ed2e9474b..c435b6dd3ae2 100644 --- a/drivers/target/target_core_iblock.c +++ b/drivers/target/target_core_iblock.c @@ -76,6 +76,14 @@ static struct se_device *iblock_alloc_device(struct se_hba *hba, const char *nam return NULL; } +static bool iblock_configure_unmap(struct se_device *dev) +{ + struct iblock_dev *ib_dev = IBLOCK_DEV(dev); + + return target_configure_unmap_from_queue(&dev->dev_attrib, + ib_dev->ibd_bd); +} + static int iblock_configure_device(struct se_device *dev) { struct iblock_dev *ib_dev = IBLOCK_DEV(dev); @@ -119,7 +127,7 @@ static int iblock_configure_device(struct se_device *dev) dev->dev_attrib.hw_max_sectors = queue_max_hw_sectors(q); dev->dev_attrib.hw_queue_depth = q->nr_requests; - if (target_configure_unmap_from_queue(&dev->dev_attrib, bd)) + if (iblock_configure_unmap(dev)) pr_debug("IBLOCK: BLOCK Discard support available," " disabled by default\n"); @@ -923,6 +931,7 @@ static const struct target_backend_ops iblock_ops = { .configure_device = iblock_configure_device, .destroy_device = iblock_destroy_device, .free_device = iblock_free_device, + .configure_unmap = iblock_configure_unmap, .plug_device = iblock_plug_device, .unplug_device = iblock_unplug_device, .parse_cdb = iblock_parse_cdb, diff --git a/include/target/target_core_backend.h b/include/target/target_core_backend.h index 773963a1e0b5..a3c193df25b3 100644 --- a/include/target/target_core_backend.h +++ b/include/target/target_core_backend.h @@ -37,6 +37,7 @@ struct target_backend_ops { struct se_dev_plug *(*plug_device)(struct se_device *se_dev); void (*unplug_device)(struct se_dev_plug *se_plug); + bool (*configure_unmap)(struct se_device *se_dev); ssize_t (*set_configfs_dev_params)(struct se_device *, const char *, ssize_t); ssize_t (*show_configfs_dev_params)(struct se_device *, char *);