From patchwork Wed Mar 8 14:25:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13165914 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 86FD8C64EC4 for ; Wed, 8 Mar 2023 14:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231182AbjCHO0f (ORCPT ); Wed, 8 Mar 2023 09:26:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230013AbjCHO0e (ORCPT ); Wed, 8 Mar 2023 09:26:34 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2073.outbound.protection.outlook.com [40.107.93.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F7C4C3E27; Wed, 8 Mar 2023 06:26:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=egKeappAzFlWeDily9eQoWgpw0DTjAtw23trBMh1HGayc4HHu+J1TbQv3R9OId9QqXd+zHxktm5cYmt/Dmt6jw6JlXQ82D4ogdUsnBXJxALf82EH6o5o06DPBPnY3PYbtn1fgn0skV8f170bzFT2D0sjjwewxg3rXUpjriiLcdEF2wntziTeHEso2a+JjQB/Nj4XmBbccC92D41QqZpYZvRki0hynMvQ6DwItUIuJfglaki31Y/f5ghG+pT6yC/81AdWfAIt3ittc8iodKLxt1mR0IyT9WqvoGKwNlBjLmOLTLqou92/h18VdEyCbKHypVXIHhvKnjbGdLFGK3hkrg== 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=Ss/5/RsG79O6QZhht0gvrXJr/7k9FG5EPgRft3KsyRk=; b=mPoTWNkG9k4aTIVwH0J4j1/Tgjc4r2Y4EBKTMCMG4vSxq+TdnL+GyP2Pb8czCvtw1zhDGntUFfWZa65aFNr3HLsyS3nF/p4kbuVQkbJrjyiWOfqTAyVPoUSOq+hJZYWm4LsrKkvWhMtJR6WJRQYvEQwjFuekBbiCSbBGWblsaH9g3yiO+Zslq4o8EdFCTj33BHjMzlhqLzQJpiwRD4juTH6VGulm/gJa0ELLjeFgQ/0WN9iKvGxgMigeW1w7Jcdhi8jfMfNRZypOUzmmk+Flypv0qlhNSNTvjjA/a6iWe3TvRDSHbegDym08VmYF2JrNecDXSjOs9AxCbx4n8DG6FA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) 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=Ss/5/RsG79O6QZhht0gvrXJr/7k9FG5EPgRft3KsyRk=; b=X5MuPW7cDVe+hW+ZT4OzrNG7srm5HhtgZFlezsyep1QJU8u5qenelep9Ij5snIYYucK6hkFwauE3UBO2ZGkltiFV+s7vLit5MZ3hqNoeXS3vE38tzvhBffrCvP4FSAlCo77MWjLso0D1S3LFWL2Y5UVXcsKIdBBJbOY8oC/7JQUp4Ux3tPTvCiqXBNnAOoKCmJQlZc/HwR3QGFugJmTs4MaGlv9xpDVgZp0/q9hLmDJtVEa2PoRUJ1w5it+YiwFawYjHNS63sd+7LqlPnu2FfLox3H2u7F9dI1tI22M8/0oVPwhQXwW62AY75RIf0Kvgk/Oes7NahUqcaAw8mt9szw== Received: from BN9PR03CA0736.namprd03.prod.outlook.com (2603:10b6:408:110::21) by DS0PR12MB8574.namprd12.prod.outlook.com (2603:10b6:8:166::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.29; Wed, 8 Mar 2023 14:26:28 +0000 Received: from BN8NAM11FT072.eop-nam11.prod.protection.outlook.com (2603:10b6:408:110:cafe::12) by BN9PR03CA0736.outlook.office365.com (2603:10b6:408:110::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.17 via Frontend Transport; Wed, 8 Mar 2023 14:26:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by BN8NAM11FT072.mail.protection.outlook.com (10.13.176.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.18 via Frontend Transport; Wed, 8 Mar 2023 14:26:28 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Wed, 8 Mar 2023 06:26:20 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) 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.986.37; Wed, 8 Mar 2023 06:26:19 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.5 via Frontend Transport; Wed, 8 Mar 2023 06:26:19 -0800 From: Nicolin Chen To: , , , , , , CC: , , , , , , Subject: [PATCH v4 1/5] vfio: Do not allow !ops->dma_unmap in vfio_pin/unpin_pages() Date: Wed, 8 Mar 2023 06:25:58 -0800 Message-ID: <2dc87ceb7bf02c7f405bde44e9ee9b21398c5228.1678284812.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT072:EE_|DS0PR12MB8574:EE_ X-MS-Office365-Filtering-Correlation-Id: e1f17bc5-39a1-4f32-f53f-08db1fe11afa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yguxdC/5yU068tLy30R/cpalEtay4fQozNcLFmxT9x3zkcH4JRzOlvJ6hAojYeUZ/Pxu7zxNulIQ9iGpkLV8dVpubvz5U+oQCRpB6tBAu6CVdSPIO237pkOYc6JYTpDheBkx82Kjst4ObaYrMmjkMzn+N1oofQ7jkYm705A/Q0mMiauviF19O/JOnAas19/iVO6dH1w0Dmk6iOiUL+i4YX7e3c3pEIX0jriBzBj4JsICkFK3v7GpePZdEj1/H2SgK0Oes4uTtwBvE6AKhOx5F7PO33RFIHe+E6q0H74cHcHVSCvw/O/6Or8MAX3IoXvwUMH3gs+l381bT9VCa4Vt09An/gJQcfXxUw8eeAnzJx+z///zIrlRBRCsFoXGXWZSffWIpSNh8cGnTbLPJw717h/gLjdlID8QTCQz/VSaNzBuP3AzTFBYJU8xE5VPMz03jZMRwf+NP8Omm7iY5VE7U7B3dNFaTqnjK21WD+I39knoOQMZIksadjlNLKkcjpfzdLrQG7IShdsKW1YNUU67vK3huIMlfLuPCi9ppJnDsBXLgWuusWbXJE7ytgEm3ojtPsrECiAk6ERdoQQVv91dCkS2w1FU9LcOssoKcufYoX2K2KIFiQPBxzb1JMn1780ppAiBFcokTAnawVrgn1YVhkGcQELpjxJmJhuxYP0us+V8IVjw4X0AN9MORMVlEAKaagMgXh5avRclUFAOCETm4Q== X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230025)(4636009)(376002)(346002)(136003)(396003)(39860400002)(451199018)(46966006)(40470700004)(36840700001)(36756003)(40460700003)(54906003)(316002)(110136005)(186003)(478600001)(8936002)(7416002)(7696005)(5660300002)(40480700001)(2906002)(70586007)(6666004)(70206006)(8676002)(4326008)(41300700001)(356005)(7636003)(82740400003)(86362001)(36860700001)(2616005)(83380400001)(26005)(82310400005)(47076005)(426003)(336012);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2023 14:26:28.1939 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e1f17bc5-39a1-4f32-f53f-08db1fe11afa 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.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT072.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8574 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org A driver that doesn't implement ops->dma_unmap shouldn't be allowed to do vfio_pin/unpin_pages(), though it can use vfio_dma_rw() to access an iova range. Deny !ops->dma_unmap cases in vfio_pin/unpin_pages(). Suggested-by: Kevin Tian Reviewed-by: Kevin Tian Reviewed-by: Yi Liu Signed-off-by: Nicolin Chen Reviewed-by: Jason Gunthorpe --- drivers/vfio/vfio_main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index e5f4738692ac..32ea7cea1236 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -1522,6 +1522,8 @@ int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova, /* group->container cannot change while a vfio device is open */ if (!pages || !npage || WARN_ON(!vfio_assert_device_open(device))) return -EINVAL; + if (!device->ops->dma_unmap) + return -EINVAL; if (vfio_device_has_container(device)) return vfio_device_container_pin_pages(device, iova, npage, prot, pages); @@ -1559,6 +1561,8 @@ void vfio_unpin_pages(struct vfio_device *device, dma_addr_t iova, int npage) { if (WARN_ON(!vfio_assert_device_open(device))) return; + if (WARN_ON(!device->ops->dma_unmap)) + return; if (vfio_device_has_container(device)) { vfio_device_container_unpin_pages(device, iova, npage); From patchwork Wed Mar 8 14:25:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13165917 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 1689BC64EC4 for ; Wed, 8 Mar 2023 14:26:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231615AbjCHO0n (ORCPT ); Wed, 8 Mar 2023 09:26:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231474AbjCHO0i (ORCPT ); Wed, 8 Mar 2023 09:26:38 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2067.outbound.protection.outlook.com [40.107.237.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D89FC5607; Wed, 8 Mar 2023 06:26:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PNlLMHuRpJxqw1jKc91VGxlaO37n9XLzaorOutcNUYa2p78/EgU68vjmCsVd6XcBtCKMHFY4xZSkxuoWNKlpVmMiMc9kyEPGEJfLaZI++ohmikVVO3CPvgM9z5GMvEzUY54xfUf0EbZyYuFPwQK6fAl+W7s35ECo/wVIKc4SUS4EWAssdspnSNYoWVhNtdm0XcSTbGs3zgFhSfz6pnE4cmr7RDLmIaZR5Co7JAE7J5+X/Cr0mJybhqpOgtl3orVZoY6J4KuWwiwxvno602upzUwOzUApZurcXg3OvbeKk53NXhqa5NOegIrVxezK/4YDjhlc2RC44DesVk8W9p0DKw== 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=NzbPeHexKIf3PE+bJGFCFDeSpY8S/7mrVS5Vct/ECOE=; b=V3LMYf4dNG869loRKQnAsv1GTqCgVBwsVnIR9bNJs+tm4TRUMF5tAxPNN7TVj5q8Ky99aas8W/LmjCozJwnEdToPCS16ARBzuCDpgiloVaWcRsX2ctwXBAuBhgFkmOAQY9AlJxiRT/azZE9lbduasM6l+BKZfL38JypCWtOpOA64yZug+vli4fjeHIjXODzflMEwBjaPITDX2eDv9BE0jgrv97z0FXZqxODT0kvzsGPK5ooXmUPNwMDnKPkD6oSUqUm5/Up8vs7Gv3PI4nSxyqPdHrbWnMxSF4STtxbX8GPtkmBkxob7bvM62+p7KGDxVMEDNFYu2P1+mru3tZqLxQ== 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 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=NzbPeHexKIf3PE+bJGFCFDeSpY8S/7mrVS5Vct/ECOE=; b=E2Af0WqfcrGSqc+evPt3KnFGJ/hH31Qyji2fFEMW81MvU1V9xuooYP9jRpsQ4dkYhtuDLBmY6p/a3/9Irl5O8JWMz5P8j1KUK4NtjJFjY5LTcPcroPwIh/t+wf7uBxE+1ulwkJtAMSyj0PtPZleSaXWqsfi0CAn7VsVi3ZHh92UQYoF6jYjk3nPAhY8rUvBvF5r9AZkWMYTVl2yO3+nthV0LVj6OpClQ/dTRhiMZnNYtK62+QGSjz1mXxaitNY+NLJVdsdOpAeqdPsv2fHRuBS+B4t8cgs7/pE5Mh14NJ01M99dbZ1fJY78bOwEQ5PW7O1v/wtC5qeIXH18p+p1W+A== Received: from BN9PR03CA0365.namprd03.prod.outlook.com (2603:10b6:408:f7::10) by PH7PR12MB7844.namprd12.prod.outlook.com (2603:10b6:510:27b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.28; Wed, 8 Mar 2023 14:26:32 +0000 Received: from BN8NAM11FT019.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f7:cafe::19) by BN9PR03CA0365.outlook.office365.com (2603:10b6:408:f7::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.18 via Frontend Transport; Wed, 8 Mar 2023 14:26:32 +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 BN8NAM11FT019.mail.protection.outlook.com (10.13.176.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.19 via Frontend Transport; Wed, 8 Mar 2023 14:26:32 +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.986.5; Wed, 8 Mar 2023 06:26:21 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) 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.986.37; Wed, 8 Mar 2023 06:26:21 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.5 via Frontend Transport; Wed, 8 Mar 2023 06:26:20 -0800 From: Nicolin Chen To: , , , , , , CC: , , , , , , Subject: [PATCH v4 2/5] iommufd/selftest: Add IOMMU_TEST_OP_ACCESS_SET_IOAS coverage Date: Wed, 8 Mar 2023 06:25:59 -0800 Message-ID: <08a875b83daf7047c3cc67ed0da23045b6dc6fb9.1678284812.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT019:EE_|PH7PR12MB7844:EE_ X-MS-Office365-Filtering-Correlation-Id: 5c5611f9-f536-474e-a869-08db1fe11d9b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AohzTo6cZ+bS2wujbT7IXhMTHz/TB5dX1GQFjQ+CV/FX2FmhH7j7t8YsjuuHx7Ago5GwSJjW4oMj4Mot9VW02X7IxJMuLpoFwS2Y7cbjwqEp8+NX+1WKtkiKb+VH1U27JbjIgHdtG6Q7v4/g7VXgMf8nI2DDmBcJYfkylklY6qHMUBTgZ5Jx4+KlqjPaeSyRljnziqWBsLR9bjGsgLd91BxZoxyYMO0q9VKVD4YjbMLD7icNDNFxJYCCQ1nA4ne3cZwCvEJ8+prxOuFGheGE8J4xMBJysMgGiM0p88oJrxAiEVrEZLf9mZ5+RfAyjdEKLq4wsixJxYG+RD0A3ZKLSqtm327NUjjARwMkJcdO8VMOJe6QoGxG0p8QUyCHE/ZeGegJ4wCYCGzFvj2U+Fhn2QmhCO+Shqdv9k53bA0QlyBW6SwWt0tJB7I0ijts7+gxBlRvnX6aVbdI7iz2vJ5acfbizPIo7pecWKVOlUlnNwndJoNj7eyxTP/Ty0ivoazxMSxDxirOARgi9x5UojiKPq5KhR9XxoBXhLDyTPVhOvMfzriIIicjSKJ86aTT8f6ej/EOuzJ6YRHkrrn1nzl2VkVyUv9lZjFXEiEX/Jgc+isJs51r2iukQ7UPj18zOMqnlDlOodhNcPrPQWCaCgbsqN8BeBjcbdb+gAvZbxMsBci+1/iIW5q93XqvjCFQBNr9xjVLM20AbXS5SI/lQcuQhA== 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:(13230025)(4636009)(136003)(396003)(39860400002)(376002)(346002)(451199018)(36840700001)(40470700004)(46966006)(36860700001)(6666004)(36756003)(426003)(47076005)(86362001)(40460700003)(82310400005)(83380400001)(82740400003)(40480700001)(336012)(186003)(26005)(2616005)(7636003)(356005)(41300700001)(70206006)(70586007)(4326008)(8676002)(2906002)(8936002)(7416002)(5660300002)(7696005)(316002)(110136005)(54906003)(478600001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2023 14:26:32.6025 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5c5611f9-f536-474e-a869-08db1fe11d9b 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: BN8NAM11FT019.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7844 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add a new IOMMU_TEST_OP_ACCESS_SET_IOAS to allow setting access->ioas individually, corresponding to the iommufd_access_set_ioas() helper. Reviewed-by: Kevin Tian Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_test.h | 4 +++ drivers/iommu/iommufd/selftest.c | 26 +++++++++++++++---- tools/testing/selftests/iommu/iommufd_utils.h | 22 ++++++++++++++-- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/iommufd/iommufd_test.h b/drivers/iommu/iommufd/iommufd_test.h index dd9168a20ddf..da1898a9128f 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_SET_IOAS, }; enum { @@ -91,6 +92,9 @@ struct iommu_test_cmd { struct { __u32 limit; } memory_limit; + struct { + __u32 ioas_id; + } access_set_ioas; }; __u32 last; }; diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index 60f21bb3f3d4..d7832ffc3aa6 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -732,7 +732,7 @@ static struct selftest_access *iommufd_test_alloc_access(void) } static int iommufd_test_create_access(struct iommufd_ucmd *ucmd, - unsigned int ioas_id, unsigned int flags) + unsigned int flags) { struct iommu_test_cmd *cmd = ucmd->cmd; struct selftest_access *staccess; @@ -764,9 +764,6 @@ static int iommufd_test_create_access(struct iommufd_ucmd *ucmd, rc = PTR_ERR(access); goto out_put_fdno; } - rc = iommufd_access_set_ioas(access, ioas_id); - if (rc) - goto out_destroy; cmd->create_access.out_access_fd = fdno; rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd)); if (rc) @@ -785,6 +782,22 @@ static int iommufd_test_create_access(struct iommufd_ucmd *ucmd, return rc; } +static int iommufd_test_access_set_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_set_ioas(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) @@ -998,8 +1011,11 @@ int iommufd_test(struct iommufd_ucmd *ucmd) ucmd, u64_to_user_ptr(cmd->check_refs.uptr), cmd->check_refs.length, cmd->check_refs.refs); case IOMMU_TEST_OP_CREATE_ACCESS: - return iommufd_test_create_access(ucmd, cmd->id, + return iommufd_test_create_access(ucmd, cmd->create_access.flags); + case IOMMU_TEST_OP_ACCESS_SET_IOAS: + return iommufd_test_access_set_ioas( + ucmd, cmd->id, cmd->access_set_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_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h index 9b6dcb921750..399779acce23 100644 --- a/tools/testing/selftests/iommu/iommufd_utils.h +++ b/tools/testing/selftests/iommu/iommufd_utils.h @@ -117,13 +117,31 @@ 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_set_ioas(int fd, __u32 access_id, + unsigned int ioas_id) +{ + struct iommu_test_cmd cmd = { + .size = sizeof(cmd), + .op = IOMMU_TEST_OP_ACCESS_SET_IOAS, + .id = access_id, + .access_set_ioas = { .ioas_id = ioas_id }, + }; + int ret; + + ret = ioctl(fd, IOMMU_TEST_CMD, &cmd); + if (ret) + return ret; + return 0; +} +#define test_cmd_access_set_ioas(access_id, ioas_id) \ + ASSERT_EQ(0, _test_cmd_access_set_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) { struct iommu_test_cmd cmd = { .size = sizeof(cmd), .op = IOMMU_TEST_OP_CREATE_ACCESS, - .id = ioas_id, .create_access = { .flags = flags }, }; int ret; @@ -132,7 +150,7 @@ static int _test_cmd_create_access(int fd, unsigned int ioas_id, if (ret) return ret; *access_id = cmd.create_access.out_access_fd; - return 0; + return _test_cmd_access_set_ioas(fd, *access_id, ioas_id); } #define test_cmd_create_access(ioas_id, access_id, flags) \ ASSERT_EQ(0, _test_cmd_create_access(self->fd, ioas_id, access_id, \ From patchwork Wed Mar 8 14:26:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13165915 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 E3CB4C74A44 for ; Wed, 8 Mar 2023 14:26:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231465AbjCHO0i (ORCPT ); Wed, 8 Mar 2023 09:26:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231402AbjCHO0g (ORCPT ); Wed, 8 Mar 2023 09:26:36 -0500 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2068.outbound.protection.outlook.com [40.107.100.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02A37C5604; Wed, 8 Mar 2023 06:26:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FfiPXlNWio6I1JkEO95ungASUprhjhfNCD1YMMCEfvYA8zi5gMIfj3XC/4Z4uFf5bPAqTZX+6PUUQyRcOzBkqgfyyKjatS7aNEjneYusoQmFs9/aKh4FurVBAinQG5/Ssw+mHwBgWu2M2/QsudGYubqfPSVi3QFR0TQbMM/fVUuJAVDvuWSXDDxk0yekNIyzuZ3+ic6vHbA69e9APNarzmz+I0SbmqyWjMU3qykZzSggNLwWJ5Js854vj/8h45GQSQJ2zI8wcG2mp0BbwAKdtcYqBXyoDQYaDkgkys2xWl8W2E1fHmxv9oRALgRtc4F6QVuVHJ5og7VwnrbcVuKJkw== 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=ASDw3GKkMVKHR5vFMjUe7HP5KDKS5oD9aQGH4N66VTc=; b=hIUxEqmDaya+OM5DSJAY9uCgJfRv7APmeQlemVFx8gW61xfq6EaorH6zGanqVnDoKIYxPHf3EGju/DMEoy/2Jb8oBuLZErBwn/tbXewE7DW2YiHxRriZUbGYvimEhdiaxlkZlakBfym2ld5D1OIDkhCKwcUgSogCkaoUhJueEJXFRxiSLCQHZerML2bo2bkR1I8fka/JWczWfyFbRSzvxft7dapshrSr2yAqG90uSSuj/cZMSzHn0QM5pBwMTIKz93t3mRJQpAIND4/VkhK8KcFYW84ExgOX6cd/wECl1UMtJbokl+LQyRzg5SA3gGBxQzGIrhcxCshOfRMy62YWcQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) 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=ASDw3GKkMVKHR5vFMjUe7HP5KDKS5oD9aQGH4N66VTc=; b=r3AFjY2o5adBLD5mpOZ7WPJ/Xw2SWYffwYAzKmtc409DVsnZPBokBYfexUFKCT9Kh7QudgTNot9DkDeguabGZjyxQwwDpf7ODXuWJRong2jufj5aWUI9rHs7PHaq7lqOOeO7QHXwoCuE1+wmLMiO17ubgUllraLt5PhvlNWbuw6H0xSjf/ima4wT2uxWY7CX+vMNHqGdrR1V6qL1bvC0DPZZ2hbRDxMGhPeiGEySvu7o6u7bdNtugJpBnXczmvwhJTdOp5yMa9v3l1FO6OPcytY/kMMtO/Bm5fn3PnJGSiJH64fVema1gUKL31vUcADy3ulCKv92DeErT6KFbz4QSQ== Received: from BN9PR03CA0087.namprd03.prod.outlook.com (2603:10b6:408:fc::32) by PH7PR12MB7891.namprd12.prod.outlook.com (2603:10b6:510:27a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.17; Wed, 8 Mar 2023 14:26:31 +0000 Received: from BN8NAM11FT108.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fc:cafe::14) by BN9PR03CA0087.outlook.office365.com (2603:10b6:408:fc::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.29 via Frontend Transport; Wed, 8 Mar 2023 14:26:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by BN8NAM11FT108.mail.protection.outlook.com (10.13.176.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.17 via Frontend Transport; Wed, 8 Mar 2023 14:26:31 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Wed, 8 Mar 2023 06:26:22 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) 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.986.37; Wed, 8 Mar 2023 06:26:21 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.5 via Frontend Transport; Wed, 8 Mar 2023 06:26:21 -0800 From: Nicolin Chen To: , , , , , , CC: , , , , , , Subject: [PATCH v4 3/5] iommufd: Add replace support in iommufd_access_set_ioas() Date: Wed, 8 Mar 2023 06:26:00 -0800 Message-ID: <58b67ca78925186b246ce8ed3639a1c92e56f98a.1678284812.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT108:EE_|PH7PR12MB7891:EE_ X-MS-Office365-Filtering-Correlation-Id: fe2b4725-ebe6-415f-0fad-08db1fe11cc0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GpGScsGc0ZD6qJ6b4INqyG7YZs2hUlLVAge0IOVF8WppyM6j0Age0OUTTyFJlEp3EZGIolqK3J3nRiY8Ze/uBQRUraqyTqLNnpuFxPONAAtTHuc3zRqu616sIbbVlZWLG2v5h40mqu8HsfH6EuDwg6UgtWDxYhks0jDB5l4kGdQYkgXPwvgqrWyjaiPrfa8ykdBZZUsBCNmZR5YkB26H/gbj0sVkaZ5BhMOVHAHXU/zeoBApQU4ajSSK0Siq/x5mmdAY873mI3oOm6BTm+GroeP//PnYHzVzx8RDEDR2Nlu7BhtjP1xkVE07F5sFHzF73cGFkL8/A+tAfL1igmBpZfQyt8YLwhE3yeYOP+0apjWEhpTTceiwQ3UPr/F1gzQjtSoy/L9Lbe4QBiwfwpNel8E93U2cTjFelPQUNOgRlcxaY+HN1h+UdFaDEOxrD6e6ZkPSg3jJ+oQKYJ42N0kq7AceNWGPih7pIwSNpNydsUVdRKutdROvcL1lz1SOfrXub6M0cNEauqxXSexdP4FxljkRCXPc9mTafp+MtEq/vuOiyHski/xZwgZXEdTw4ixo+BeZzOE+68NjxZANtdu+RobP6e1BPDLwxqPqi7JpXCYVivyO9d/Nz7jhn6cTov4cPCRas8lecafKc+u3N6gJgDzRXi+39wbzjGJ90+HQVFM9QSTWhpNJJ7WHn6JxOrG8qYPD6CL+5pX+dc4ZiqzzQw== X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230025)(4636009)(376002)(39860400002)(346002)(136003)(396003)(451199018)(36840700001)(46966006)(40470700004)(82310400005)(86362001)(41300700001)(6666004)(8676002)(70206006)(70586007)(47076005)(426003)(36756003)(336012)(40480700001)(7696005)(316002)(110136005)(4326008)(40460700003)(54906003)(83380400001)(2906002)(186003)(478600001)(7636003)(82740400003)(26005)(356005)(8936002)(2616005)(36860700001)(7416002)(5660300002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2023 14:26:31.1633 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe2b4725-ebe6-415f-0fad-08db1fe11cc0 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.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT108.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7891 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Support an access->ioas replacement in iommufd_access_set_ioas(), which sets the access->ioas to NULL provisionally so that any further incoming iommufd_access_pin_pages() callback can be blocked. Then, call access->ops->unmap() to clean up the entire iopt. To allow an iommufd_access_unpin_pages() callback to happen via this unmap() call, add an ioas_unpin pointer so the unpin routine won't be affected by the "access->ioas = NULL" trick above. Suggested-by: Jason Gunthorpe Signed-off-by: Nicolin Chen Reviewed-by: Kevin Tian --- drivers/iommu/iommufd/device.c | 17 +++++++++++++++-- drivers/iommu/iommufd/iommufd_private.h | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 612a5f424bd7..c10e02f6a0be 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -727,11 +727,24 @@ int iommufd_access_set_ioas(struct iommufd_access *access, u32 ioas_id) iommufd_ref_to_users(obj); } + /* + * Set ioas to NULL to block any further iommufd_access_pin_pages(). + * iommufd_access_unpin_pages() can continue using access->ioas_unpin. + */ + access->ioas = NULL; + + if (access->ops->unmap) { + mutex_unlock(&access->ioas_lock); + access->ops->unmap(access->data, 0, ULONG_MAX); + mutex_lock(&access->ioas_lock); + } + if (cur_ioas) { iopt_remove_access(&cur_ioas->iopt, access); refcount_dec(&cur_ioas->obj.users); } + access->ioas_unpin = new_ioas; access->ioas = new_ioas; mutex_unlock(&access->ioas_lock); @@ -805,11 +818,11 @@ void iommufd_access_unpin_pages(struct iommufd_access *access, return; mutex_lock(&access->ioas_lock); - if (!access->ioas) { + if (!access->ioas_unpin) { mutex_unlock(&access->ioas_lock); return; } - iopt = &access->ioas->iopt; + iopt = &access->ioas_unpin->iopt; down_read(&iopt->iova_rwsem); iopt_for_each_contig_area(&iter, area, iopt, iova, last_iova) diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index db1ead8ff9d0..b18f843ad6a4 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -312,6 +312,7 @@ struct iommufd_access { struct iommufd_object obj; struct iommufd_ctx *ictx; struct iommufd_ioas *ioas; + struct iommufd_ioas *ioas_unpin; struct mutex ioas_lock; const struct iommufd_access_ops *ops; void *data; From patchwork Wed Mar 8 14:26:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13165918 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 18433C64EC4 for ; Wed, 8 Mar 2023 14:26:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231720AbjCHO0t (ORCPT ); Wed, 8 Mar 2023 09:26:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231649AbjCHO0o (ORCPT ); Wed, 8 Mar 2023 09:26:44 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2054.outbound.protection.outlook.com [40.107.94.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84AFFC709C; Wed, 8 Mar 2023 06:26:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A3AyGtZn7S5r7/Kps6HY6f48rGQUMqn2F4N2kqWTmlcWFVMCJd9+8tGtEycxxd+PWqcUKbBt9+qSGV/WvL6zZI6tAk3o3w7w8wPRh0PpjVdY9O8bF72I5yYumbe8l2PjLTd/B+FmEHdiYk5bD05yLylXT4ARyg8M5sY57SfBJmjy0u97/sMPLhO+/OcYvvdCkaNhWUTtD7ATQMm2mhDZB63b1vQhVfUX71yBmQrJVx/nMawZoT6zqHQB+1wMq5w0u3wbkUzbP+LoV1G4ZTDzd/K+wvY/YgpPZdIGNyw28CJTWEWD+9qPofaAbByKgstXz8G4QeAI5+qZwRMr1jxwBQ== 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=GBpMSN1XdXWnRLypdOscjNZjW9V51VxbSHPDW1MqkvM=; b=WhLlBVPfAPgQJRC36wGXkYWaTId2EIjlpUVPuO42hoAMlP4HwePFdui6ZNcNDEQYw1PrG1BGIMEg5xtYOdBKLx/a86SzUNayZN6u6Mp5mfQmlUarXSypNLPCsq/t2tMK2KGelLulV6B+xfxUKbn6ZEEjJq8q0AZ+ByuYKhqBCf7E667QGg2JXV322xcfKgXr71fh8HELwncnFBATDpiVtiPgPJPMWmjXxwIcjkGDdmAL2PvJSyYoNo0PKUghkD61OXNQdYP1vrrWnP5DGl1GOzyz8jehtk5AdQol4+fOAlFgs6cnl6ebUcKdY9jNWZYEIPNQiqBfLun+Ne3eFRNAag== 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 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=GBpMSN1XdXWnRLypdOscjNZjW9V51VxbSHPDW1MqkvM=; b=P8+DDQSi+cp9ccnUSBtU4oAuOQQmsGte2tQgCUQZ/aXXoHf1ozS7sqHNyTsZsytkxY1UagwcCCNM7bwyTx5cQbX/cr28Opdt7yibhYX3DDa3EVXuTTtna28ECDQP3mWDqJ1X5Qa3pypeSBojyvA1cuumlLyyKU9uxhYOKLiugOfdvlycWU5/0W/D2VN7CFono5xGKrBbHb4gBk7HQX9LiOMAhTdTaFur7BXZmc19X8SA7LhP3oMHbx1zOXg/ogb9MYeG4kdJWgVEuPlggQuSDELCGSdDD2WJz6f9kmajapsm5uC+eAub/zyYz9FnrFLZZeRvMsj5Q3pWynmjOOjITQ== Received: from BN9PR03CA0390.namprd03.prod.outlook.com (2603:10b6:408:f7::35) by LV2PR12MB5798.namprd12.prod.outlook.com (2603:10b6:408:17a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.29; Wed, 8 Mar 2023 14:26:36 +0000 Received: from BN8NAM11FT019.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f7:cafe::4e) by BN9PR03CA0390.outlook.office365.com (2603:10b6:408:f7::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.18 via Frontend Transport; Wed, 8 Mar 2023 14:26:36 +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 BN8NAM11FT019.mail.protection.outlook.com (10.13.176.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.19 via Frontend Transport; Wed, 8 Mar 2023 14:26:35 +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.986.5; Wed, 8 Mar 2023 06:26:23 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) 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.986.37; Wed, 8 Mar 2023 06:26:22 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.5 via Frontend Transport; Wed, 8 Mar 2023 06:26:22 -0800 From: Nicolin Chen To: , , , , , , CC: , , , , , , Subject: [PATCH v4 4/5] iommufd/selftest: Add coverage for access->ioas replacement Date: Wed, 8 Mar 2023 06:26:01 -0800 Message-ID: <4d2431e62910002feadd9bfaba0f397629aa4cc7.1678284812.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT019:EE_|LV2PR12MB5798:EE_ X-MS-Office365-Filtering-Correlation-Id: 8dcfcd80-775e-43fb-9ade-08db1fe11f9e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: buSauBUjbUkDm0l0ENncMTfSuMBsdye7n/kyFU9Bf0GGDWeQZvTKlSUtsjR6TjJ40wKi31+fxFhW3/bzIe5p2T3Nz6tXXTh5WDuUeb6lzlGWvoEAdtySKNVr8zzbaB7xMHqIDy6NESWtlOGPRncCzAU63ST4wZqwAGaULltTff5sZuMWp69fSs9ktXOrYZTRnlAyTa/4vRJlFUQLgqXXaGXGoilGlD8ZweXcwx+B0YmE8ryKsNALyezn72T+GdGJ67p4pCbTPazRb3nPSxSfueQ3viJm13tsw+ZZQeneC5LhH9gAGu7s1Qd1x/bJmzi3C7Ar2xNbyvyf6Z0XrIExDo+o6yI3VSTnm4vTVkTWV3mvk2JkxXkGANaWUoG23xZaiSURAu1mw2NxQFmFp6J0E33o1EHX3+xn9rer4EpbYyvTH2/k+pLX1OWF4FVJ+hUFm4KHIC65/WG0P4dBHjYXRkubpLDUQo6L8FlSwD9mqH6x1C4j/QLTs7Pc0EpZozySnXi9BqS4LDdjE9G6loRT0wPzSc8aJ9gJE9vcPNpBLXfTPazZ29mb61lFTeWUDETbY4ditIdPgeEil+wnk1uGS1XqijQEovmZ8OGRWfB/mqyIPsOIgDUPtO/zA2xtOROvj1w0oRvWHI5YidNzszC1JS/OUnM7v38IlmywDfSkQ1S/cx08JRwWPRmlXpytFLPzNtIpaw0I/RdOlbY1mbaIbQ== 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:(13230025)(4636009)(39860400002)(136003)(376002)(346002)(396003)(451199018)(40470700004)(46966006)(36840700001)(83380400001)(82310400005)(336012)(2616005)(47076005)(426003)(2906002)(5660300002)(4326008)(70586007)(7416002)(36860700001)(26005)(186003)(70206006)(8676002)(41300700001)(36756003)(7636003)(6666004)(82740400003)(40460700003)(8936002)(86362001)(478600001)(356005)(40480700001)(7696005)(54906003)(110136005)(316002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2023 14:26:35.9616 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8dcfcd80-775e-43fb-9ade-08db1fe11f9e 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: BN8NAM11FT019.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5798 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add replace coverage as a part of user_copy test case. It basically repeats the copy test after replacing the old ioas with a new one. Reviewed-by: Kevin Tian Signed-off-by: Nicolin Chen --- tools/testing/selftests/iommu/iommufd.c | 29 +++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index c07252dbf62d..5c33b6b52c65 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -1252,7 +1252,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); @@ -1270,11 +1276,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_set_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) From patchwork Wed Mar 8 14:26:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13165919 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 AEAD6C678D5 for ; Wed, 8 Mar 2023 14:26:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231816AbjCHO0y (ORCPT ); Wed, 8 Mar 2023 09:26:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231645AbjCHO0o (ORCPT ); Wed, 8 Mar 2023 09:26:44 -0500 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2060.outbound.protection.outlook.com [40.107.92.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95F85C3E27; Wed, 8 Mar 2023 06:26:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BLS42hZ38uSCszISFzAVaFGuW6+L1Dmor9OOPzGwMZBnBtWhcOUuD+PeHvQHwYPzwqCkwinST6UgHElvVv1EbTJbQlSP8jDoRPqRzl/vJAzBHIgqRMk2hcmP2Yg5iQPGTEkvi4Kiil9IGrlBiNAaspWq2THnmPiG7lAI3c06//v5o/wtWY2GJqDSMepSyKBtNA3SF3NhA6KDgiYJX1pVPfANc83JOlm4Q1VDjFr2R8vfdTFFWh4Val0l/ge86g9hilBDtCWv/u+FdmDXlwrvJdcLFmBnbDUY58f5ydNlk+oE4hOIdr2VPqsKB/bipZC1Hedn2PshZEM7LPo4LnfNFA== 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=lEHEiva0AInWLMPGMorLpy6fr1b2GpNjaBysPbPcCOw=; b=fklRz0ibqsHhU+/guB5tHro+6CChQQlnkabJM+Xhq5hqjCZ+oMxt3jyy4zQAk43LQ4jEIrwN2nWl6QFQ4pB6/UQbTZ4F7B1NNW4S4HxI3j19FqlQxYAt3MXjl6mQlUYJt22irIefyz31Kn9+330DDyXDIHXkpRDPSOVs2GqiCYdITfdSj0hX0ZJAa2uF6H68ydTxyioxFihC4VBo6MALD2ugyX5E2VYOsHc5cAHY0/RrCmJY/nWLbi0uOvDK/Cz52iwbXmNrXUOVXyhs3IUqYLMzgVcyhNBTJgOExiTqyFRELJfxBnQckgDutDxZCAi3ULUn48bnRVGMPHeZBYK7Lw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) 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=lEHEiva0AInWLMPGMorLpy6fr1b2GpNjaBysPbPcCOw=; b=DIvSE+xLdvyru41ugUp6dqeRkL9D+9y4JixJYNZm5Xs4ODVrU9ENFGdB8/U8xpRhs0mWT5vPwV1KjT1LiSNzYrr/C/xtU2i18BrVgLivBLoRso7IziBvJXxQoaaho1OHCHKYEUBMj1v954606thj2nfaDnnTZSi8mBj8s/BIfKSUMjlLsK2zwNeVl6ud9cii50F3cMesxCVfmM0q3nll7HAlJy+w3LHbWbhMt0O2So6592C8kBTB5aJPbB8rKh9pl6dpQOQtBo6+kiN5uAQzGBVtfeDb2J9CUVABInJhY/WEcnVX+p8jNkYHw+zDJlza+R2WRZ1XgC7bKelri0nNBQ== Received: from BN9PR03CA0532.namprd03.prod.outlook.com (2603:10b6:408:131::27) by CY8PR12MB7611.namprd12.prod.outlook.com (2603:10b6:930:9b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.29; Wed, 8 Mar 2023 14:26:36 +0000 Received: from BN8NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:408:131:cafe::c4) by BN9PR03CA0532.outlook.office365.com (2603:10b6:408:131::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.17 via Frontend Transport; Wed, 8 Mar 2023 14:26:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by BN8NAM11FT060.mail.protection.outlook.com (10.13.177.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.18 via Frontend Transport; Wed, 8 Mar 2023 14:26:36 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Wed, 8 Mar 2023 06:26:24 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) 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.986.37; Wed, 8 Mar 2023 06:26:23 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.5 via Frontend Transport; Wed, 8 Mar 2023 06:26:23 -0800 From: Nicolin Chen To: , , , , , , CC: , , , , , , Subject: [PATCH v4 5/5] vfio: Support IO page table replacement Date: Wed, 8 Mar 2023 06:26:02 -0800 Message-ID: <600343ffb282ff3bed5eb98a9255c0084d01a859.1678284812.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT060:EE_|CY8PR12MB7611:EE_ X-MS-Office365-Filtering-Correlation-Id: 7324f2f7-7edc-407e-802e-08db1fe11fc9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FRhummsE804Gc78CWoI49EcOI8MS97zKCxpieW8/j+2qLBz6ClZnNbz6bkP3iIoujrQb0p8uSDDUFEAb3svwlu6zZAjfeurseFfwzGboT8tjL1CC0ddSH6RlCPzxpDuaY7UUuSw2qpyu+BbIESD/wsCoYAlAfExjL+5LH0rl2vbPt64HMJ4VDryseDhvfFtKyg4IYF07i0dTZC30Qo0domzr47QdLvVog2j6DTMEXJwakvWKMNta1mOK/sHdlH8Qsy0Cin9yZRvoc2ZRN/YXQdJWwaYQ1g/r1zAZTuW79YMwJyXOih++zAe+QPZeM+om1bNw1sINstiazQvod5SXvt6LfR6Aph3ZoKgfE+qJFjuwDLYf4o5q4/gBeybnxz1FrNE3+RaeJNxQydBq6APzeZegz7YBF9LaRtd+ckcQXChUgyP+zjRxG1TO2DnE7ZDOf7CxU8A7sAa5voFhzTuoC/sCeFEMvE2FFNc8LWjMedlnr8mwqMthMvbLkB18jbnmK2Jrty4ukrxHuAJMcri66hG/4OIii2NPanGlANIdbJT1pQr2TXIGEU1XjGctgVVDDKndGf2b08BiAAS0BxMLRw1m9LKN3pAzMRCwIUqwDSzCyNyrzYGCeZdEr91BeJoW00LSrXuYjPOJbUnXaDRHuyEqplakdRTon8gdoZpjfPFsGHCjg3AgzO923JFIn5z2oL5vzywihA4Fxq3hiskOwg== X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230025)(4636009)(346002)(396003)(376002)(136003)(39860400002)(451199018)(36840700001)(40470700004)(46966006)(8676002)(36756003)(356005)(8936002)(41300700001)(4326008)(7416002)(70206006)(5660300002)(70586007)(7636003)(86362001)(82740400003)(36860700001)(7696005)(6666004)(478600001)(110136005)(54906003)(316002)(83380400001)(47076005)(40460700003)(82310400005)(2906002)(426003)(2616005)(186003)(336012)(26005)(40480700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2023 14:26:36.2584 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7324f2f7-7edc-407e-802e-08db1fe11fc9 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.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7611 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Now both the physical path and the emulated path should support an IO page table replacement. Call iommufd_device_replace() when vdev->iommufd_attached is true. Also update the VFIO_DEVICE_ATTACH_IOMMUFD_PT kdoc in the uAPI header. Signed-off-by: Nicolin Chen --- drivers/vfio/iommufd.c | 6 +++--- include/uapi/linux/vfio.h | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/vfio/iommufd.c b/drivers/vfio/iommufd.c index 8a9457d0a33c..a245a8e0c8ab 100644 --- a/drivers/vfio/iommufd.c +++ b/drivers/vfio/iommufd.c @@ -145,9 +145,9 @@ int vfio_iommufd_physical_attach_ioas(struct vfio_device *vdev, u32 *pt_id) return -EINVAL; if (vdev->iommufd_attached) - return -EBUSY; - - rc = iommufd_device_attach(vdev->iommufd_device, pt_id); + rc = iommufd_device_replace(vdev->iommufd_device, pt_id); + else + rc = iommufd_device_attach(vdev->iommufd_device, pt_id); if (rc) return rc; vdev->iommufd_attached = true; diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 692156a708bb..14375826a25b 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -243,6 +243,12 @@ struct vfio_device_bind_iommufd { * * Undo by VFIO_DEVICE_DETACH_IOMMUFD_PT or device fd close. * + * If a vfio device is currently attached to a valid hw_pagetable, without doing + * a VFIO_DEVICE_DETACH_IOMMUFD_PT, a second VFIO_DEVICE_ATTACH_IOMMUFD_PT ioctl + * passing in another hw_pagetable (hwpt) id is allowed. This action, also known + * as a hw_pagetable replacement, will replace the device's currently attached + * hw_pagetable with a new hw_pagetable corresponding to the given pt_id. + * * @argsz: user filled size of this data. * @flags: must be 0. * @pt_id: Input the target id which can represent an ioas or a hwpt