From patchwork Wed Jul 6 16:44:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 9216687 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 2AED860752 for ; Wed, 6 Jul 2016 16:44:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C49C27E15 for ; Wed, 6 Jul 2016 16:44:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10D3D27E33; Wed, 6 Jul 2016 16:44:52 +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 BADEE27E15 for ; Wed, 6 Jul 2016 16:44:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754490AbcGFQou (ORCPT ); Wed, 6 Jul 2016 12:44:50 -0400 Received: from mail-pa0-f68.google.com ([209.85.220.68]:33791 "EHLO mail-pa0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753813AbcGFQot (ORCPT ); Wed, 6 Jul 2016 12:44:49 -0400 Received: by mail-pa0-f68.google.com with SMTP id ts6so21511449pac.0; Wed, 06 Jul 2016 09:44:49 -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=IqswgbS9C5Fp2midkoFgYzxbyFDyUydKh9MS3uUvaww=; b=Bys+ZPSQ+T3AepcrYpoapDXIH1tJg9mhIgTSDnDijuDotXC29hsZCAI0iO4+Dlt/E8 fl1zj0qxbNl9GtOvrGMs+h94BCfIh/0YHiRRt7j+YpJKO3XWI7IXeYgq0NQkPlJHWiBx egMVJ5GIGwrvIPtNTRzb7xFefPQ2PGO9SPuYFo5vuiHAIDjUX+NQSNiKEUakMB12gI0k QLxGd2GdZkvy0DLJek7JycXI7lbI9eG0H8VY+WMCwJExg3K/fbm0EqqYAI51qf7th9be oWbVT3mUzUcDy1lr7i6iNx9JZ4NnoDxkZWMdSNqrFgs9WeULUkf+KZm566ey47icssPV TcgQ== 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=IqswgbS9C5Fp2midkoFgYzxbyFDyUydKh9MS3uUvaww=; b=W8ozCbbmzpWTlv7V6VOaXJGbJFdf4zroB8xTl7wH1bjCmAk59IZoyKSdQcs5ZXxT+3 qDIQO42Rp4adRIemX7CrdCNz/2oyxC7XKGibZ+36WbbhXPICAXAQkkQiLArvd8AIp3Ab ixIF9pdgVAMARL21nN2FTrePG2ZxCYk16N1naejSuZllX7wyUcK9IiYvsuwvGUNA42bc 6fOm8rPf2Il29r8ZT2KjyKGNkXLht+VQJeSfhIZpNQPjVLb3BQ4HYnVfbJv1PT93aZIk KTFM+YJmOaC9ZX3CirE2EEJ8aPNdRikayLr1YWKxOPuZuSW5R0h0ouGTTuW/MhvPdNcc vk+A== X-Gm-Message-State: ALyK8tIdqOYNDkudDXqv/TLKktXJvriRgLsPAO5FbhIWpwDi95SPCG2UpqQcrFVV2blT7g== X-Received: by 10.66.139.230 with SMTP id rb6mr44449705pab.101.1467823488928; Wed, 06 Jul 2016 09:44:48 -0700 (PDT) Received: from localhost.localdomain ([2404:c805:e00:4700:ae22:bff:fe29:e60c]) by smtp.gmail.com with ESMTPSA id x67sm4998857pff.47.2016.07.06.09.44.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jul 2016 09:44:48 -0700 (PDT) Message-ID: <577d3580.46c0620a.b8b1b.ffff9a01@mx.google.com> X-Google-Original-Message-ID: <20160706164440.1176-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 v3 1/2] libata-scsi: reject WRITE SAME (16) with n_block that exceeds limit Date: Thu, 7 Jul 2016 00:44:39 +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 CBD" 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 */