From patchwork Wed Oct 9 16:38:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13828860 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 DDF45CEE330 for ; Wed, 9 Oct 2024 17:22:22 +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=5asN4gechTz+hjEKh9L0yFbZdpPyBvxZHorkwZtYA64=; b=ZC+hYs4YheJekTh5gG3gU9vkYm 6mz1yNgN2AJi1N0nWWdUSjyBXqhqZXQm2RFxnDVyqjCgz+pJ1wbRN2FADxXWsOl9cBzmGrML6BSUa R8ha+gAgSCSXxeJYkAxswCcnXBdspCAVgZAaH1Wgt6xpq+NHMb4GVEITLFizcwJtaRX9grRQ5e3bj E1cd/Li9XiOc3GBGvuRiPBSK/khRkRqHQhSbxjjW6QAH/DTdRFVfcdu/LjnugShCa0K36HaKwYW1c /D3lLqTuUJR/neYV24ovGCZa8gNWPTtrsFxxxFTw83cHk1igs7czCoqBksO3ngr2n+/EFHGGpb2zx GM0dfrlw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syaO3-0000000AA6B-0tov; Wed, 09 Oct 2024 17:22:11 +0000 Received: from mail-dm6nam10on20600.outbound.protection.outlook.com ([2a01:111:f403:2413::600] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syZik-0000000A0hW-3BVK for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2024 16:39:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=aS7naL7bzzm1MJ3g2j98KntXlFprYZMmQbIpdMqnoKc4jqSVInjiAFkigiNEg2ZvUznDj4OtX2Xb6ZMrKd4g3g4FZpI+BRUnIKjVQj0CKq39JmmU+rYmcuda1Aosu99CvXqfaTOKqXlZdVLXR54VSW7Zv7eOHqrXTeZya/2DlgEGUejcMBrfOlQsPKH7A6VAe/70CsicLkDjAOZNaEDWyhIu45AB08+cXDZVhvpzYawJhndG5gT89qNdE/K12DjV+aFaGYayt5PKy31k/wzi7rJKuWGm8Y4iNyX6sJKpaWDFCvQhm2x5ky+yospH9qe4LR4efvD2yEKUyywQTRLm8w== 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=5asN4gechTz+hjEKh9L0yFbZdpPyBvxZHorkwZtYA64=; b=VF4aK9RqtQ9gTnb3ApCPMRxepE+UnZ02OsbE9KXTmGH5CNCMi14ewElqszmqxuE9K44TELP7CHJzfRlvEyqrAK+kU0aw76zKyXKGeDYAtzz/bgGqJ8VC2rJV8fVcy4kDXXwrP++iNuO607c1HC2vO9RIVIB0zMbVBJrJqcT/U7keXtOXZ0FjmtIwgDQC+pGAsQkVgWwblNHm8U1zxVhj8vF5PLGSUn417XkJVEfTmocf0kFzNC789fAeLCeqpMt24KM0izmloTfOM+ZejkzBIg6Cvd7RtS+q6kN2sMbt300+t3hhaUZZ2NaXXWK1ohUu35B97eQ1Ir7C3h5rlVLiPw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=intel.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=5asN4gechTz+hjEKh9L0yFbZdpPyBvxZHorkwZtYA64=; b=HJOKSvMdmE4vw6olASvB0mBRfcSUA5FNRjO33W9xUwMm5o5pb3Z6Zn3inxk5eXCuWabJCkFe2HWqZO8FaAo2Ww8Adux8dPgMT+tsInJo82s4j7o6ap3gjANImbWE3E1Cyw36SOqTheLgVJ42E4XJbe73wwLZSa/NFLR7dflOB8XJapqYPjOlFX229ir2q8n2uJ/Q43KUM9saUigADaiULnfNFj5LvkSgEgB+vDStcwQhwQGnlNiUnJa4i24nLINyrkvXkYN2k3nfile+eZm+uOulRZ58c1xQ8zuJJkUaLmU+W9URFcb5ECeNR7hHcNawZBOiHDNefJgBQKRKKDsLEw== Received: from SN6PR01CA0028.prod.exchangelabs.com (2603:10b6:805:b6::41) by DS0PR12MB7780.namprd12.prod.outlook.com (2603:10b6:8:152::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.23; Wed, 9 Oct 2024 16:39:21 +0000 Received: from SA2PEPF00003F64.namprd04.prod.outlook.com (2603:10b6:805:b6:cafe::2e) by SN6PR01CA0028.outlook.office365.com (2603:10b6:805:b6::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.34 via Frontend Transport; Wed, 9 Oct 2024 16:39:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) 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.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by SA2PEPF00003F64.mail.protection.outlook.com (10.167.248.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.13 via Frontend Transport; Wed, 9 Oct 2024 16:39:21 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 9 Oct 2024 09:39:10 -0700 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 9 Oct 2024 09:39:10 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 9 Oct 2024 09:39:09 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 11/16] iommufd/selftest: Add IOMMU_TEST_OP_DEV_CHECK_CACHE test command Date: Wed, 9 Oct 2024 09:38:23 -0700 Message-ID: <021a42e13a7aeded63451279480510a8bc8a4833.1728491532.git.nicolinc@nvidia.com> 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: SA2PEPF00003F64:EE_|DS0PR12MB7780:EE_ X-MS-Office365-Filtering-Correlation-Id: c80f0764-2d26-4761-8ba3-08dce880ed59 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: VCBjyiU6rosXqAtV/WX06NgOMqlrvMpRtf78rhRK9VAOj6oYv5BW+stkLs0BqJlCGP7GIAOMWlLQj0gO3R2d1gX+D5A9be/nJH4TGuQgEY4Cs6WnM/Pm9QLtJcrIj+T2zrxHCfiJiVYhwARSl75hXI55V+daOpjCql/tfxw1hXyO8NuYogEbswXmNHIGaRqlHGj3XOLtQsedwAsfzhCN3XGsRiukpe81TLpDAgBdvJYSLCTMgp0ad2wrYHueO+rTOnEV+1Z6eIsA3dJBxw5WvmmegUmvHeLzlYvahcsmL9IKclvlQfipgnEvAsIwLdsF9Evy0vrCKRGB/5QA0g4Hd61q2EYGp8u4eaRLCCF9RMnnaw+I0Tnuhce8uYxx30dYc1v3ObtTjk2sd3AuaXae3AQtE2X4gxIDcN2Yxew3UhPkNJ3TxLdXwo76ckPFSZyrGMGqq8SCMVXpKPHmZa7r0dNXU+DxaLoGulMeDbldvu1UKn/gJ0/JodQ7CNKqg2fB4tS91F9xPGT4k/Pdi80xOfS3mQsfKtH5BdSwo1X4ssyfG9Zc0NRC1mDYG5mEsqV1WdRfqYw+1Q6ih1sL0p9gvcbTRBvMazbzgAz8d4yh1VUQZ5Rd3V2ePVJAuTt23XGHL4v3Swhk53YgnDg6vVEVKY7akFjy2V085ucokG7xtsIdqs8vSg5rYxH3NZVwXV/lRg0NT+l8354ai5TGQ78EfNbGfkWkGGHUM8aDEeA3J9RPqNrcj4PPs/96IcI0BVfYF3/OuhEESYIoZbkcmvdd89Mxugzk+5H8eULz55nI1VyhB1xNPnjNuTvmT7zUdp6Zo/vsWcIukJzoIsPOh8Hmm/8YO/Q6/k4ccXxQQAQgF3Fj1WOSP12OTfTlT9gM1nqeWvyJQ0FebmUOXpdIb+383euH+bDnBZBKfHfOm4U9Rc5ecGNpXhy+RY9Una961BeKnxe69EFw4UyTsxyLW9TVrBDYP5m+PkFmt92kCY2PSCNEszSST4eV6RngwsFXwxEIgI7uyjror/lEXSFohOh1u3qWXKQHBJF0KXOl8vNgPLIUeYzR2IQCRCrCYx0D9YGHVAnFhbBWhSyiY4LMETWvjvl95UoBJJHXsPUgopIPlz/fAu39FWqn+JFNPzWChWwRpH1YQJPXTJnGmJuEBplKMrN/7ky0q216N0CTNi4P1d3rRiymcKUSej90fexMy26wop0Va4O5jtQ2Ubz/4pZvkBBzC9H9t75Lb/1K/mhUYIj5+Zu7lNOhj+JqfW/SZm7OroG8zYsnSb9TJJ/mU6eekZoYAltkTnOiRw/JFyG0h+z6moTmjCImFZPlxl2xXl9h5Te986XdBvwOm/XKPYSZnAblRhiJdZpM1pKi74Iq9kYDggYKH5WaiKRm7Z2EySzb X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2024 16:39:21.3575 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c80f0764-2d26-4761-8ba3-08dce880ed59 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F64.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7780 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241009_093930_917881_E8911AED X-CRM114-Status: GOOD ( 16.64 ) 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 Similar to IOMMU_TEST_OP_MD_CHECK_IOTLB verifying a mock_domain's iotlb, IOMMU_TEST_OP_DEV_CHECK_CACHE will be used to verify a mock_dev's cache. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_test.h | 5 ++++ tools/testing/selftests/iommu/iommufd_utils.h | 24 +++++++++++++++++++ drivers/iommu/iommufd/selftest.c | 24 +++++++++++++++++++ tools/testing/selftests/iommu/iommufd.c | 7 +++++- 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommufd/iommufd_test.h b/drivers/iommu/iommufd/iommufd_test.h index 05f57a968d25..b226636aa07a 100644 --- a/drivers/iommu/iommufd/iommufd_test.h +++ b/drivers/iommu/iommufd/iommufd_test.h @@ -23,6 +23,7 @@ enum { IOMMU_TEST_OP_DIRTY, IOMMU_TEST_OP_MD_CHECK_IOTLB, IOMMU_TEST_OP_TRIGGER_IOPF, + IOMMU_TEST_OP_DEV_CHECK_CACHE, }; enum { @@ -140,6 +141,10 @@ struct iommu_test_cmd { __u32 perm; __u64 addr; } trigger_iopf; + struct { + __u32 id; + __u32 cache; + } check_dev_cache; }; __u32 last; }; diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h index ccd1f65df0b0..b3da8c96a828 100644 --- a/tools/testing/selftests/iommu/iommufd_utils.h +++ b/tools/testing/selftests/iommu/iommufd_utils.h @@ -234,6 +234,30 @@ static int _test_cmd_hwpt_alloc(int fd, __u32 device_id, __u32 pt_id, __u32 ft_i test_cmd_hwpt_check_iotlb(hwpt_id, i, expected); \ }) +#define test_cmd_dev_check_cache(device_id, cache_id, expected) \ + ({ \ + struct iommu_test_cmd test_cmd = { \ + .size = sizeof(test_cmd), \ + .op = IOMMU_TEST_OP_DEV_CHECK_CACHE, \ + .id = device_id, \ + .check_dev_cache = { \ + .id = cache_id, \ + .cache = expected, \ + }, \ + }; \ + ASSERT_EQ(0, \ + ioctl(self->fd, \ + _IOMMU_TEST_CMD(IOMMU_TEST_OP_DEV_CHECK_CACHE),\ + &test_cmd)); \ + }) + +#define test_cmd_dev_check_cache_all(device_id, expected) \ + ({ \ + int c; \ + for (c = 0; c < MOCK_DEV_CACHE_NUM; c++) \ + test_cmd_dev_check_cache(device_id, c, expected); \ + }) + static int _test_cmd_hwpt_invalidate(int fd, __u32 hwpt_id, void *reqs, uint32_t data_type, uint32_t lreq, uint32_t *nreqs) diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index 8a1aef857922..ac3836c1dbcd 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -1106,6 +1106,26 @@ static int iommufd_test_md_check_iotlb(struct iommufd_ucmd *ucmd, return rc; } +static int iommufd_test_dev_check_cache(struct iommufd_ucmd *ucmd, + u32 idev_id, unsigned int cache_id, + u32 cache) +{ + struct iommufd_device *idev; + struct mock_dev *mdev; + int rc = 0; + + idev = iommufd_get_device(ucmd, idev_id); + if (IS_ERR(idev)) + return PTR_ERR(idev); + mdev = container_of(idev->dev, struct mock_dev, dev); + + if (cache_id > MOCK_DEV_CACHE_ID_MAX || + mdev->cache[cache_id] != cache) + rc = -EINVAL; + iommufd_put_object(ucmd->ictx, &idev->obj); + return rc; +} + struct selftest_access { struct iommufd_access *access; struct file *file; @@ -1615,6 +1635,10 @@ int iommufd_test(struct iommufd_ucmd *ucmd) return iommufd_test_md_check_iotlb(ucmd, cmd->id, cmd->check_iotlb.id, cmd->check_iotlb.iotlb); + case IOMMU_TEST_OP_DEV_CHECK_CACHE: + return iommufd_test_dev_check_cache(ucmd, cmd->id, + cmd->check_dev_cache.id, + cmd->check_dev_cache.cache); case IOMMU_TEST_OP_CREATE_ACCESS: return iommufd_test_create_access(ucmd, cmd->id, cmd->create_access.flags); diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index 2651e2b58423..d5c5e3389182 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -222,6 +222,8 @@ FIXTURE_SETUP(iommufd_ioas) for (i = 0; i != variant->mock_domains; i++) { test_cmd_mock_domain(self->ioas_id, &self->stdev_id, &self->hwpt_id, &self->device_id); + test_cmd_dev_check_cache_all(self->device_id, + IOMMU_TEST_DEV_CACHE_DEFAULT); self->base_iova = MOCK_APERTURE_START; } } @@ -1386,9 +1388,12 @@ FIXTURE_SETUP(iommufd_mock_domain) ASSERT_GE(ARRAY_SIZE(self->hwpt_ids), variant->mock_domains); - for (i = 0; i != variant->mock_domains; i++) + for (i = 0; i != variant->mock_domains; i++) { test_cmd_mock_domain(self->ioas_id, &self->stdev_ids[i], &self->hwpt_ids[i], &self->idev_ids[i]); + test_cmd_dev_check_cache_all(self->idev_ids[0], + IOMMU_TEST_DEV_CACHE_DEFAULT); + } self->hwpt_id = self->hwpt_ids[0]; self->mmap_flags = MAP_SHARED | MAP_ANONYMOUS;