From patchwork Wed Jul 6 17:19:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 9216701 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E1F5060467 for ; Wed, 6 Jul 2016 17:19:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCF4027F89 for ; Wed, 6 Jul 2016 17:19:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BEE7327F99; Wed, 6 Jul 2016 17:19:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6680627F89 for ; Wed, 6 Jul 2016 17:19:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754706AbcGFRTV (ORCPT ); Wed, 6 Jul 2016 13:19:21 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:34188 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753917AbcGFRTU (ORCPT ); Wed, 6 Jul 2016 13:19:20 -0400 Received: by mail-pf0-f193.google.com with SMTP id 66so22320584pfy.1; Wed, 06 Jul 2016 10:19:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:from:to:cc:subject:date; bh=+T78xZdZTuuNN7Y1e0dlKpHwbmvR85R7ifhN3iXv2rk=; b=Kv6ogpXNXPdSJYkHuE+1f5u5wv5IMAPS13qMfkdkduAHpyYjbJLO+9rb5UZkQu2NJF J/oql3IbCL5d7xCTeOZlBpmFdNfm4S8XWPQI/NklSEA8DVR+SWVI674/1q41OIvN/1Il iTBpK66XlFSoXlnaMckqMjPD+fMHRInjFNRDeAWLLwoMme63lu+IFDjK+6x9m0FrIklg +I88bZpNnMzPzRR7a/FV32/9GWDZVQwc6fhZRfgPgpR3/JD1p9xEA8wuj/J4Erza9mNW j6Ff9LiJwhIW4KKBmNiE9DuZPe59kbr70MCwUw3xYX4sKtlzcayS+fDx00jBwBl7jGIy PjQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:from:to:cc:subject:date; bh=+T78xZdZTuuNN7Y1e0dlKpHwbmvR85R7ifhN3iXv2rk=; b=FtiUPZlpgU3Jjiqf7SIvzWnH4hBet8WG1pgEcagrAyoDExNTKHw1qVe4eaegli/aKH ZvN6fMv8zmarzhuI1YXpOfZ+MEyVrSpoc30KtToOPAd5/45KunOqrPB9wVwNQ8McFd08 zaaBEO2+RubjaLokwis0IdJiDm4xM/mV6tPE7fEUAefPixqv/GP6gPfI8Hb5okOTnGev RlYVYxhWMKGJAwFFfsCUVM2I1elb8+FyEuElwaSX0UhmX7hRz38ucJQrA1UcdgdYqSvM aG+pH+G64a7C+iTCbP1tyTnHWxut12OBBlaShkMouF5Ohxpbl4TFqTTHxZXBIE/FV66e s4Uw== X-Gm-Message-State: ALyK8tKmHuk8efddcRRYV7mCTPHS89xrl/t17WZLWgbZGY43BBWrg97xvolBDaXW7Zz63A== X-Received: by 10.98.149.149 with SMTP id c21mr44470963pfk.73.1467825559439; Wed, 06 Jul 2016 10:19:19 -0700 (PDT) Received: from localhost.localdomain ([2404:c805:e00:4700:ae22:bff:fe29:e60c]) by smtp.gmail.com with ESMTPSA id vx4sm5900199pac.35.2016.07.06.10.19.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jul 2016 10:19:19 -0700 (PDT) Message-ID: <577d3d97.24f0420a.c2bbd.ffffd426@mx.google.com> X-Google-Original-Message-ID: <20160706171906.1993-1-me> From: tom.ty89@gmail.com X-Google-Original-From: me To: tj@kernel.org, martin.petersen@oracle.com, sergei.shtylyov@cogentembedded.com Cc: linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org, Tom Yan Subject: [PATCH v5 1/2] libata-scsi: reject WRITE SAME (16) with n_block that exceeds limit Date: Thu, 7 Jul 2016 01:19:05 +0800 X-Mailer: git-send-email 2.9.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tom Yan Currently if a WRITE SAME (16) command is issued to the SATL with "number of blocks" that is larger than the "Maximum write same length" (which is the maximum number of blocks per TRIM command allowed in libata, currently 65535 * 512 / 8 blocks), the SATL will accept the command and translate it to a TRIM command with the upper limit. However, according to SBC (as of sbc4r11.pdf), the "device server" should terminate the command with "Invalid field in CDB" in that case. Signed-off-by: Tom Yan diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index bfec66f..a1f061a 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -3305,7 +3305,11 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc) goto invalid_param_len; buf = page_address(sg_page(scsi_sglist(scmd))); - size = ata_set_lba_range_entries(buf, 512, block, n_block); + + if (n_block <= 65535 * 512 / 8) + size = ata_set_lba_range_entries(buf, 512, block, n_block); + else + goto invalid_fld; if (ata_ncq_enabled(dev) && ata_fpdma_dsm_supported(dev)) { /* Newer devices support queued TRIM commands */