From patchwork Wed Jul 6 16:55:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 9216691 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 E159960752 for ; Wed, 6 Jul 2016 16:55:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D350927F10 for ; Wed, 6 Jul 2016 16:55:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C7FFC27F54; Wed, 6 Jul 2016 16:55:35 +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 BDBDB27F10 for ; Wed, 6 Jul 2016 16:55:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754692AbcGFQze (ORCPT ); Wed, 6 Jul 2016 12:55:34 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33750 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753813AbcGFQzc (ORCPT ); Wed, 6 Jul 2016 12:55:32 -0400 Received: by mail-pf0-f195.google.com with SMTP id c74so22317155pfb.0; Wed, 06 Jul 2016 09:55:32 -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=Rj3+UEY06IIsI5JtdG2FuA4SEhn+UajbHQj2ccSLOoU1+FRaPaYfqtDlQMtaKvDTwR VFBZz5g2fAmjwySvBsuJ2dAQaoLra1SHiVOVNvCGeWR2JWZED/I6NP/ADKA3L5PP3IVR rwiurriOETA3kgghyqRLDZb8TRxgXdMDkGAy1CMu6st1MSra07lO42C75eaJ8wHiCQwm lSyAH0g3FMTs2dCiJvIsOgC1vEtsPxu4fP2xf0SHUFjpNHuAOCb3uiSffKj2M4EVjobg aR0DWcBiiaI6phu8ucOHwvot+IUvvSUNqOiaMNWIQyaNnGYPWjB4nmOT0iStfiJh+/sb z9sA== 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=ZlnA0nGobFpv01Cgayl2cEX8f/Vj0hd+yJZG1VX1VE8/3+tUXjvqMaQn8/ViBv93GA FWM3opA6pTeLWTMRTzvHFY+HZkQv6ZZbmYQB0SJoOxozoiSyY7Amcln01BMk99+FL0zt mZu3L8BRh+TAGWTlj6dQ6edOsqH6ouT3+lXh0RCfxtjXKEqqbgo/i6vuhucAQ7PiIi1M uXvAtHe/8v/Xjy3HKsgurpNlhUqARrBykAefQXcvrX9wwNNqge3bi9JwurLlb0IgzkWl tjO4UsJr/eBjvgkyN7yShl0n5NOcvC99g5oF/zfFrMks9fh/tK4YSuBO1q5qwFwF1jMH fG1A== X-Gm-Message-State: ALyK8tKPixrAoCuOgwEMlyt6wmxCcXebOdD0Q/QKK3h/g0Rj5DNFcCTqsVtMWqDAmE9h1Q== X-Received: by 10.98.32.148 with SMTP id m20mr43434838pfj.77.1467824132090; Wed, 06 Jul 2016 09:55:32 -0700 (PDT) Received: from localhost.localdomain ([2404:c805:e00:4700:ae22:bff:fe29:e60c]) by smtp.gmail.com with ESMTPSA id p129sm5767888pfb.73.2016.07.06.09.55.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jul 2016 09:55:31 -0700 (PDT) Message-ID: <577d3803.875b620a.e1c80.ffffd000@mx.google.com> X-Google-Original-Message-ID: <20160706165523.1437-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 v4 1/2] libata-scsi: reject WRITE SAME (16) with n_block that exceeds limit Date: Thu, 7 Jul 2016 00:55:22 +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 */