From patchwork Tue Jul 12 20:31: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: 9226213 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 8019760868 for ; Tue, 12 Jul 2016 20:32:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7366724B48 for ; Tue, 12 Jul 2016 20:32:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67CDE27D85; Tue, 12 Jul 2016 20:32:41 +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 1BD8B24B48 for ; Tue, 12 Jul 2016 20:32:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750907AbcGLUcj (ORCPT ); Tue, 12 Jul 2016 16:32:39 -0400 Received: from mail-pa0-f65.google.com ([209.85.220.65]:36384 "EHLO mail-pa0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750867AbcGLUcj (ORCPT ); Tue, 12 Jul 2016 16:32:39 -0400 Received: by mail-pa0-f65.google.com with SMTP id ib6so1657708pad.3; Tue, 12 Jul 2016 13:32:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=JCkqoTCFDugIpY+tr9UP59N0zFjQXoWAwbz6ytWFDZo=; b=tiVdC7ezc4l9rJHAd+RgKK5Y5lJIiz6HtG2Kkmb0Q2rAgrKuJOmGchK5XeNDpRfJUQ nC+MogTYLyaWC70Sa+v18EacUD1uymWGa/VkJVr7uwyomM1LqHig8Cj1VtiBdc3ybbmW V0eZ9AP2x8L2KfY/SoPAx/JFgQuaG2hOlzHn+18gyOwg6NpTZlY9tIUlRo4J5FzpLQx0 E/aBp4+JSS4m/kafxPzVB3MxQ+hAYZUJ+iXWPgyhs2h0yfNamVtiLZrEomvt/v62a2Ar aYM9kN6gTGoFp84fyzySTiWCEJPEpBtV39eBAMk5v5BBfkU1eU8CMhrMfvET6QOdHxBS liow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=JCkqoTCFDugIpY+tr9UP59N0zFjQXoWAwbz6ytWFDZo=; b=hR7TCIHeAOhI/6WlFLubxUaoZOYd1HACuRwLEeDfeItFPiU0a5TIVHHD73CPj6JJjP v49POxV5Yb428dHMh/rqkz6AailcR6XFvkwaEo4tiIiiekUJUUZijvAVHCs9f7s+uVro tRn7XO7MR4DIOX68TbzJvbeOqNSe4QwZEkgoB12WFf1D3qPBcZONocIHGFC4yq5yBqt1 T1YdQgeCfcLuFPseDDJHwYp5A6lBsQBlCAIUEceSTKduVUta5D9iSsMZeMPnM8V9tZc/ U/SVitwl88pYeIwMfhRf41xNQKuPzBnisWDRFt1yVxzCqYS3TCRz2ui8uEOEgJjtckKL eB3g== X-Gm-Message-State: ALyK8tJga+e1Yf+gtt1J6laFMUSpKqQD4iE2omm9JTjlHGukuywV0M/1EagROSkOlZL/6w== X-Received: by 10.66.26.105 with SMTP id k9mr7323974pag.103.1468355534450; Tue, 12 Jul 2016 13:32:14 -0700 (PDT) Received: from localhost.localdomain ([2404:c805:e00:4700:ae22:bff:fe29:e60c]) by smtp.gmail.com with ESMTPSA id e187sm7187559pfg.43.2016.07.12.13.32.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jul 2016 13:32:13 -0700 (PDT) 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 v6 1/2] libata-scsi: reject WRITE SAME (16) with n_block that exceeds limit Date: Wed, 13 Jul 2016 04:31:22 +0800 Message-Id: <844c07e66ad6d410029d80e6b32e8f1480fa9f47.1468354842.git.tom.ty89@gmail.com> 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..392aebb 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -3305,7 +3305,13 @@ 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 { + fp = 2; + goto invalid_fld; + } if (ata_ncq_enabled(dev) && ata_fpdma_dsm_supported(dev)) { /* Newer devices support queued TRIM commands */