From patchwork Tue Oct 22 00:20:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13844943 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C9F51D1714E for ; Tue, 22 Oct 2024 00:58:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=TP5SUkpFOyldAeG64DkAlgp/ANrr0ntMTe2WM/Kl4FI=; b=eYLAmx7+kXmOk5LP21BrEgZt3S SuSul04KFLST7pAYmv5695uJNCPrcEz0ekY6x0/MC6cgnstUb+6CYzOUbnP9Fkf/JQ9IdzDaIfXTD mIB3W2M+pEq/X+PY4hkIo2szgnEQexZuq2DzQQ6NBgudyjdU752LJVKeq1c8Hn6m9A7d9uZ5LP/Ja 43at4LJ2A2JBCL5mElr+Z2FXC9k/gTIZhe/ugHA0GIMIa2Ayrgy3fo+qAvmxJmTaTHQs2T8XQi4Q4 vRerMa0qOTmfTLhGr19Ciho8iCKeQvBkH5FkP9SYhfOItYp6a2OHAYsw/3GySu5DwNdhL2prXzPIl 4yCkotvQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t33EG-000000098QF-2cRT; Tue, 22 Oct 2024 00:58:32 +0000 Received: from mail-dm6nam12on20614.outbound.protection.outlook.com ([2a01:111:f403:2417::614] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t32e5-000000092a5-1Bq1 for linux-arm-kernel@lists.infradead.org; Tue, 22 Oct 2024 00:21:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=e2RaF37CzIp0Rsfrz2l1MRpfX3T+qmB0awhBNyHBk+aibgadkcA+nDXwSKyW32nzhxOSdyRvBiKrc2wzytzlpF8dTDdrQijgF28oO08fkYI3tcSIwlbxGTR4UqLpdtn0lxLRu3rPBmy9D9qZj5qOtyQNtB12iXJ88nEjrlglS3u0ESpEgRIMOr20w8GpNTkVNRXRW0/AhExGQMez1BFsa6yWj1qdvktrfXk6FkWbCnwRNw/+zSY9nuiCimUiPGZogJeslvdPFgrTkAXccXsS37R8j9QlpnR+pHpxRe3nn+1pUDhHIk9f+hYeI90TvmuvQI92bjSycomSK35mC6jOsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TP5SUkpFOyldAeG64DkAlgp/ANrr0ntMTe2WM/Kl4FI=; b=UgHE7mkM5WMTLX3XBRPWLA+1bUFJZhNSzjS+X4Q3zWfu/+Jw3gxNfoyRQMe5W88y2t26b9jzWvGtuNgRb5nVpHBVayAionDfffgXlgNFmmB4kpURwXrsdg+YpUh/XpWVBMT1deaqImxuJhuE8c0S89o5PjLRK/NU71cYr2RfI/5jOycfk6oBgEG/YbZN8w2CUuTYjrPsxaFH0ozVXG7kAHWUrMkOWbgqU/IAPGq9eaDlgEhav1+u/fRkb/DYeudqjJ5f461pR0oJewjGgJxHiC0kwqDXAD7Uga5jLvkEcCd6sZFZZO0b3oKnG5QsrgqLPC6VUD/MnasH0zhEapno2g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=amd.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TP5SUkpFOyldAeG64DkAlgp/ANrr0ntMTe2WM/Kl4FI=; b=G4IoHB0imq+X8OBmuUMnZCk6LNLA8R3jJfGxAwnyV2ynMiNyIGI/to48zS2X+4OyXsuiUNGHU49c+6lC8cyZpvft/JZGwHon1ibTX8iMUsfJOR+PRL/Fua5/9fuAyg/pBPP3Heyi99WaYbptCu4CCWjlu+pBYG+xSowOziTPM/ieTvYUw5BzVfeMfyNmSox+8klPoLAFk3D+nD8o9lf+/+OHJrWe5FnGU3gqI2NaSDU+mBdMiQPsUzkuojASrF/qm03v0yjDCD4sFDP60E94k5rVio3BcrN6ywmvpezcLYWcKkqp90sfZd9CR6RBKfwAXtFmhjpUNrpYVLL6eqzffQ== Received: from BN0PR03CA0001.namprd03.prod.outlook.com (2603:10b6:408:e6::6) by SN7PR12MB8603.namprd12.prod.outlook.com (2603:10b6:806:260::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.27; Tue, 22 Oct 2024 00:21:02 +0000 Received: from BL02EPF0001A106.namprd05.prod.outlook.com (2603:10b6:408:e6:cafe::87) by BN0PR03CA0001.outlook.office365.com (2603:10b6:408:e6::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28 via Frontend Transport; Tue, 22 Oct 2024 00:21:01 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL02EPF0001A106.mail.protection.outlook.com (10.167.241.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.14 via Frontend Transport; Tue, 22 Oct 2024 00:21:01 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 21 Oct 2024 17:20:43 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 21 Oct 2024 17:20:43 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 21 Oct 2024 17:20:42 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 11/14] iommufd/selftest: Add vIOMMU coverage for IOMMU_HWPT_INVALIDATE ioctl Date: Mon, 21 Oct 2024 17:20:20 -0700 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A106:EE_|SN7PR12MB8603:EE_ X-MS-Office365-Filtering-Correlation-Id: b8c06d3a-d393-4194-4cf4-08dcf22f68ef X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|36860700013|7416014|82310400026; X-Microsoft-Antispam-Message-Info: kVBlAhdsJlKqp7mbBTSF5+8IvOcz2aCJIQhCvhuS9ZzyMX/gisZISE+S/yN1xAeFo5O9QkzjJX8ypDUOci1hMi8zNVmzthZbdkRy52piEfTPLX3xer2nO92kg7oy2kcVGSyxXseWh2mUsWTLQ7GWUvOwt4284u3RnY3U44Mp1KWATplOzoTUFjJVPnLHyMumvZaOe7lS1fHMfGIPHcaIC6K+FwXm0IPkhDHyzPEMJo8mifWnFpQ8a7ZLL+LxM+MbuF53gd+CHvNSkyPTuHbZmrKhigl4bDdgbIcpe6g91ln+RUXX1WjxBqON8dPpDrg776MeyXwSlvHrvSHdZ+9NuDeYdTPiMICvLuc1y3+J22vyBv6ySUZeSWRaqavmdCVh2HEDuiNt0pcSssTuIB1H7OT5w2WfUxZZQ6igZGneEv52mVTC2tLyFBHaPkNS4yrVwXhsC3dc7IIiVBO2bDr3hEOq1ts5KodHXtxh8W1ehs9oaib2yw/QPWXwc88QygG/WPCWdP9Om0OqHubXKuETwzU0RDS+LRtrqIBt2VX7w5iqW+PixPxvC1BfWft8O3iL//tBqLjD73by4AJaxoNdZvcRqywQukRz2B8QEGyD5mT4jBNqRcAaTDxA/ZCBzAQDJWdq4Y4LP1Ge5S+neWfo28Vy6oBtfbuBeHuBR9tpT1HQ5ueYQWzram4vJ9Gni/QSj/V3fAeYiJszFaagd7ykrVkQj6n/LDG3fKPF6iEBbTMNctgJqw/M+B88glDiUd2iu3u2HpwHjNWwaHn0CJOC+okmlpCeqKiUMlovofNxNPcgDoPXBIJglqi8YiDwVB7mzM84ZYgBDVm4QmoiQMrseOa8425LxiuOfvL0h1AUyfFCe7bZostrBNA93u7Ghra+aRfosZaL8cUo2CUifA/gtJAbE1yqbnZun88ivjM1oszLK8gk9hQNzprlzDQuU6C6kF5B8MoufLRMRwIOPTloVxSTI+OQp79u+uwH1qwhmuGXSTdKPc5O6CDbma9cMb/GX86mHa/5HKLxz9wYyt0sFCPnmwAux2yKeNwrn5MC1hSYr/S2DrvfA8q3Gy1GGVDvG29RYA3mbyrBFJI98WvB5+naZGP2PYUFCuUv/bPCJq69Q6UezfomyqLc6ijxD36ht0zhSNM06jWjtU3qIkiQXY7Ns8IFW/6TTkQEo88KDKoRad6ZrPAArk35IalnKqOUZ2tI+qCDoX+/dqHSl0EjT13QDbNgp9W4MCdxwfLN1J+kI0DkHnQG2q9MwlVd142kzaz8HGdisIRr0wsDTorRZISP2UkD0dAUmS0cfxFI+glmPovvgQPIGvx0dHOVQV6Y/evOBlgDsirvV3i90aQNiDPXF+yTfRzR/6g/36qE+EhYrX3sinVUQEDqxYLIfI4D985xO6nahqPaO9n/sxLFJQ== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(376014)(36860700013)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2024 00:21:01.5634 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b8c06d3a-d393-4194-4cf4-08dcf22f68ef X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0001A106.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB8603 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241021_172109_414781_A4897715 X-CRM114-Status: GOOD ( 14.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a viommu_cache test function to cover vIOMMU invalidations using the updated IOMMU_HWPT_INVALIDATE ioctl, which now allows passing in a vIOMMU via its hwpt_id field. Signed-off-by: Nicolin Chen --- tools/testing/selftests/iommu/iommufd_utils.h | 32 ++++ tools/testing/selftests/iommu/iommufd.c | 173 ++++++++++++++++++ 2 files changed, 205 insertions(+) diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h index 3ae6cb5eed7d..aa458c80ad30 100644 --- a/tools/testing/selftests/iommu/iommufd_utils.h +++ b/tools/testing/selftests/iommu/iommufd_utils.h @@ -289,6 +289,38 @@ static int _test_cmd_hwpt_invalidate(int fd, __u32 hwpt_id, void *reqs, data_type, lreq, nreqs)); \ }) +static int _test_cmd_viommu_invalidate(int fd, __u32 viommu_id, void *reqs, + uint32_t data_type, uint32_t lreq, + uint32_t *nreqs) +{ + struct iommu_hwpt_invalidate cmd = { + .size = sizeof(cmd), + .hwpt_id = viommu_id, + .data_type = data_type, + .data_uptr = (uint64_t)reqs, + .entry_len = lreq, + .entry_num = *nreqs, + }; + int rc = ioctl(fd, IOMMU_HWPT_INVALIDATE, &cmd); + *nreqs = cmd.entry_num; + return rc; +} + +#define test_cmd_viommu_invalidate(viommu, reqs, lreq, nreqs) \ + ({ \ + ASSERT_EQ(0, \ + _test_cmd_viommu_invalidate(self->fd, viommu, reqs, \ + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, \ + lreq, nreqs)); \ + }) +#define test_err_viommu_invalidate(_errno, viommu_id, reqs, data_type, lreq, \ + nreqs) \ + ({ \ + EXPECT_ERRNO(_errno, _test_cmd_viommu_invalidate( \ + self->fd, viommu_id, reqs, \ + data_type, lreq, nreqs)); \ + }) + static int _test_cmd_access_replace_ioas(int fd, __u32 access_id, unsigned int ioas_id) { diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index 79b0739d586b..00f08f79b0d9 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -2489,4 +2489,177 @@ TEST_F(iommufd_viommu, vdevice_alloc) } } +TEST_F(iommufd_viommu, vdevice_cache) +{ + struct iommu_viommu_invalidate_selftest inv_reqs[2] = {}; + uint32_t viommu_id = self->viommu_id; + uint32_t dev_id = self->device_id; + uint32_t vdev_id = 0; + uint32_t num_inv; + + if (dev_id) { + test_cmd_vdevice_alloc(viommu_id, dev_id, 0x99, &vdev_id); + + test_cmd_dev_check_cache_all(dev_id, + IOMMU_TEST_DEV_CACHE_DEFAULT); + + /* Check data_type by passing zero-length array */ + num_inv = 0; + test_cmd_viommu_invalidate(viommu_id, inv_reqs, + sizeof(*inv_reqs), &num_inv); + assert(!num_inv); + + /* Negative test: Invalid data_type */ + num_inv = 1; + test_err_viommu_invalidate(EINVAL, viommu_id, inv_reqs, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST_INVALID, + sizeof(*inv_reqs), &num_inv); + assert(!num_inv); + + /* Negative test: structure size sanity */ + num_inv = 1; + test_err_viommu_invalidate(EINVAL, viommu_id, inv_reqs, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, + sizeof(*inv_reqs) + 1, &num_inv); + assert(!num_inv); + + num_inv = 1; + test_err_viommu_invalidate(EINVAL, viommu_id, inv_reqs, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, + 1, &num_inv); + assert(!num_inv); + + /* Negative test: invalid flag is passed */ + num_inv = 1; + inv_reqs[0].flags = 0xffffffff; + inv_reqs[0].vdev_id = 0x99; + test_err_viommu_invalidate(EOPNOTSUPP, viommu_id, inv_reqs, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, + sizeof(*inv_reqs), &num_inv); + assert(!num_inv); + + /* Negative test: invalid data_uptr when array is not empty */ + num_inv = 1; + inv_reqs[0].flags = 0; + inv_reqs[0].vdev_id = 0x99; + test_err_viommu_invalidate(EINVAL, viommu_id, NULL, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, + sizeof(*inv_reqs), &num_inv); + assert(!num_inv); + + /* Negative test: invalid entry_len when array is not empty */ + num_inv = 1; + inv_reqs[0].flags = 0; + inv_reqs[0].vdev_id = 0x99; + test_err_viommu_invalidate(EINVAL, viommu_id, inv_reqs, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, + 0, &num_inv); + assert(!num_inv); + + /* Negative test: invalid cache_id */ + num_inv = 1; + inv_reqs[0].flags = 0; + inv_reqs[0].vdev_id = 0x99; + inv_reqs[0].cache_id = MOCK_DEV_CACHE_ID_MAX + 1; + test_err_viommu_invalidate(EINVAL, viommu_id, inv_reqs, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, + sizeof(*inv_reqs), &num_inv); + assert(!num_inv); + + /* Negative test: invalid vdev_id */ + num_inv = 1; + inv_reqs[0].flags = 0; + inv_reqs[0].vdev_id = 0x9; + inv_reqs[0].cache_id = 0; + test_err_viommu_invalidate(EINVAL, viommu_id, inv_reqs, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, + sizeof(*inv_reqs), &num_inv); + assert(!num_inv); + + /* + * Invalidate the 1st cache entry but fail the 2nd request + * due to invalid flags configuration in the 2nd request. + */ + num_inv = 2; + inv_reqs[0].flags = 0; + inv_reqs[0].vdev_id = 0x99; + inv_reqs[0].cache_id = 0; + inv_reqs[1].flags = 0xffffffff; + inv_reqs[1].vdev_id = 0x99; + inv_reqs[1].cache_id = 1; + test_err_viommu_invalidate(EOPNOTSUPP, viommu_id, inv_reqs, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, + sizeof(*inv_reqs), &num_inv); + assert(num_inv == 1); + test_cmd_dev_check_cache(dev_id, 0, 0); + test_cmd_dev_check_cache(dev_id, 1, + IOMMU_TEST_DEV_CACHE_DEFAULT); + test_cmd_dev_check_cache(dev_id, 2, + IOMMU_TEST_DEV_CACHE_DEFAULT); + test_cmd_dev_check_cache(dev_id, 3, + IOMMU_TEST_DEV_CACHE_DEFAULT); + + /* + * Invalidate the 1st cache entry but fail the 2nd request + * due to invalid cache_id configuration in the 2nd request. + */ + num_inv = 2; + inv_reqs[0].flags = 0; + inv_reqs[0].vdev_id = 0x99; + inv_reqs[0].cache_id = 0; + inv_reqs[1].flags = 0; + inv_reqs[1].vdev_id = 0x99; + inv_reqs[1].cache_id = MOCK_DEV_CACHE_ID_MAX + 1; + test_err_viommu_invalidate(EINVAL, viommu_id, inv_reqs, + IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST, + sizeof(*inv_reqs), &num_inv); + assert(num_inv == 1); + test_cmd_dev_check_cache(dev_id, 0, 0); + test_cmd_dev_check_cache(dev_id, 1, + IOMMU_TEST_DEV_CACHE_DEFAULT); + test_cmd_dev_check_cache(dev_id, 2, + IOMMU_TEST_DEV_CACHE_DEFAULT); + test_cmd_dev_check_cache(dev_id, 3, + IOMMU_TEST_DEV_CACHE_DEFAULT); + + /* Invalidate the 2nd cache entry and verify */ + num_inv = 1; + inv_reqs[0].flags = 0; + inv_reqs[0].vdev_id = 0x99; + inv_reqs[0].cache_id = 1; + test_cmd_viommu_invalidate(viommu_id, inv_reqs, + sizeof(*inv_reqs), &num_inv); + assert(num_inv == 1); + test_cmd_dev_check_cache(dev_id, 0, 0); + test_cmd_dev_check_cache(dev_id, 1, 0); + test_cmd_dev_check_cache(dev_id, 2, + IOMMU_TEST_DEV_CACHE_DEFAULT); + test_cmd_dev_check_cache(dev_id, 3, + IOMMU_TEST_DEV_CACHE_DEFAULT); + + /* Invalidate the 3rd and 4th cache entries and verify */ + num_inv = 2; + inv_reqs[0].flags = 0; + inv_reqs[0].vdev_id = 0x99; + inv_reqs[0].cache_id = 2; + inv_reqs[1].flags = 0; + inv_reqs[1].vdev_id = 0x99; + inv_reqs[1].cache_id = 3; + test_cmd_viommu_invalidate(viommu_id, inv_reqs, + sizeof(*inv_reqs), &num_inv); + assert(num_inv == 2); + test_cmd_dev_check_cache_all(dev_id, 0); + + /* Invalidate all cache entries for nested_dev_id[1] and verify */ + num_inv = 1; + inv_reqs[0].vdev_id = 0x99; + inv_reqs[0].flags = IOMMU_TEST_INVALIDATE_FLAG_ALL; + test_cmd_viommu_invalidate(viommu_id, inv_reqs, + sizeof(*inv_reqs), &num_inv); + assert(num_inv == 1); + test_cmd_dev_check_cache_all(dev_id, 0); + test_ioctl_destroy(vdev_id); + } +} + TEST_HARNESS_MAIN