From patchwork Thu Jul 27 20:24:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 127181 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp12704vqg; Thu, 27 Jul 2023 14:07:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlFnmiY+OV8aeKtN0T5I2r0p/rJ/ZMIqrKXSuEprYwrlVXjuuTxZKf4zmqD4kq8x248wDKsi X-Received: by 2002:a17:902:d4c7:b0:1b8:948b:41b6 with SMTP id o7-20020a170902d4c700b001b8948b41b6mr4948998plg.10.1690492063991; Thu, 27 Jul 2023 14:07:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1690492063; cv=pass; d=google.com; s=arc-20160816; b=w69qP43k0DJhW0Iye8EN+RqYkVg4p7Trba6hQBGKNSja/+OggD8Ev5wDGvRrI0c6Wp ZhXA07UauWiSyF9MOjLbNBOt2GpyTYLMHU7ve2DJtmKJqNq+hImOoo1jk0Jbmk+D+iPr LrypPU3IcJBWLTKfHqLIShaftyZPFMNEXxpTu4imRJPKR5V+ZvCeGcT/f7O5KGnASFz1 givAaDAXH2eMuUy06Md0eJudpnv56PBX4rwwxFdFd5iIMn8UuuzJRMLyzlFMSDdBU2Rk XZnDn4jNPlYITXUoLSWI34OBzgOLarAaoxqRXOs4bnPKUFhtIe29ipbkuUsMLPx6ptJt lOGA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iirMKJG1l4d932PYYOqkXDT5WydmhkNOrAq8wo1jKiw=; fh=qC2Tv3KKwVGixY6WZei9zODHRrUJaQPqzd5TxSwHSnU=; b=K1Oz/3vQ9u93nGAFopColOEgORfsfRogQVHtOlwk2bZByw7o9Asb2Su9nTgdaHKv0t 6yP1q+S0NKFbi2wITLGs7gCG15JZfz03tc+ivQ9p8nd+mVxsiqJ5Eqw5MxkX6R4L1+Sg YoFxyuiD/DEAv4ThmjasukPwes8DydnsQWwrUQlv88CrxQzXvFHaItFE/cAbTyUNIf0z XaAH8blsHubBnfBKSHPRanFO7VWn6bJ6lRgdyVEQysgvlqr48hgMLygt7mSUMgoom6q0 ryMMACAtiv1d9kHzZPMg0dQQf5P+0M47kjruMrY672+VwN9RwHGH0uk75JEV4+2ifK5w o1Kg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=Z1cR3amk; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y8-20020a17090264c800b001bb8a8dbd21si1781403pli.242.2023.07.27.14.07.31; Thu, 27 Jul 2023 14:07:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=Z1cR3amk; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232135AbjG0UZf (ORCPT + 99 others); Thu, 27 Jul 2023 16:25:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232876AbjG0UZP (ORCPT ); Thu, 27 Jul 2023 16:25:15 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2058.outbound.protection.outlook.com [40.107.223.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A03CA272B; Thu, 27 Jul 2023 13:25:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DPF5sqpb22dKdpxENRpC02m+Igw8vufEhQ/XFw1myT6n0eVoBiVyZiVFG+Q4XYCklGX+gIiUHf/qARbCRJvw8Ix2Nt8dBKBF/wgMUKpwfDlTmfEi/neOIq9wWb6WAznm0QgTwhVAbIEuHDO58F8cMxFNwbrNv+mo0uiTMjm+miLaIrGVJMLg26vu1N+QPU91CAAoXj9BHBXNAdKtKNfOaj9dfHM5mfYEIJFCh9+hfUCz2Xbwsek4PADLCZfBfZMAVBdv8d5cW3A3qT9oumCi09BKvxjuF3NBU+9KcdrfYX95IiFMgv5nU8lmBHYGGTCvcGdTZtw20rdZ2t0Rq135hw== 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=iirMKJG1l4d932PYYOqkXDT5WydmhkNOrAq8wo1jKiw=; b=iylr+L2BQ6OPiFQet+S0TG/jIct4vRZpolc7VnXVhRWrm4Nv+GFZ2p1I0x6r2AHDB/RE18KRLNCZNYn0gBU3bKV8Vp0qwNZ7uF8ba0Sa5U0UtyaV3HmSeH/M7FLUvbnjImScilbrAqFrQ0ZY43egUQAIg/jWcPuxsGq8RVaZFgOm0AAnGzvgediY5VsdBqsSD+Ll+m7DIRzTxfaqgKd/BwLNjzxTW9PdVG5oaXUkxXX1OzxbjUapigVItWqWSwVeAteGz2d95Fe02ghhTa4IbQZUDFr8PJiZLyHAtW+OfxuYZLaC0c0wLFmwoSXXZcFGpae/GEs1FwF0mi66gX9XTQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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 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=iirMKJG1l4d932PYYOqkXDT5WydmhkNOrAq8wo1jKiw=; b=Z1cR3amkolnLfSct5VMX4zqZkBMu+1RRqQ3stU8Fs88NBYUpAzAxtGoTj/WtRHm9SvzscmpzxW0udPonkl6oSn/cRKtYVPEbTvcqQJn2Xj0BUxeuAE4/R7eNCGx4mcyTymrSIpa27QbIG8LloWuFB7mMGx4O/hjo6fVM4M0PBZHhQ5zWhx7KXiY5mvvQbytbDUaJYWWR2o5khTUkM68iCAj5myXVL4hDqRX1j6KW2G+5l7oIeD7726FeN+WIIBVlceLSu6IguhLIfT2ciqjJWlJr30VWihCDSkm0HFlWMEmYJInREq1r7XmhWpDEYzcKSOQWEoB9pgF37wxfmmJiLw== Received: from DM6PR02CA0072.namprd02.prod.outlook.com (2603:10b6:5:177::49) by LV8PR12MB9136.namprd12.prod.outlook.com (2603:10b6:408:18e::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Thu, 27 Jul 2023 20:25:10 +0000 Received: from DM6NAM11FT099.eop-nam11.prod.protection.outlook.com (2603:10b6:5:177:cafe::1) by DM6PR02CA0072.outlook.office365.com (2603:10b6:5:177::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29 via Frontend Transport; Thu, 27 Jul 2023 20:25:10 +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 DM6NAM11FT099.mail.protection.outlook.com (10.13.172.241) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29 via Frontend Transport; Thu, 27 Jul 2023 20:25:10 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) 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.986.5; Thu, 27 Jul 2023 13:24:53 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Thu, 27 Jul 2023 13:24:53 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.13) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Thu, 27 Jul 2023 13:24:52 -0700 From: Nicolin Chen To: , CC: , , , , , , , , , , , Subject: [PATCH v10 5/6] iommufd/selftest: Add IOMMU_TEST_OP_ACCESS_REPLACE_IOAS coverage Date: Thu, 27 Jul 2023 13:24:36 -0700 Message-ID: <0a70ac96e5d10d090b16f4aad5da40dfd83af6ad.1690488745.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT099:EE_|LV8PR12MB9136:EE_ X-MS-Office365-Filtering-Correlation-Id: a0820bc2-e5f9-482b-a13f-08db8edf935c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nPf2jkBleH6kA0z0KzkXwL0fIhFQj6xJI+TRSkrKluYHNclGXKH1DczgwiwEtUeECp6tEJGypg9Qp5ia+q6R5+m7bsR/xb81TNmjcazs1M615GHUlMAgbkSgVXWvzqYRTWwcalKGuvSsu/NMpUjfb81DWmkbRrAJqzNeKyG7sl9rSEiO98C7dVNX1HjexYHWBh+uWF8QqkNGnHTBBhduB7yqX2dgTMHQ/QVb22OhpiKGA3RUEPQefb86DVHmP7MSsKIugH6W/ZzlmPV64biA0j3w13B26TLLEOf5tgIIubGBDSs+l+2klLMEeRpEWDJkGILH4+sEInsukCU+jE4lL9Mxrp5RNiFM6+X4WwqVO2jZJsQJ1sq481Xgk7VCjn3OM8kFIITMQzX2tkbGCu5HC6Axq/kmghisAtdPkI4Af9BAevaXYnqqEEK96wkWSq6WxtrKlGgkbp+3EEB5pQYJQ8VMjHpSY6ZueovEucq52oA2ET8STVLPCSM8r7pJjcnn+eWzbbPG+Ijz5Pbdr3ZZRFdl3Z4GMDAhYGT8qahl8fRilxsPBcA+urFuOVg7v4rCm6vFUs/tMkVfXFWvi/UpUjbcqET90Ee06OuaiAbeZ6EUizluNfX/SWdlVC9eSzJiZ8gqZ/yK9pU9QSzz7OU1ZKr15N8Ok2O8sXbZa95XdjBt/Cjs+wKmWxm/UEjYBqzJ1baXDl4DCyEFPyJ5ja8swiKUc65oDxTfkGUiC0zZ+yU= 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:(13230028)(4636009)(376002)(136003)(346002)(39860400002)(396003)(82310400008)(451199021)(46966006)(36840700001)(40470700004)(2906002)(336012)(26005)(186003)(316002)(7636003)(356005)(36860700001)(70586007)(2616005)(426003)(40480700001)(83380400001)(5660300002)(41300700001)(47076005)(70206006)(40460700003)(8676002)(7416002)(110136005)(36756003)(8936002)(4326008)(82740400003)(54906003)(6666004)(478600001)(7696005)(86362001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2023 20:25:10.2823 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a0820bc2-e5f9-482b-a13f-08db8edf935c 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: DM6NAM11FT099.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9136 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772609406344518590 X-GMAIL-MSGID: 1772609406344518590 Add a new IOMMU_TEST_OP_ACCESS_REPLACE_IOAS to allow replacing the access->ioas, corresponding to the iommufd_access_replace() helper. Then add a replace coverage as a part of user_copy test case, which basically repeats the copy test after replacing the old ioas with a new one. Reviewed-by: Kevin Tian Reviewed-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_test.h | 4 +++ drivers/iommu/iommufd/selftest.c | 19 ++++++++++++ tools/testing/selftests/iommu/iommufd.c | 29 +++++++++++++++++-- tools/testing/selftests/iommu/iommufd_utils.h | 19 ++++++++++++ 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/iommufd/iommufd_test.h b/drivers/iommu/iommufd/iommufd_test.h index dd9168a20ddf..258de2253b61 100644 --- a/drivers/iommu/iommufd/iommufd_test.h +++ b/drivers/iommu/iommufd/iommufd_test.h @@ -18,6 +18,7 @@ enum { IOMMU_TEST_OP_ACCESS_RW, IOMMU_TEST_OP_SET_TEMP_MEMORY_LIMIT, IOMMU_TEST_OP_MOCK_DOMAIN_REPLACE, + IOMMU_TEST_OP_ACCESS_REPLACE_IOAS, }; enum { @@ -91,6 +92,9 @@ struct iommu_test_cmd { struct { __u32 limit; } memory_limit; + struct { + __u32 ioas_id; + } access_replace_ioas; }; __u32 last; }; diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index 9d43334e4faf..bb2cd54ca7b6 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -785,6 +785,22 @@ static int iommufd_test_create_access(struct iommufd_ucmd *ucmd, return rc; } +static int iommufd_test_access_replace_ioas(struct iommufd_ucmd *ucmd, + unsigned int access_id, + unsigned int ioas_id) +{ + struct selftest_access *staccess; + int rc; + + staccess = iommufd_access_get(access_id); + if (IS_ERR(staccess)) + return PTR_ERR(staccess); + + rc = iommufd_access_replace(staccess->access, ioas_id); + fput(staccess->file); + return rc; +} + /* Check that the pages in a page array match the pages in the user VA */ static int iommufd_test_check_pages(void __user *uptr, struct page **pages, size_t npages) @@ -1000,6 +1016,9 @@ int iommufd_test(struct iommufd_ucmd *ucmd) case IOMMU_TEST_OP_CREATE_ACCESS: return iommufd_test_create_access(ucmd, cmd->id, cmd->create_access.flags); + case IOMMU_TEST_OP_ACCESS_REPLACE_IOAS: + return iommufd_test_access_replace_ioas( + ucmd, cmd->id, cmd->access_replace_ioas.ioas_id); case IOMMU_TEST_OP_ACCESS_PAGES: return iommufd_test_access_pages( ucmd, cmd->id, cmd->access_pages.iova, diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index dc09c1de319f..8acd0af37aa5 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -1283,7 +1283,13 @@ TEST_F(iommufd_mock_domain, user_copy) .dst_iova = MOCK_APERTURE_START, .length = BUFFER_SIZE, }; - unsigned int ioas_id; + struct iommu_ioas_unmap unmap_cmd = { + .size = sizeof(unmap_cmd), + .ioas_id = self->ioas_id, + .iova = MOCK_APERTURE_START, + .length = BUFFER_SIZE, + }; + unsigned int new_ioas_id, ioas_id; /* Pin the pages in an IOAS with no domains then copy to an IOAS with domains */ test_ioctl_ioas_alloc(&ioas_id); @@ -1301,11 +1307,30 @@ TEST_F(iommufd_mock_domain, user_copy) ASSERT_EQ(0, ioctl(self->fd, IOMMU_IOAS_COPY, ©_cmd)); check_mock_iova(buffer, MOCK_APERTURE_START, BUFFER_SIZE); + /* Now replace the ioas with a new one */ + test_ioctl_ioas_alloc(&new_ioas_id); + test_ioctl_ioas_map_id(new_ioas_id, buffer, BUFFER_SIZE, + ©_cmd.src_iova); + test_cmd_access_replace_ioas(access_cmd.id, new_ioas_id); + + /* Destroy the old ioas and cleanup copied mapping */ + ASSERT_EQ(0, ioctl(self->fd, IOMMU_IOAS_UNMAP, &unmap_cmd)); + test_ioctl_destroy(ioas_id); + + /* Then run the same test again with the new ioas */ + access_cmd.access_pages.iova = copy_cmd.src_iova; + ASSERT_EQ(0, + ioctl(self->fd, _IOMMU_TEST_CMD(IOMMU_TEST_OP_ACCESS_PAGES), + &access_cmd)); + copy_cmd.src_ioas_id = new_ioas_id; + ASSERT_EQ(0, ioctl(self->fd, IOMMU_IOAS_COPY, ©_cmd)); + check_mock_iova(buffer, MOCK_APERTURE_START, BUFFER_SIZE); + test_cmd_destroy_access_pages( access_cmd.id, access_cmd.access_pages.out_access_pages_id); test_cmd_destroy_access(access_cmd.id); - test_ioctl_destroy(ioas_id); + test_ioctl_destroy(new_ioas_id); } TEST_F(iommufd_mock_domain, replace) diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h index 53b4d3f2d9fc..70353e68e599 100644 --- a/tools/testing/selftests/iommu/iommufd_utils.h +++ b/tools/testing/selftests/iommu/iommufd_utils.h @@ -119,6 +119,25 @@ static int _test_cmd_hwpt_alloc(int fd, __u32 device_id, __u32 pt_id, #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_access_replace_ioas(int fd, __u32 access_id, + unsigned int ioas_id) +{ + struct iommu_test_cmd cmd = { + .size = sizeof(cmd), + .op = IOMMU_TEST_OP_ACCESS_REPLACE_IOAS, + .id = access_id, + .access_replace_ioas = { .ioas_id = ioas_id }, + }; + int ret; + + ret = ioctl(fd, IOMMU_TEST_CMD, &cmd); + if (ret) + return ret; + return 0; +} +#define test_cmd_access_replace_ioas(access_id, ioas_id) \ + ASSERT_EQ(0, _test_cmd_access_replace_ioas(self->fd, access_id, ioas_id)) + static int _test_cmd_create_access(int fd, unsigned int ioas_id, __u32 *access_id, unsigned int flags) {