From patchwork Mon Jan 22 09:04:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10177761 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 2C43360224 for ; Mon, 22 Jan 2018 09:05:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 179B727D0E for ; Mon, 22 Jan 2018 09:05:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08BBD27F81; Mon, 22 Jan 2018 09:05:13 +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 BA9AE27D0E for ; Mon, 22 Jan 2018 09:05:11 +0000 (UTC) Received: from localhost ([::1]:57320 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edY2Q-0007gn-DA for patchwork-qemu-devel@patchwork.kernel.org; Mon, 22 Jan 2018 04:05:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53864) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edY1g-0007I7-Oc for qemu-devel@nongnu.org; Mon, 22 Jan 2018 04:04:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edY1b-0003eb-Qp for qemu-devel@nongnu.org; Mon, 22 Jan 2018 04:04:24 -0500 Received: from mail-eopbgr30122.outbound.protection.outlook.com ([40.107.3.122]:51580 helo=EUR03-AM5-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 1edY1b-0003bJ-0B for qemu-devel@nongnu.org; Mon, 22 Jan 2018 04:04:19 -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=uVOsL75VK/jq0v19tsUD0ezUd4iqN7QGxPRmxpIZz50=; b=QTOuuw+osyL0vTRytOnULnGDY161loV1BvGxwpUuBrZbZvRwc3O6/P2uXpSU82KQc80U3WATRzkjpr/l8cikXa1T3+7qy7oqArE61Ir/UecErBCPLUqjTPl1GQysD2b87wGN4L+5Zwjlzz9Lb/kDjiwII/KTD6bgiduoexSHKNg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=anton.nefedov@virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by VI1PR0801MB1999.eurprd08.prod.outlook.com (2603:10a6:800:8a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.428.17; Mon, 22 Jan 2018 09:04:15 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Mon, 22 Jan 2018 12:04:01 +0300 Message-Id: <1516611841-5526-1-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR0502CA0012.eurprd05.prod.outlook.com (2603:10a6:3:e3::22) To VI1PR0801MB1999.eurprd08.prod.outlook.com (2603:10a6:800:8a::20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 58493fbc-ea33-4504-217f-08d561771d1c X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:VI1PR0801MB1999; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1999; 3:OrslIwW6jgSpkDnEoog1q4/gJlTvbPov/G+G9chPnPpV6xpiGVrQk11H5otOYNIomxq8yt5v9zXp9greRBoaGxhfcgk5dCCjt6L4KsIcq2v3TKmjwkeaY9rLqMCO8v4v7v48mHlI3IK/FEYikVI76/CiOtUhA5IDKWQ1AVhROcZElcwZmKN4R8oyCHQCkbnL3m+CXw64SP2vLWT6J1lZaLWjXefTo6nvpfWrWYl7ly06Yxe9glrq1gVBCpe5ekWN; 25:0AjNwaoipjk8dN6iEGVNGHJ36sshhJ9dFM2Jj+7GDVy4wygChFSB5PdZxhexJFDE32V71nXC7CEeRPmiD6F+AMCf6hCzmxHlod2QIW7oEjKae7LEIPwrOookr6h3vmdNrsdZUDQY87uZ1u2CU3pcBdHIkHaMdX2EUWaHTqM3FSSel5OBVpSQgciVQqHz/uwseg20whsF1YZCPTskCRWwrhY9ca98nv5xAYUDzjtmX3hqzFMjd2TleVbHeGezDo04ldhJFqfLJqjrs6K2C7eyjmm/7Wx8hHK5dpyEUyagOfUC6YAomD3rfh6aVz90dXn7WB1NaWNEfz2i4cqDsL3fPw==; 31:lCpzH6y2XLjZbbKlPPDp4NZB1Pr7vcVmZbd7ZC/kRYNPyunmvw0kZ7whiG1r9V3g+1y18NKUgz/iwyMuNvhwrlmwGpAmOdHCFJejhqkkX4BBWA2iOKYhouVv7Dpt4V0jdmejOGvwiNL+SnZdXLk7flLFTDnpYrrzcJeiqaH09h5AXwB4OWoiuTe08MsTbdrVSwq+nrZ4/CIWFuW03nIqMpz3tdM5tl2H8cHRjMSZBIc= X-MS-TrafficTypeDiagnostic: VI1PR0801MB1999: X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1999; 20:iVLudBLU2SSuo6VvdbPs9II6uG9295Gr5gTL3x5oVG89eICbypWVgOrb/2bPpQCB+swe2o6f9hd04oPsjqh5XeujSepYyT15sVKGVdAZSoUjA7Ulj2jj96U7Qux2/z/eLur7+j9wbYHFGox1BzaHVpe7oPAHrFBe5oZCdzR0jlIMxru1EvwxiZDEpinr14jR/laVRxoonJ9WOBv9/fuboiLvwrUGLEduU7xHDxtizUg7a58+yHmQ7G0/FLR57ocKiDgcdJKUa7z7F4xiFX2aQNkfGvZG+9sUZ6luKY+Mv84sCLOb/zqfH/3Dmxldg/FG9uDFwkJ30y/WZxxW4pLPCkyqdh22ft0d+cfDhRnckgLW4XEU++VB0Ij73yZ6CBWxOdpbw0WniYa/EZcVe5kyCWXsEaef6mq/tYChwRPZ/6s=; 4:Oz+bQB/tJ7ZcVX5nZ6aIFAD9jD3F/dFihviBKCxsTjEg0WLrJMbKDN/dmECWWX5ZleEUKPgoyH0/Mwn5LFceO7ydDlMR5F6+gTMdWlaSob7+VvpHI88HN6o/cEcZavLRBgy/Nk77wi+3hf9nN6sgQ6Ifnv+iWWXbIs7r4ug/INMsCD+NMaqm0Ag5yhqrBl/EkOL3d2WBXROqN77NLzCyno8R/UxDZg7LLq3FFiXJ+pneohErIpZh/TKwZFmcA7it/vRuAzMC8VxZK+5Fk1hoKQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(3231023)(2400081)(944501161)(6041288)(20161123564045)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011); SRVR:VI1PR0801MB1999; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:VI1PR0801MB1999; X-Forefront-PRVS: 0560A2214D X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(979002)(39380400002)(366004)(346002)(376002)(396003)(39840400004)(199004)(189003)(66066001)(4326008)(6512007)(69596002)(59450400001)(107886003)(53416004)(26005)(386003)(6506007)(48376002)(50466002)(97736004)(47776003)(25786009)(316002)(478600001)(16526018)(16586007)(6486002)(5660300001)(53936002)(3846002)(6666003)(6916009)(6116002)(36756003)(50226002)(81166006)(105586002)(81156014)(8676002)(8936002)(52116002)(51416003)(2906002)(68736007)(305945005)(2351001)(106356001)(2361001)(7736002)(86362001)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0801MB1999; H:xantnef-ws.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; VI1PR0801MB1999; 23:Di+0uYeWDnjC/lfXqa5TwdR3HBMkNsBVt645Ja7?= =?us-ascii?Q?7tRrzOtXhxwty04mcItbwh/ZrMXHH9wCsSuqPsCubZIAZi7/Olb9NDY852zC?= =?us-ascii?Q?9fAMx/1iO/CMysDeWegy6ZRF47KQR7a0e6Gv9daSHjXAzV5rCRaH7JUUY0ya?= =?us-ascii?Q?NNU/YJ+H89O4J2dpCa0PzJqOMGdfbbE+ZX4+Gu058Wq2Fs6fMkdLIH0hyWCn?= =?us-ascii?Q?CuH9MhoG1Tp/mjEUfK05U91GykZ1r9sImKNUaY5UAyj6m3P+AMPx5brGYY9s?= =?us-ascii?Q?toslA+yuEEzIjmlujSvSfCnO35zR8vX3PsIE3ylLf/qAo5hO7PraevuOvYQV?= =?us-ascii?Q?OQ2qRQFemTWehC/BqfSvdNUB4RMCwKBCz9qqYaCuHVROuPwiy6AWY16Xq5wC?= =?us-ascii?Q?RlRu2Ezw4gr2hc1AIWmYnyfIiYqvD90CIerzdpQyMvqnU4CNHWcSByPCHfY7?= =?us-ascii?Q?11LSs0+aVU+pnkkRnBTaYwaL4mGD5Mnnnj2ePK+L9vUdbTy7cNUNBWtir6xg?= =?us-ascii?Q?9DoX+rB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aioFfCCiSqX5cUHe0oopYv9yzAV09gHRrMGcoueTiKZdjGkZ711woku0PdeL5FKDyCNUKox6dnJ8CcNH6YIbYDEWnc04Cxhvrv+PhlbdI8Y1jkLrvktRoc2LKqRQGNMTKUbFLjkbQ6DXP0fzKCueEXx5rNqBWbHe0H+Y6B26JvwIZDfdbW3LWWg5ArlIKhtaQnr7CBtdI7kuD3kQpm7VJYK2XfA7sqHP0xx56nypZPloBZXcjechGtSXS1WNhj1e4STk=; 5:asyhyVutrTje/zJUfaYApYpxwWEnsIczwnmPTZ1svoRv7KNZUgKbrLv5+Hmexb2mywm9NueqHEUtG7q8wBIO3U85d8k1rOfxpZzYGRrJfK20xesmQZOutWvzrvKykxW4udFIk50S9H/trXLwrH69bibRg2S9sFSaj+I7Rp1fbyg=; 24:eh8jOChB6ALcxfbd/VfZBEFCUEu82u6mo+FpJ7rJT70A1hdmQDfR6IKNVm2UQ2r/4yfv0kULFavme44NnkdBa3y+RKy9LxFQf0tAUnxqBYw=; 7:mE38hGbblHOps65+Ez59WTdTb6ausG5s6g3XwxJT+GKPHt6vqXdZmzbzuTPhTtaEWHHCwhNSWSGKw2PhZRpdG46SGcNJxv79VYNkhHopXpMXT+TWfUxHBZfMKPSXy1UlQP7IF4CKOt68Ds4YRtdRHeZ6w9rwr8/y3SFsYuWN1LjUvVfv084qxfjOLdqvyjO1RS31fjZrTCjSzgM8y7dzD2Nxp1zO3RD28cb/qRQm5I9N1AJNnQRWXJzMNF7rXhfm SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1999; 20:FjybFzbslkMQtY28LU3DGHJ5X8uDAazvs6g7DjNJoL2cpUaZbQdDk8+kibumEfYyo72QyMDpiFaZxcnnGAZOC2z6eF8jtVXXVYmY8uJfsQeNVsckC9HOTsIxj77R2AIRoz/eypAE57dTKH3zqUJsBku7pQlaEPKtqXBtXeF2zSQ= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2018 09:04:15.6741 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 58493fbc-ea33-4504-217f-08d561771d1c X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1999 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.3.122 Subject: [Qemu-devel] [PATCH v2] ide-test: test trim requests 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 Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Anton Nefedov Reviewed-by: John Snow --- tests/ide-test.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/tests/ide-test.c b/tests/ide-test.c index aa9de06..be427e4 100644 --- a/tests/ide-test.c +++ b/tests/ide-test.c @@ -52,6 +52,7 @@ enum { reg_data = 0x0, reg_feature = 0x1, + reg_error = 0x1, reg_nsectors = 0x2, reg_lba_low = 0x3, reg_lba_middle = 0x4, @@ -69,6 +70,11 @@ enum { ERR = 0x01, }; +/* Error field */ +enum { + ABRT = 0x04, +}; + enum { DEV = 0x10, LBA = 0x40, @@ -81,6 +87,7 @@ enum { }; enum { + CMD_DSM = 0x06, CMD_READ_DMA = 0xc8, CMD_WRITE_DMA = 0xca, CMD_FLUSH_CACHE = 0xe7, @@ -179,6 +186,12 @@ typedef struct PrdtEntry { #define assert_bit_set(data, mask) g_assert_cmphex((data) & (mask), ==, (mask)) #define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), ==, 0) +static uint64_t trim_range_le(uint64_t sector, uint16_t count) +{ + /* 2-byte range, 6-byte LBA */ + return cpu_to_le64(((uint64_t)count << 48) + sector); +} + static int send_dma_request(int cmd, uint64_t sector, int nb_sectors, PrdtEntry *prdt, int prdt_entries, void(*post_exec)(QPCIDevice *dev, QPCIBar ide_bar, @@ -204,6 +217,7 @@ static int send_dma_request(int cmd, uint64_t sector, int nb_sectors, * the SCSI command being sent in the packet, too. */ from_dev = true; break; + case CMD_DSM: case CMD_WRITE_DMA: from_dev = false; break; @@ -234,6 +248,10 @@ static int send_dma_request(int cmd, uint64_t sector, int nb_sectors, /* Enables ATAPI DMA; otherwise PIO is attempted */ qpci_io_writeb(dev, ide_bar, reg_feature, 0x01); } else { + if (cmd == CMD_DSM) { + /* trim bit */ + qpci_io_writeb(dev, ide_bar, reg_feature, 0x01); + } qpci_io_writeb(dev, ide_bar, reg_nsectors, nb_sectors); qpci_io_writeb(dev, ide_bar, reg_lba_low, sector & 0xff); qpci_io_writeb(dev, ide_bar, reg_lba_middle, (sector >> 8) & 0xff); @@ -344,6 +362,58 @@ static void test_bmdma_simple_rw(void) g_free(cmpbuf); } +static void test_bmdma_trim(void) +{ + QPCIDevice *dev; + QPCIBar bmdma_bar, ide_bar; + uint8_t status; + const uint64_t trim_range[] = { trim_range_le(0, 2), + trim_range_le(6, 8), + trim_range_le(10, 1), + }; + const uint64_t bad_range = trim_range_le(TEST_IMAGE_SIZE / 512 - 1, 2); + size_t len = 512; + uint8_t *buf; + uintptr_t guest_buf = guest_alloc(guest_malloc, len); + + PrdtEntry prdt[] = { + { + .addr = cpu_to_le32(guest_buf), + .size = cpu_to_le32(len | PRDT_EOT), + }, + }; + + dev = get_pci_device(&bmdma_bar, &ide_bar); + + buf = g_malloc(len); + + /* Normal request */ + *((uint64_t *)buf) = trim_range[0]; + *((uint64_t *)buf + 1) = trim_range[1]; + + memwrite(guest_buf, buf, 2 * sizeof(uint64_t)); + + status = send_dma_request(CMD_DSM, 0, 1, prdt, + ARRAY_SIZE(prdt), NULL); + g_assert_cmphex(status, ==, BM_STS_INTR); + assert_bit_clear(qpci_io_readb(dev, ide_bar, reg_status), DF | ERR); + + /* Request contains invalid range */ + *((uint64_t *)buf) = trim_range[2]; + *((uint64_t *)buf + 1) = bad_range; + + memwrite(guest_buf, buf, 2 * sizeof(uint64_t)); + + status = send_dma_request(CMD_DSM, 0, 1, prdt, + ARRAY_SIZE(prdt), NULL); + g_assert_cmphex(status, ==, BM_STS_INTR); + assert_bit_set(qpci_io_readb(dev, ide_bar, reg_status), ERR); + assert_bit_set(qpci_io_readb(dev, ide_bar, reg_error), ABRT); + + free_pci_device(dev); + g_free(buf); +} + static void test_bmdma_short_prdt(void) { QPCIDevice *dev; @@ -963,6 +1033,7 @@ int main(int argc, char **argv) qtest_add_func("/ide/bmdma/setup", test_bmdma_setup); qtest_add_func("/ide/bmdma/simple_rw", test_bmdma_simple_rw); + qtest_add_func("/ide/bmdma/trim", test_bmdma_trim); qtest_add_func("/ide/bmdma/short_prdt", test_bmdma_short_prdt); qtest_add_func("/ide/bmdma/one_sector_short_prdt", test_bmdma_one_sector_short_prdt);