From nobody Mon Feb 9 05:41:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151640145320152.409030075250485; Fri, 19 Jan 2018 14:37:33 -0800 (PST) Received: from localhost ([::1]:50082 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecfHu-00033b-2k for importer@patchew.org; Fri, 19 Jan 2018 17:37:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57656) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecfCg-0007kP-DK for qemu-devel@nongnu.org; Fri, 19 Jan 2018 17:32:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecfCf-0005NC-9i for qemu-devel@nongnu.org; Fri, 19 Jan 2018 17:32:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34526) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ecfCf-0005KS-4e for qemu-devel@nongnu.org; Fri, 19 Jan 2018 17:32:05 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 58FE3C050049; Fri, 19 Jan 2018 22:32:04 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-231.bos.redhat.com [10.18.17.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC31081213; Fri, 19 Jan 2018 22:32:03 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Date: Fri, 19 Jan 2018 17:31:58 -0500 Message-Id: <20180119223159.29890-4-jsnow@redhat.com> In-Reply-To: <20180119223159.29890-1-jsnow@redhat.com> References: <20180119223159.29890-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 19 Jan 2018 22:32:04 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/4] 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: peter.maydell@linaro.org, Anton Nefedov , jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Anton Nefedov 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 Message-id: 1512735034-35327-4-git-send-email-anton.nefedov@virtuozzo.com Signed-off-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 27226bfd51..5be72d41dc 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -400,6 +400,7 @@ typedef struct TrimAIOCB { QEMUIOVector *qiov; BlockAIOCB *aiocb; int i, j; + bool is_invalid; } TrimAIOCB; =20 static void trim_aio_cancel(BlockAIOCB *acb) @@ -427,8 +428,11 @@ static void ide_trim_bh_cb(void *opaque) { TrimAIOCB *iocb =3D opaque; =20 - 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 =3D NULL; qemu_aio_unref(iocb); @@ -455,6 +459,11 @@ static void ide_issue_trim_cb(void *opaque, int ret) continue; } =20 + if (!ide_sect_range_ok(s, sector, count)) { + iocb->is_invalid =3D true; + goto done; + } + /* Got an entry! Submit and exit. */ iocb->aiocb =3D blk_aio_pdiscard(s->blk, sector << BDRV_SECTOR_BITS, @@ -470,6 +479,7 @@ static void ide_issue_trim_cb(void *opaque, int ret) iocb->ret =3D ret; } =20 +done: iocb->aiocb =3D NULL; if (iocb->bh) { qemu_bh_schedule(iocb->bh); @@ -490,6 +500,7 @@ BlockAIOCB *ide_issue_trim( iocb->qiov =3D qiov; iocb->i =3D -1; iocb->j =3D 0; + iocb->is_invalid =3D false; ide_issue_trim_cb(iocb, 0); return &iocb->common; } --=20 2.14.3