From patchwork Mon Mar 27 18:38:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13189848 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56FC5C76195 for ; Mon, 27 Mar 2023 18:39:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232475AbjC0SjG (ORCPT ); Mon, 27 Mar 2023 14:39:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232170AbjC0SjF (ORCPT ); Mon, 27 Mar 2023 14:39:05 -0400 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2076.outbound.protection.outlook.com [40.107.95.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61C221AD; Mon, 27 Mar 2023 11:38:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mxYW5GjUtnzzSHOrtZuuIbvHqn2Cy45EAb0LQ8jajOwYSsQ7CrJXjQV70yLnfLUmRP+2rf/XnBWWhq5NDdSvGKfeY9FL5d0vgL1kckf+K3E/vnhzFnOsYxh7dXPbIk6lqmxrkb5xZaAjU9JqYqXte/EZpTFP7kzTKED+aOkUfAcOuEt2DgtqpwO+AEPAAZLgIvZNzozKK8EfIImplZgyg4xGe1QgWaEDG7xRAkwkPjC1TSfakmCf97Mw6r/JANifioTFUh7Li1uvjcSAe2k0iA/0Z5pagb9F8TaXRt1iJUrI1jNvILPEucwF35XKwshlJ/I37CXTMG+quc2IbS/mPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=YPFv55G9dMElzX1sVD7XmlLL1r1w5TkbGUmLhCo4NDs=; b=mOMsbhdqBdjRZvMwjV0FYdYxTTiDypqmhYNWlxMhVsGp8E5v267IWKFSRNyBB1GvoylNXFkdsRqzAgapzqtKoxvrhxbL2MYSzdbdxSr9JF/7V2mg3OXJVjUQzuDKScb/4h1HH55WTQoNUx5+1Xi2OJkIfluWKFnmojhvK2wAYqhN0ujNOywIu5cwVw1qFI9JJIZL6k2JZcpJYJiXipbx+JiWEAofQgI7vplz//qklylrmtINXxV1VXcswVXWLw6pZYDzUrXxVBAQpJaEIPkh9xBFt/EkxwGmFJKGD/qAdZunRluzXz4L9y4sc4P07kNhJ9CxqZomGpcEMRvuxIqvpQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none 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=YPFv55G9dMElzX1sVD7XmlLL1r1w5TkbGUmLhCo4NDs=; b=VFf9nwu1HQEecT5OKBc5c8Kqmh54RcIO6JMixRL8Didgw1rP0mypMZooU3pYaWxOAXRzRiF/MFnpSpMNHQyg0B+hh9yfBJpoDHEKLyp6e4Dwj07bjh+XNImxlax9S4kfAZstmDCWRrasx5DxH8LAEHyZFrJXidT/JWADIIxWEmulLmoIJexX6ieL6mcHkP1VOJKHE9407jvBg3nHCbcpLZ4JRcc7Ft2StjRlmDJRNJ7sB6haqXKRDJ1ggUmAW5YCganWirSPdAEkhexvcB9oB89J7kNf221ao2v8fWkLNh4z+gMsDUColB5XBZSp+gyLYCsCdeag5UTPwNFxUXycIg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ2PR12MB9008.namprd12.prod.outlook.com (2603:10b6:a03:543::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6222.30; Mon, 27 Mar 2023 18:38:16 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::ef6d:fdf6:352f:efd1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::ef6d:fdf6:352f:efd1%3]) with mapi id 15.20.6178.037; Mon, 27 Mar 2023 18:38:16 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Kevin Tian , linux-kselftest@vger.kernel.org Cc: Lu Baolu , kvm@vger.kernel.org, Nicolin Chen , Yi Liu Subject: [PATCH v4 17/17] iommufd/selftest: Add a selftest for IOMMU_HWPT_ALLOC Date: Mon, 27 Mar 2023 15:38:11 -0300 Message-Id: <17-v4-9cd79ad52ee8+13f5-iommufd_alloc_jgg@nvidia.com> In-Reply-To: <0-v4-9cd79ad52ee8+13f5-iommufd_alloc_jgg@nvidia.com> References: X-ClientProxiedBy: YT4PR01CA0391.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:108::9) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ2PR12MB9008:EE_ X-MS-Office365-Filtering-Correlation-Id: 2b8cad41-6fdf-4b63-f92c-08db2ef26bb2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KoHjRHjJc8/FuG9uZzVfjl/mczq101Qh9p0U4ZkU/MV6zJ/YyIaFurFxHtHNvzZFdkgzSnLJfMqWMF51Dh6m12RxLVyazgQooShWQ51pzvV1QcYohF4VSw4xwOawQVWPkFQPeX4eXwGI9rlmswIm8ZlXe9ajsPflVZB8rVI4urx7IjVnWyG5YWd1d470BVDz/gaLKPPJ85sJ3uTqfDPtVIzdefCgR2wuVj0AiakDx0C7Ef2xsdwZ3+HKBHklsrRBtAMYgj32H/DnUHrrMbisRnVsbyNBU8QP3h1wBj87qEPYfeEtBr24ZYeB8sFMuWOw/0eTA8/wb3acBOVW2EGSJ9NlxaEBRE7EuMKaA6KcIg03hcyTBpZHZchTlfFnZsd+q3F7VHVvXygXvx/etFt82XWjgmiOIJuz+9ZjJ1EUhkpBDQiHEDFVRqhLhSLmc4o9Q81UjbMsmHDVB8E1JjhBUTMOfQmkqRNJ2ZtrKxBOERU3VmmKRAb9ekttou/Y0qG75+41TN4pgAtUEBLwPq2xfHUc7m/4PE0UL1L0Mrz5Y83l9jHOA+bdJDlJk3Bsprbc X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(396003)(366004)(136003)(39860400002)(376002)(451199021)(6512007)(6506007)(26005)(54906003)(6486002)(316002)(6666004)(4326008)(186003)(66476007)(66556008)(66946007)(8676002)(478600001)(41300700001)(86362001)(5660300002)(38100700002)(2906002)(83380400001)(36756003)(2616005)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2r/K4ryyMCUGiYY1hebSMFM3wkxklHpVNpqdTPa3XCQ8o6nDvit+DLLUtr3StfEZ+BXbOIE3GZUcI7aMZ81i2th0X1F+ku1J9mzElUi0DC+CJTQfZA/wdIICYZeZpr7xovxNKu4Gw5graioynwJFQMor7zZXZdVwdbeg6oADl5fwnGapnuY1ekppziCg6tRXUM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wLucXwhvhjBHGMprMzYWdRTbTncVwiE9PbKC/Mlf7KIEOcw/4MrLVhZAI+XIQA6TMWDEsPS/VaXOlsP7mh2dkSrQaO8AfhYiY4qciH8uW4c2/NVsjgv3GCioUmAuCKy326js5JLAIYpMYihzNRbxw1wrcuO8SJKzgwhUPODFsOCa7r2eTotYF6qBFYyLRyyGmlFPp+oRitor2A94+MfugUkFrAQE+OVuL0Kyqln5MOs34ZkqIaesr68lKIwQ+ApzylhStHzqBILcBK5Wf6k0uCqyfffTS21EWJwEmR0Mmzo5KlnE125kM8pi9eajAJ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2b8cad41-6fdf-4b63-f92c-08db2ef26bb2 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2023 18:38:12.8630 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jJNVv0bSDJ3PTa9JLooq9cRRFyNDiMfkeJG0Rjx6ZPYmYm3FSnL+WdStjF5sonun X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB9008 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Test the basic flow. Reviewed-by: Kevin Tian Signed-off-by: Jason Gunthorpe --- tools/testing/selftests/iommu/iommufd.c | 15 +++++++++++++ .../selftests/iommu/iommufd_fail_nth.c | 11 +++++++++- tools/testing/selftests/iommu/iommufd_utils.h | 21 +++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index 83c98a371f9e7a..c07252dbf62d72 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -1307,6 +1307,21 @@ TEST_F(iommufd_mock_domain, replace) test_ioctl_destroy(ioas_id); } +TEST_F(iommufd_mock_domain, alloc_hwpt) +{ + int i; + + for (i = 0; i != variant->mock_domains; i++) { + uint32_t stddev_id; + uint32_t hwpt_id; + + test_cmd_hwpt_alloc(self->idev_ids[0], self->ioas_id, &hwpt_id); + test_cmd_mock_domain(hwpt_id, &stddev_id, NULL, NULL); + test_ioctl_destroy(stddev_id); + test_ioctl_destroy(hwpt_id); + } +} + /* VFIO compatibility IOCTLs */ TEST_F(iommufd, simple_ioctls) diff --git a/tools/testing/selftests/iommu/iommufd_fail_nth.c b/tools/testing/selftests/iommu/iommufd_fail_nth.c index 7a3d149019da92..7e1afb6ff9bd8d 100644 --- a/tools/testing/selftests/iommu/iommufd_fail_nth.c +++ b/tools/testing/selftests/iommu/iommufd_fail_nth.c @@ -577,6 +577,8 @@ TEST_FAIL_NTH(basic_fail_nth, device) uint32_t ioas_id; uint32_t ioas_id2; uint32_t stdev_id; + uint32_t idev_id; + uint32_t hwpt_id; self->fd = open("/dev/iommu", O_RDWR); if (self->fd == -1) @@ -590,11 +592,18 @@ TEST_FAIL_NTH(basic_fail_nth, device) fail_nth_enable(); - if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, NULL, NULL)) + if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, NULL, + &idev_id)) + return -1; + + if (_test_cmd_hwpt_alloc(self->fd, idev_id, ioas_id, &hwpt_id)) return -1; if (_test_cmd_mock_domain_replace(self->fd, stdev_id, ioas_id2, NULL)) return -1; + + if (_test_cmd_mock_domain_replace(self->fd, stdev_id, hwpt_id, NULL)) + return -1; return 0; } diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h index e67a929a5c87d3..9b6dcb921750b6 100644 --- a/tools/testing/selftests/iommu/iommufd_utils.h +++ b/tools/testing/selftests/iommu/iommufd_utils.h @@ -96,6 +96,27 @@ static int _test_cmd_mock_domain_replace(int fd, __u32 stdev_id, __u32 pt_id, EXPECT_ERRNO(_errno, _test_cmd_mock_domain_replace(self->fd, stdev_id, \ pt_id, NULL)) +static int _test_cmd_hwpt_alloc(int fd, __u32 device_id, __u32 pt_id, + __u32 *hwpt_id) +{ + struct iommu_hwpt_alloc cmd = { + .size = sizeof(cmd), + .dev_id = device_id, + .pt_id = pt_id, + }; + int ret; + + ret = ioctl(fd, IOMMU_HWPT_ALLOC, &cmd); + if (ret) + return ret; + if (hwpt_id) + *hwpt_id = cmd.out_hwpt_id; + return 0; +} + +#define test_cmd_hwpt_alloc(device_id, pt_id, hwpt_id) \ + ASSERT_EQ(0, _test_cmd_hwpt_alloc(self->fd, device_id, pt_id, hwpt_id)) + static int _test_cmd_create_access(int fd, unsigned int ioas_id, __u32 *access_id, unsigned int flags) {