From patchwork Fri Jan 19 12:40:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10175189 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 4D3FA601E7 for ; Fri, 19 Jan 2018 12:41:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3BE4128669 for ; Fri, 19 Jan 2018 12:41:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CBCF28696; Fri, 19 Jan 2018 12:41:25 +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 CEAE628669 for ; Fri, 19 Jan 2018 12:41:23 +0000 (UTC) Received: from localhost ([::1]:46902 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecVz1-0003Wp-1T for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 Jan 2018 07:41:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55814) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecVy5-0002pR-Dw for qemu-devel@nongnu.org; Fri, 19 Jan 2018 07:40:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecVy1-0006T0-6A for qemu-devel@nongnu.org; Fri, 19 Jan 2018 07:40:25 -0500 Received: from mail-he1eur01on0717.outbound.protection.outlook.com ([2a01:111:f400:fe1e::717]:53696 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 1ecVy0-0006RX-M9 for qemu-devel@nongnu.org; Fri, 19 Jan 2018 07:40:21 -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=gKWaa63Ldd8BnjqrcMdgN5WA4dWa8pUW81MDxljJpHI=; b=cKdT0cQ90kuHcodBsC4kJmPQBvmkVsYsirx48pXYVEU8fuxX3LTFpnoOZyIcbZOkCK7UQpbXZGAgc4gHI1l0GeKVfAoSwljOp6OMUoGK0/izqb3SM2Xe+ejOncLIWwzrPy+qkeOB0IYVB3uPqy3gpNU2oqlrSX7F/mLGlwB3bK8= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=anton.nefedov@virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by AM5PR0801MB1986.eurprd08.prod.outlook.com (2603:10a6:203:4b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.407.7; Fri, 19 Jan 2018 12:40:17 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Fri, 19 Jan 2018 15:40:00 +0300 Message-Id: <1516365600-105416-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: HE1PR0202CA0005.eurprd02.prod.outlook.com (2603:10a6:3:8c::15) To AM5PR0801MB1986.eurprd08.prod.outlook.com (2603:10a6:203:4b::13) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d20079a7-6fb6-4343-71d5-08d55f39cbdb X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:AM5PR0801MB1986; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1986; 3:CNUxXNJEB4LWvO+WrN31by6wkCUgDgLHIGy/wG+708UJwqltq7HuAxG6qa3LAc8GjaNkDVXvXZ/7jaMpiq05tsdFGoRrZK8jAdKiH7l+q0qH4hcC7GCaIJZ7/3z5gT/Are0Q8840lbsFkYYhaUIJY6yjT2kBAzDoBYrIrn49fdS4PeEIYSEyUF5+J0j1MMbtdskO8U8OoeOUPrfqU2TPeHu5gNzB/KPzxYN+URomFi/IV9HwcRk6u9dHfh7+YLwP; 25:e8pkGAu3O9UNOV5AP/Ce8OcuRPZQ90FvlWRsH4m2SoFcffZCXGq2LqzlNauYWCiEwMUOfx30CvmUxVuy68K8mccO05xBx88rEpCzbmIQt3RgatF81K7sHYADcUTk9V50jZbL4bJqKPxptypk2BhyiQISpCvb8pW3TvBpZUyG5RZCkMFGyrLNsH1oRSNHsVbyPY36/SxvtvYMq2wZ/Fk8EH1kySn5ZW5PHrMVibZEoOmlZF5zTz2wBCzFs1mnrq/igdRtWkIH3VijiCk81jUlkkqmKEl6Zt7q2IgPvev38UwhFV4VT+9xaG3hOo8+hQ3dorgfg+rrmPJ/IJO3plG3Bw==; 31:/1JMJuBWn06S+wK8XbJV+Yg2d/Yr7HR6jk8kNSPddQ+10fvHwgQeO0ycnHrzhY2U8CkGCUkSYSgLHLaoy9d6M0gg/NuVVN0D6ycuS8bGOsTIsPEhc20op0DRqQ4j9ncxYi52NmblYWIg2YBQAGduz9geJQl3MQ6O/Xd5LNa1++F8hg6VXWSWsf1Eu+pIiDzEPVmwRppFjmRiIuxSWxoMUxeIDuqDeXYpc/vhhboeUp8= X-MS-TrafficTypeDiagnostic: AM5PR0801MB1986: X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1986; 20:8bhtcnWuJX2nVSwcN9ZmDRocE3mMiwEgQYwnlYfSLC72+I8MRbAf0zExm/YYVNAgrmSzDS3FPu8kjq2axlsx0YQlZdHTGWmOAHQLLo2zHkpJUuzGvMbe7czVYw063H1NAEc85GdhBeE/YlVdVyDhPaMdoaA+O1DX7tREsObe/M7VxPpdC3DkaIb1J15NJA7SC6G58znL9lhhCly3RKHLiFgUjGo93vMe+ejGvKcZxk16H2wi4pJf+FDXBVDa8ovBe4xg0Ui2AKAfkGSNFBcMPyVhRNY4lKqO47W6SuhhDt/aLxpx1+IgXioH6MQEMpR36V4rlP232pmMiv0ktAhi3+c+X4iSjmzUMHb/tyfJ7NE0l6K4M7EQ7ZxgjGQYuFAvGqNL/OW2r4nNigeruiAF69i3EIKG3O4nLKbIduwuClo=; 4:5LDLfwNT6rjHHv5mXUrJtCHxsMsuMSVRu3AJ3ButhXGCg9CW/L4AhgMJ3zRQy6WP1gW1oZkxzGujljC4aqtpq2Pg3Q0pHb/0s1slIIzCn1WAHzsIOe1noq+4CXD4prsNm1eaJldDhgUQk9MKg3bkqmOkRq29uSvoLO9mHBONC8hH6TaIrOQrcwGPksE1riSZEA/kT/+KwwdfaX/TEd9iGGdNcD+DATSWSBXanQ+JVLFjBdyxXVmDDSj5palTaQ9zFE4MgfIl8TGa9JP8UWrf5w== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(3231023)(2400077)(944501161)(6041268)(20161123564045)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011); SRVR:AM5PR0801MB1986; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:AM5PR0801MB1986; X-Forefront-PRVS: 0557CBAD84 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(366004)(346002)(39380400002)(396003)(39850400004)(376002)(189003)(199004)(2361001)(6116002)(3846002)(2351001)(2906002)(48376002)(50466002)(16586007)(86362001)(105586002)(6486002)(478600001)(106356001)(6512007)(107886003)(36756003)(6916009)(66066001)(47776003)(97736004)(316002)(81156014)(7736002)(16526018)(69596002)(53936002)(5660300001)(26005)(6666003)(53416004)(4326008)(305945005)(25786009)(51416003)(6506007)(68736007)(8936002)(50226002)(8676002)(386003)(59450400001)(81166006)(52116002); DIR:OUT; SFP:1102; SCL:1; SRVR:AM5PR0801MB1986; 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; AM5PR0801MB1986; 23:SbF/CmZtov1Da965NHtpBRsjFa4MHBUoBG5OMzW?= =?us-ascii?Q?F9Wi1M2rCeB0ocE6TSwnz8R9HM+6LkkRFX6mtVdwI0WDjslfI0PPg5CUFX6B?= =?us-ascii?Q?jgg+lKStky/7NaB8H4tNmzdzWzCayseKveRXh8NIRACmn0ldfcRM4TrEvUzK?= =?us-ascii?Q?L9ll6grsS4qXjg/Shtp48IaXO/3crmMXotC9B6QzJolhoJ2259j8WWa86YKX?= =?us-ascii?Q?W3xp/MEBL7BiIfOEGojRTt9UCWUOMeQkABRknXK1+kdkTf3BUw4CAwFa6W2Q?= =?us-ascii?Q?8dGiHX2+Ec1HC+PjsHwFPRR6zud+RTSP+oZYqPudJfQKp7F/YXD25eSJJ1a7?= =?us-ascii?Q?jj58M4Qqn8Wcn/x6cLGuF94JDkYkXqji008TiDyfPvbXoLs9W9suiWxM9Iq3?= =?us-ascii?Q?fy6WZsK4ieYt4PyoxL2qkBciZw7xdOmnVdnU6QBjvp0h9MD7JxME3g49rb5D?= =?us-ascii?Q?prcKFDwVn5D3usrridiK0hH7KU2e65Ya+7qf5YM+5fXK2QmDAvUUlop/hIHV?= =?us-ascii?Q?vz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RX8DoUQPpxIKX54F38+gr7WS4v7jJW1EOxgsHRjBPfBcmOkxh86IhY20/lFC4NyMjwKtZhcBoZXcmj67OkWk9Nngsq2v3Zb+E2u3cGvAIS6DYEEqqGB5fm/0xTbSpoT9k6pw=; 5:a5bWDS633mdLgzC/p6uR6LzHo96kQXp2kd2u5YAYCaFu+cz7GmxgYYMC4cv15ThDn/TS4z4QNl6Pe45eoEkGA3YXiuVkB/PlYH3F6lzVd9HYcxkzuGnItXNLT3ZdsP2BtpKrs9yqXL+ODkcrDfjMW/80lddRVPRfiH2F8EFzmHw=; 24:+1Apm6uJCK0fhIoeXcjp5WGKnkVp9/e6vlDJMWmvkFLXIALga3kNtVXaC+akcJ0HZnhcbPiFop1pCxCGn7OSlg5OYJFAoqWX6XCwRXTgfWw=; 7:/w63k1Ul2vgCd5Xz/OLA753vPW8YuvC5VuwXoN9jfWmJNqOB3bY5I6fX9HWWAw91IVgkWMN2Aw7lfwzPeMmJaM0F6n5oAPC3QoU8DSKcVZycYk2Gr6ymbjzfbSdjHMi4uHqsjZ54pgr9Jmhz6zQLcTwI+yuMWXHBRh1on2tTuG5tc+73j443nZ6hhItBn+EiyoVLh6Gj8Pi5fx6aWsfi6z07jt8X98KW72uSJ6AwaZU1WZQkubjLUAOvwWmAIxLk SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1986; 20:yfJhka2AJE7ti54OqUcgsg3srKYtEoyk564GkmIYW/tyR2B2ssqvJuw9C1HlwvGyy/cQCXu5Vsx9alkBbPNSGhMeO9HcP5o9xmRKuoB2fpz7XPvAJhwHupXnf9XavXAlKpmp5iSM4odluuk9Pa1fTLb4s6DMEAri0BYNEYi3H4k= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2018 12:40:17.7911 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d20079a7-6fb6-4343-71d5-08d55f39cbdb X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1986 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 2a01:111:f400:fe1e::717 Subject: [Qemu-devel] [PATCH] 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 --- tests/ide-test.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/tests/ide-test.c b/tests/ide-test.c index aa9de06..259f39f 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, uint64_t count) +{ + /* 2-byte range, 6-byte LBA */ + return cpu_to_le64((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 random_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) = random_range[0]; + *((uint64_t *)buf + 1) = random_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) = random_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);