From patchwork Fri Dec 8 12:10:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10102435 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 6981160325 for ; Fri, 8 Dec 2017 12:15:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44AFD28AB8 for ; Fri, 8 Dec 2017 12:15:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3783128C06; Fri, 8 Dec 2017 12:15:06 +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=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 96EA628AB8 for ; Fri, 8 Dec 2017 12:15:05 +0000 (UTC) Received: from localhost ([::1]:36806 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eNHYW-0002ZL-WB for patchwork-qemu-devel@patchwork.kernel.org; Fri, 08 Dec 2017 07:15:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39020) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eNHVP-0007OZ-5R for qemu-devel@nongnu.org; Fri, 08 Dec 2017 07:11:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eNHVL-00044c-1m for qemu-devel@nongnu.org; Fri, 08 Dec 2017 07:11:51 -0500 Received: from mail-he1eur01on0126.outbound.protection.outlook.com ([104.47.0.126]:59386 helo=EUR01-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eNHVK-00043g-PK; Fri, 08 Dec 2017 07:11:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=tTDBl6KiJuJQjnK0rkmnRW8IBt0Qe5KlpTAnXa/7QSs=; b=G006sobMDMHfJ0kHBvdtTRWtHjjcPs8ZezstGNqHZsn/vE1pOEtmR2mc/k6Z9DrfXtMkEHjzOYXto1q+7JvsxOPKjeo8bKOnwE6xD2RajVNmKd2KSc8HYTLAEI9HUH8K+uJumHyJfnhpfUo116iRODtO/rvrb3aSQ26x0W1Crjs= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=anton.nefedov@virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by VI1PR0801MB1998.eurprd08.prod.outlook.com (2603:10a6:800:8a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.282.5; Fri, 8 Dec 2017 12:11:45 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Fri, 8 Dec 2017 15:10:34 +0300 Message-Id: <1512735034-35327-4-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1512735034-35327-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1512735034-35327-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: AM5PR0602CA0015.eurprd06.prod.outlook.com (2603:10a6:203:a3::25) To VI1PR0801MB1998.eurprd08.prod.outlook.com (2603:10a6:800:8a::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 42e208e5-dc7e-493f-a624-08d53e34d9f5 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(7168020)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307); SRVR:VI1PR0801MB1998; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1998; 3:ibE9AVgxZJCwH4PRavHzAO5t24YrJREBc4MXkS66eGN5CbrCxSXCXJ3bu2QfLx9NoSxQmpLdPQx/hXvhxQJ7OKDoTZxazqgj0P0mSCOQCI9l014vlfg62L4G+MGEe5YiPZubtiDUBBop5kSpj6Pwg1tE9FA/nUBFTzheZ5Ocpd/PLFSJB8mSVyRvre5CCKolpEdZVIxGf6LvPpWG/foPpX0qShCQKtVIwmEabz1vUtkr48fzOlRE6I4fjUdDNrCc; 25:zVErb4QbRPk2nw/dTtGRyelvzAvr5TavaI9pqDUWDkjsDzQuzF1qj44n+PKFFv4kXt3U7wBO2qom4YHkrfBfAyST+imDXvE0FRz0wnm0EuMpFuQ/mg5d1ljabgyVGcgR9AgF6Rn6XrnuNtaDX09znohsYE6KfGJtazppAX+SNjONT27Xl7DGdM90bnmdC+iHt42NqmmAFlDuFN8YkzC4agD7/jpS0Gc3qL4f8OfAoJR/4l/4WZ861TP9O249yOxfrAhj+NsJcntRxScJ0LMXg+gQxZVJ9spmfRPf7xRVKVnHwn/Z6HATHO2oxuCcJk1VAI4or5K42bjpqv+3zlXCWA==; 31:C7x/YzlH1XlEGUPsPKuZMi8O7RES1FNw4lbh/vHho97p2YaN2Bi+EcjVuZRH/nircpvf4hc6xddxvLcY7zCMWlFQcb8/VPYV282XvJpphJRp6c6udFE53vQqAdjyxEp+EuwgOfUTo8iU7kDpzYS35mBAeq2O7a6btsXbvN8tYOGasBzXMMiLZ2N3k6n9PEnTXoRzE4EMYbTyqG6WQzAPx7n0r7JSoaPc1FxtzvYW644= X-MS-TrafficTypeDiagnostic: VI1PR0801MB1998: X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1998; 20:J6VHKQYboB9Y0/n05Mi0f3aSwZhv6jvZgd96OqD/PsmWW6A0QE8l1qjpPzyECkWTUkVooru+N8PET0uqff79eFoNA3kaEQx3FfOy8Qw/e0fN8JkwapUepbf7DkyFfttjCR+Z+Pa48ZAVlJlVrIxafnyZNr75q50KtAX82NHecNvP3sp28RZuOmEGOu773BS6/co1Dndtk6ULdWHANFzWN5AVg0L/k3oEEeZMOVzSdv6dSLzhelZlUn2VaO7mAIjq8FgR4MGKqmmTSIS+uH7UtXk3iFgEhMKPi3Vld5w9hEUFT0hkxQ4W3F/mBlsrkMMBw5TXg84ITEYr5XZwvQEYUzhiDdfeFH25r5QfaLUhn1NBeKE+vA6esFN/Kg/cSiAERbuMSzLygzXs2wFYC+6+Ox523TCS+srGn1AQ2VCbYAQ=; 4:x5wnhBozSgzzlvh/6DtjXmBCtol3AXp/NVwxDFEKHtmP1jJ6StXuUzk4TQt2tchi2WeT589bJ+UxKFFuANx94o9vhIcKvq3rWneNS+t8IxGt/bKhX/tZPIt0xfJvEAjtqj98TnspZZiGu0qcwbk1KdW8Zdk9pm7SWFUigxFa9maP05N1BDg6bw0/D7AZObXHbamMXMzXsyPpR0MRtZ5B+P7nfTUqFegcY/xl0a2+57X7BqThTDBNQN7J8xvtJxTCZKKUnZxDo1DmX6rwZegnag== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(2401047)(5005006)(8121501046)(3231022)(93006095)(93001095)(3002001)(10201501046)(6041248)(20161123555025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123560025)(20161123562025)(6072148)(201708071742011); SRVR:VI1PR0801MB1998; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:VI1PR0801MB1998; X-Forefront-PRVS: 0515208626 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(39830400002)(346002)(376002)(366004)(189003)(199004)(50466002)(47776003)(69596002)(3846002)(25786009)(55236003)(97736004)(36756003)(16526018)(51416003)(6116002)(478600001)(6512007)(48376002)(76176011)(6486002)(52116002)(16586007)(316002)(6506006)(2950100002)(305945005)(5660300001)(68736007)(8676002)(7736002)(107886003)(50226002)(86362001)(6916009)(2361001)(2351001)(4326008)(81156014)(53416004)(2906002)(53936002)(6666003)(105586002)(8936002)(66066001)(81166006)(33646002)(106356001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0801MB1998; H:xantnef-ws.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0801MB1998; 23:EMkt5QaWrjmYR6/28MBbzo4+5JZfrWGDT0ItqhQ?= =?us-ascii?Q?81AmhKwOUGCcPMGd84que965YzyL2XqAYbp2nQ7ND22QOm474BJMRG/0k/xE?= =?us-ascii?Q?L5/bFjlH1N/rJlZQfAzrDiqtxxR4xN4vskftjnfZ9r8DURSrrgLiSw7KKI7e?= =?us-ascii?Q?6gy+9QJCTL/AVzoS/7LHYxX1SWxuHS/1JPA+sy0uAiWGH/8tqqNVPPUOwRjw?= =?us-ascii?Q?DYClfUPUxZXp1mPHorU6X1zv90aynwOstNZqke5Un/5VpagQQJ8SAXiXgAZW?= =?us-ascii?Q?ZKFik4pkkJ6DyN4MKEop8U0QmCwcpKG8peJict3/dcLjPE6kdJdPWoBi6so2?= =?us-ascii?Q?j9z5PQcJXUXV9tb2TKlzPd9kB5wUvVAj9cVBf+0CJ25sRMQYEl1cutV+14R5?= =?us-ascii?Q?mUqHM2HFLpoEqrxxzS2rm6f8qovV8dD8t58Pxjce7t+tihAQV2KT1G553fvb?= =?us-ascii?Q?3SDVAoo86xNQD3YR2lUc4kXFq2Yg/CV5s1OGXPZ/7HReA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tNXv7AIIRDpATJfrCzbxUDxxWv+0eiJMHJl7nacA6WGFTdyOhNfjjuHNn0Tkb8vHJro+SN8gDsQVbF9JZjNM8XVOsZC48yib5Csj3AZVDS116Vqdb1OXtb3+P9vBNRNKzYQUsDCtLmrPMKygJqR/m2fAcSr8LugvdmiEQtw+hTcJP7d/mKO8=; 5:ELRWiIEGyBSySk0nRE0U13ctMvHk2m0Ffse8wjTSvefrPFKVfxeshZzqeI1td4aFuaY4DqCwtO5Oms0rDN74eHYgbkuUufXVtCd1/SWx+w2rNr4AdKymYGmH/gqhNxyQGOUwkQeXbYvC4SEvz3d69EaE8PKOsPSkY6ngV7sZwCs=; 24:FCGlyvV8c8oPuUWg3x92YEJNaYJ7xE3oyzjw9mU8nqZ/4NUTjHwvLucxMMskMXMWT3ivVyKrFIasPsiT3Hn9phjz5yRE4HlJJp1kz+NtNUA=; 7:Xh4+byrL3YFsoaijV6bqEdSByymUCDRKZ2vhxZDBdN5YX2FoD4y/ek58I9Vpa4mmYyzt8z1MikeIM3ouiqoJ2/5wHbGfctFYkSou3Rb7DaukKbk0z2QfKFgEUswOttD/oEUC1VnpsEMnx9b8hDd0U8FIhnH+VWtBfhQ8ocWwKyy7D3CL4nchOFBFVglScddkndQHTP8n0DIfDKShAduDshSc/QXm3Zov1SziWqAHm4cBwhbE4k2hn65m6Sjj7C2S SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1998; 20:ssxM31oeI0H/EZkTRG/RYvrQE89Nigjl4Kkqh6/ZzI6heN89KIlQx6JVEvqVbR5OzJTBWtmmoGm+aSN+t/ExARJPLoque7jV8298iL+AtGP2n9x1SSXczHMD18qvTAEbpZpNurpOzeMFyUh3V+VE2M2cn9+OSXcn8y+tlXd2RhI= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2017 12:11:45.4863 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 42e208e5-dc7e-493f-a624-08d53e34d9f5 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1998 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.0.126 Subject: [Qemu-devel] [PATCH 3/3] ide: abort TRIM operation for invalid range X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anton Nefedov , jsnow@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP ATA8-ACS3, 7.9 DATA SET MANAGEMENT - 06h, DMA 7.9.5 Error Outputs If the Trim bit is set to one and: a) the device detects an invalid LBA Range Entry; or b) count is greater than IDENTIFY DEVICE data word 105 (see 7.16.7.55), then the device shall return command aborted. A device may trim one or more LBA Range Entries before it returns command aborted. See table 209. This check is not in the common ide_dma_cb() as the range for TRIM is harder to reach: it is not in LBA/count registers and the buffer has to be parsed first. Signed-off-by: Anton Nefedov Reviewed-by: John Snow --- hw/ide/core.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/hw/ide/core.c b/hw/ide/core.c index 23c71fa..3d1494f 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -401,6 +401,7 @@ typedef struct TrimAIOCB { QEMUIOVector *qiov; BlockAIOCB *aiocb; int i, j; + bool is_invalid; } TrimAIOCB; static void trim_aio_cancel(BlockAIOCB *acb) @@ -428,8 +429,11 @@ static void ide_trim_bh_cb(void *opaque) { TrimAIOCB *iocb = opaque; - iocb->common.cb(iocb->common.opaque, iocb->ret); - + if (iocb->is_invalid) { + ide_dma_error(iocb->s); + } else { + iocb->common.cb(iocb->common.opaque, iocb->ret); + } qemu_bh_delete(iocb->bh); iocb->bh = NULL; qemu_aio_unref(iocb); @@ -456,6 +460,11 @@ static void ide_issue_trim_cb(void *opaque, int ret) continue; } + if (!ide_sect_range_ok(s, sector, count)) { + iocb->is_invalid = true; + goto done; + } + /* Got an entry! Submit and exit. */ iocb->aiocb = blk_aio_pdiscard(s->blk, sector << BDRV_SECTOR_BITS, @@ -471,6 +480,7 @@ static void ide_issue_trim_cb(void *opaque, int ret) iocb->ret = ret; } +done: iocb->aiocb = NULL; if (iocb->bh) { qemu_bh_schedule(iocb->bh); @@ -491,6 +501,7 @@ BlockAIOCB *ide_issue_trim( iocb->qiov = qiov; iocb->i = -1; iocb->j = 0; + iocb->is_invalid = false; ide_issue_trim_cb(iocb, 0); return &iocb->common; }