Message ID | cover.1681976394.git.nicolinc@nvidia.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp150577vqo; Thu, 20 Apr 2023 00:51:05 -0700 (PDT) X-Google-Smtp-Source: AKy350Zak/NgU0D2RCv61i7ERrTnQ2yniWWboaNgSkC/gjpLwiXJVUM2H7CyKdUzUVLdQN3o5761 X-Received: by 2002:a05:6a21:998f:b0:ef:7d7b:433b with SMTP id ve15-20020a056a21998f00b000ef7d7b433bmr1159722pzb.41.1681977065074; Thu, 20 Apr 2023 00:51:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681977065; cv=pass; d=google.com; s=arc-20160816; b=DmnqywLzktRtVUBqvjHFc9x1MsIWr0imcI6hs6aWEi6jCwKiwhhggAntkcMYvNzq/l bxrKGJCyPAqtcRSxrhVnOPNVw8mI2g56Jn4JGx8CAo+UbJgnmMx7QwRUHzv212D4KGAD 9gwnR5fPHH0Tv8ECsRvBw+OIPba3ehca7OElJqoxy19R4VtGtPq72drV5PrNsUpRSNDw 5Wjd41NSgpTU/WT3xAtgo5z/aXzktJ7tDJGiHk+U9Ol+qip2yF3nikv7io1GcFPDzH+I sYhC6zraYOFEM09FeUmSCyOv3K9oPZdUoAzgm0LM52JJIq1qEyTw4bnWoG8GD/asWrWI wO3w== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=3bueHgG3Gzsc9aEiaFZ+vigM5Apov14366JFLRWtVx8=; b=H8HP0TgvZSFrREdjsOaWMh7bfk7BE6BP4TjGVTNw5XYb2l0KDsruItZyLEn9H2AO0E hb7c+EJe9DDl+Ydhh7SjcOgUQh76eOIcNrMWJnRz4JDi65d41z4/ZIpPVv8W2dXPTwul obq8KvvVlRlVqUXskjjs/cl8DmoTYrnTMncZm0cN1X8h1WKNFHWrwTLNdKJkkns3RuD/ bohWD740S+qi/cDY872FjwlXbBH7ZolhB+AbgilhLmRSca1STUCHn5FpjYHh5fh2PWPp 6DogwYg6T5kzKaUTiZhyJBYa1o3oiiCniJmCdd2talEioegJI45H3x59DCzi1WiIdukz sNnw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=ls6oJ9Vq; 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 k184-20020a6384c1000000b0051b53255837si1025816pgd.508.2023.04.20.00.50.49; Thu, 20 Apr 2023 00:51:05 -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=ls6oJ9Vq; 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 S234151AbjDTHsi (ORCPT <rfc822;cjcooper78@gmail.com> + 99 others); Thu, 20 Apr 2023 03:48:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234145AbjDTHsd (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 20 Apr 2023 03:48:33 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2045.outbound.protection.outlook.com [40.107.220.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78F4349E6; Thu, 20 Apr 2023 00:48:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TUq/iUPtMt8vqmGddXOghBtRUP1CwaTlnTBRx/wN7aKRHKKLLmtJQMEQo9jMYptw3brYUfhPhMIpas6NTIv+Ntq3uoodYK0DXT8QCNVL2WbjlsMBnWwE6Em8Vy0BhscuTOD8+yWObzGvAWsfAkFbHUHpAZLqeZMeOqnXX3t6xgRZC4qLQ9dQt235fBdg5P9CwKVr6xWjYOmPC9AQdRQf6j6ngMi1u57gAQQoFm79tSzGi7J7VdUULQgcw+LJF6ObXoEfv0Dcjo6/3kZomur+6C/eAT8nLnK2IOfPigMSi33H5zjMS1kHBCfIj0U2lkY0ukrl3m154q0CKlgLvbDlpA== 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=3bueHgG3Gzsc9aEiaFZ+vigM5Apov14366JFLRWtVx8=; b=aQb+k2ZiwD8ur4l7L9Q8cPleWy3wSJjqHC7Ef4MmFY3od4N2DiuYfktrKBSETMV7z+bfYCT2MIM6TR1rEVr36t4drxS8KzFReF9CMmIKrZuiSau9EvKHX1jN057b2XCckPSn9qFKwrIjENe7YYLGf/4RwXzxMQcLIcAWY61lh2FSI97nME0oL4QW3Fstqksp8P6HVFiaDI8kurQCvdMbt+nPX0gIp4DqrOuGxa2euC9ikbCka0CjqNoKzjhnSpp4RxIgbr6vQAwHpOCejLHyFHYl2AxjLox59LUXLf4KNMGKOIZ61AvvmhfVQCo/RBE6hwAqtIhcVWlBlDFHNQssCA== 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=3bueHgG3Gzsc9aEiaFZ+vigM5Apov14366JFLRWtVx8=; b=ls6oJ9VqGHcTOx4q/inicZis2PElLEt+74qOc+bllNYQB3akCPzVbxSrW3y0au/ii//8EcPSEIY1UoG9JMvodFEvdqGkfINP4u3jzY/wBKf+0luKA494N1ePTO89KC7/OCIn3DhySrubwwA7/zkazsCe+PNg9ytUGZYuaWKBLma1aGX7qNhV7PSkOkArvNUgmy4VReCTBMXp8eL1wT/lG7bYBjRiuPaIJpL5ondUCCU+r+mtXxUsASqfkbmQNz0i2uAy7FYfFH1Fs+3Xaxp5XnI7Ru2azF02UyVO8qCtdH2uBbgLq3WU+zi62sQiVqwnH+RbOA7RXRKAn1Peub6BoQ== Received: from DM6PR01CA0025.prod.exchangelabs.com (2603:10b6:5:296::30) by CH0PR12MB5090.namprd12.prod.outlook.com (2603:10b6:610:bd::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.22; Thu, 20 Apr 2023 07:48:27 +0000 Received: from DM6NAM11FT017.eop-nam11.prod.protection.outlook.com (2603:10b6:5:296:cafe::49) by DM6PR01CA0025.outlook.office365.com (2603:10b6:5:296::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.25 via Frontend Transport; Thu, 20 Apr 2023 07:48:27 +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 DM6NAM11FT017.mail.protection.outlook.com (10.13.172.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.25 via Frontend Transport; Thu, 20 Apr 2023 07:48:26 +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.986.5; Thu, 20 Apr 2023 00:48:15 -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.986.37; Thu, 20 Apr 2023 00:48:15 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Thu, 20 Apr 2023 00:48:14 -0700 From: Nicolin Chen <nicolinc@nvidia.com> To: <jgg@nvidia.com>, <kevin.tian@intel.com>, <alex.williamson@redhat.com> CC: <robin.murphy@arm.com>, <eric.auger@redhat.com>, <yi.l.liu@intel.com>, <baolu.lu@linux.intel.com>, <will@kernel.org>, <joro@8bytes.org>, <shameerali.kolothum.thodi@huawei.com>, <jean-philippe@linaro.org>, <kvm@vger.kernel.org>, <iommu@lists.linux.dev>, <linux-kernel@vger.kernel.org> Subject: [PATCH RFC v2 0/3] Add set_dev_data and unset_dev_data support Date: Thu, 20 Apr 2023 00:47:44 -0700 Message-ID: <cover.1681976394.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT017:EE_|CH0PR12MB5090:EE_ X-MS-Office365-Filtering-Correlation-Id: 0db6a907-8056-446a-086e-08db4173a060 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7srQVDUMVmLmZihm5dGQQZyDS31Xk4lzbqT0NL98k2G0Che/i6UR7hBYpMOvKv74jh5aJziYYUm47N4BMO7w7dZaaUKAxLx5EoVzgTWghrO9SyKuJfFDd6RxtS2j7IjB25JYK2l33v/EnOToWkme/yt6mX99kDatWRoKXXsO36Y1+QeONS9L1UiBjV1i3dRJRjx3DkwCxXxKPzNZ17X4syKi2X1Gp/gcR1AJ6PMSMasEYZiNqD7E7t9+nZfLLijSjLdejZ2+UEaGOJwe8WnkYCRw/7eYUDzITgEp+2STlafW4Q7Vl614LNOXDJKFHrv8ddXA8b0pum311ORW1nlR9xI5p0ORSo1fS/bvlL0bfeiKuas9P3I8zu/ALvh7JUJgfLsG/k7xfqzwg0g+88If061xMND0jEyNuw95mrG4TwPaDYxukl6auS2y4FqJwFW3qRgl9cCAS1JWQqJysVZv2/dYyMHfAa9e/2bfqpqpSYVz+5/pUM0LoJWjJ+NCw9AvELebKg9Epjjm1mSA0OuGiIkTmvEDhPDHx8p4BOdk/VDqcxIIZ6j7i23BL2fhJz3E4pR3qaF/MHWDXoYdS5vG78QUQ/xhLRuo1Tzk1cGF4YzrhEOZfcX18dd7d9KHr9Htz0NFyGeyvfIQCyk8Rz6pYB2TgSs8dabpD8v6tSkqccyEa9kw5nPqE7/vE8OX8yt17Y90pIEmsQIjIMNPw236vnb/j912tq2zdEzZZudmz/RQMmjCcQVbPIZCM9cy7WqNzpMpT1Iqdddiig5RluokwbfOj3N2JKr51Ic6KkehieNyqpem/XCBPNfJ2bVJ0gq8 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)(136003)(39860400002)(376002)(346002)(396003)(451199021)(46966006)(36840700001)(40470700004)(4326008)(316002)(54906003)(110136005)(966005)(70586007)(70206006)(186003)(40460700003)(26005)(36860700001)(47076005)(426003)(336012)(2616005)(83380400001)(40480700001)(5660300002)(41300700001)(8676002)(8936002)(82310400005)(478600001)(7696005)(6666004)(82740400003)(34020700004)(36756003)(86362001)(2906002)(7416002)(7636003)(356005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2023 07:48:26.9343 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0db6a907-8056-446a-086e-08db4173a060 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: DM6NAM11FT017.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5090 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_NONE,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763680783340186795?= X-GMAIL-MSGID: =?utf-8?q?1763680783340186795?= |
Series |
Add set_dev_data and unset_dev_data support
|
|
Message
Nicolin Chen
April 20, 2023, 7:47 a.m. UTC
This is a pair of new uAPI/ops for user space to set an iommu specific device data for a passthrough device. This is primarily used by SMMUv3 driver for now, to link the vSID and the pSID of a device that's behind the SMMU. The link (lookup table) will be used to verify any ATC_INV command from the user space for that device, and then replace the SID field (virtual SID) with the corresponding physical SID. This series is available on Github: https://github.com/nicolinc/iommufd/commits/set_dev_data-rfc-v2 Thanks! Nicolin Nicolin Chen (3): iommu: Add set/unset_dev_data_user ops iommufd: Add iommufd_device_set_data and iommufd_device_unset_data APIs vfio: Add dev_data_len/uptr in struct vfio_device_bind_iommufd drivers/iommu/iommufd/device.c | 65 ++++++++++++++++++++++++++++++++++ drivers/vfio/device_cdev.c | 19 ++++++++-- drivers/vfio/iommufd.c | 13 +++++++ include/linux/iommu.h | 6 ++++ include/linux/iommufd.h | 4 +++ include/linux/vfio.h | 2 ++ include/uapi/linux/vfio.h | 13 +++++++ 7 files changed, 120 insertions(+), 2 deletions(-)
Comments
> From: Nicolin Chen <nicolinc@nvidia.com> > Sent: Thursday, April 20, 2023 3:48 PM > > This is a pair of new uAPI/ops for user space to set an iommu specific > device data for a passthrough device. This is primarily used by SMMUv3 > driver for now, to link the vSID and the pSID of a device that's behind > the SMMU. The link (lookup table) will be used to verify any ATC_INV > command from the user space for that device, and then replace the SID > field (virtual SID) with the corresponding physical SID. > > This series is available on Github: > https://github.com/nicolinc/iommufd/commits/set_dev_data-rfc-v2 > > Thanks! > Nicolin > there is no changelog compared to v1. Could you add some words why changing from passing the information in an iommufd ioctl to bind_iommufd? My gut-feeling leans toward the latter option...
On Fri, Apr 21, 2023 at 07:35:52AM +0000, Tian, Kevin wrote: > External email: Use caution opening links or attachments > > > > From: Nicolin Chen <nicolinc@nvidia.com> > > Sent: Thursday, April 20, 2023 3:48 PM > > > > This is a pair of new uAPI/ops for user space to set an iommu specific > > device data for a passthrough device. This is primarily used by SMMUv3 > > driver for now, to link the vSID and the pSID of a device that's behind > > the SMMU. The link (lookup table) will be used to verify any ATC_INV > > command from the user space for that device, and then replace the SID > > field (virtual SID) with the corresponding physical SID. > > > > This series is available on Github: > > https://github.com/nicolinc/iommufd/commits/set_dev_data-rfc-v2 > > > > Thanks! > > Nicolin > > > > there is no changelog compared to v1. Weird! How could it be missed during copy-n-paste.. I recalled that I had it but seemingly lost it after an update. It is in the commit message of the cover-letter though: https://github.com/nicolinc/iommufd/commit/5e17d270bfca2a5e3e7401d4bf58ae53eb7a8a55 -------------------------------------------------------- Changelog v2: * Integrated the uAPI into VFIO_DEVICE_BIND_IOMMUFD call * Renamed the previous set_rid_user to set_dev_data, to decouple from the PCI regime. v1: https://lore.kernel.org/all/cover.1680762112.git.nicolinc@nvidia.com/ -------------------------------------------------------- > Could you add some words why changing from passing the information > in an iommufd ioctl to bind_iommufd? My gut-feeling leans toward > the latter option... Yea. Jason told me to decouple it from PCI. And merge it into a general uAPI. So I picked the BIND ioctl. Thanks Nic
> From: Nicolin Chen <nicolinc@nvidia.com> > Sent: Friday, April 21, 2023 3:42 PM > > On Fri, Apr 21, 2023 at 07:35:52AM +0000, Tian, Kevin wrote: > > External email: Use caution opening links or attachments > > > > > > > From: Nicolin Chen <nicolinc@nvidia.com> > > > Sent: Thursday, April 20, 2023 3:48 PM > > > > > > This is a pair of new uAPI/ops for user space to set an iommu specific > > > device data for a passthrough device. This is primarily used by SMMUv3 > > > driver for now, to link the vSID and the pSID of a device that's behind > > > the SMMU. The link (lookup table) will be used to verify any ATC_INV > > > command from the user space for that device, and then replace the SID > > > field (virtual SID) with the corresponding physical SID. > > > > > > This series is available on Github: > > > https://github.com/nicolinc/iommufd/commits/set_dev_data-rfc-v2 > > > > > > Thanks! > > > Nicolin > > > > > > > there is no changelog compared to v1. > > Weird! How could it be missed during copy-n-paste.. > I recalled that I had it but seemingly lost it after an update. > > It is in the commit message of the cover-letter though: > https://github.com/nicolinc/iommufd/commit/5e17d270bfca2a5e3e7401d4b > f58ae53eb7a8a55 > -------------------------------------------------------- > Changelog > v2: > * Integrated the uAPI into VFIO_DEVICE_BIND_IOMMUFD call > * Renamed the previous set_rid_user to set_dev_data, to decouple from > the PCI regime. > v1: > https://lore.kernel.org/all/cover.1680762112.git.nicolinc@nvidia.com/ > -------------------------------------------------------- > > > Could you add some words why changing from passing the information > > in an iommufd ioctl to bind_iommufd? My gut-feeling leans toward > > the latter option... > > Yea. Jason told me to decouple it from PCI. And merge it into > a general uAPI. So I picked the BIND ioctl. > 'decouple it from PCI' is kind of covered by renaming set_rid to set_data. but I didn't get why this has to be merged with another uAPI. Once iommufd_device is created we could have separate ioctls to poke its attributes individually. What'd be broken if this is not done at BIND time?
On Fri, Apr 21, 2023 at 07:47:13AM +0000, Tian, Kevin wrote: > > It is in the commit message of the cover-letter though: > > https://github.com/nicolinc/iommufd/commit/5e17d270bfca2a5e3e7401d4b > > f58ae53eb7a8a55 > > -------------------------------------------------------- > > Changelog > > v2: > > * Integrated the uAPI into VFIO_DEVICE_BIND_IOMMUFD call > > * Renamed the previous set_rid_user to set_dev_data, to decouple from > > the PCI regime. > > v1: > > https://lore.kernel.org/all/cover.1680762112.git.nicolinc@nvidia.com/ > > -------------------------------------------------------- > > > > > Could you add some words why changing from passing the information > > > in an iommufd ioctl to bind_iommufd? My gut-feeling leans toward > > > the latter option... > > > > Yea. Jason told me to decouple it from PCI. And merge it into > > a general uAPI. So I picked the BIND ioctl. > > > > 'decouple it from PCI' is kind of covered by renaming set_rid > to set_data. but I didn't get why this has to be merged with another > uAPI. Once iommufd_device is created we could have separate > ioctls to poke its attributes individually. What'd be broken if this > is not done at BIND time? Oh, sorry. He didn't literally told me to merge, but commented "make sense" at my proposal of reusing BIND. So, I don't think adding to the BIND is a must here. The BIND is done in vfio_realize() where the RID (dev_data) is available also. And the new uAPI in my v1 actually gets called near the BIND. So, I feel we may just do it once? I am open to a better idea. Thanks Nic
> From: Nicolin Chen <nicolinc@nvidia.com> > Sent: Friday, April 21, 2023 3:56 PM > > On Fri, Apr 21, 2023 at 07:47:13AM +0000, Tian, Kevin wrote: > > > > It is in the commit message of the cover-letter though: > > > > https://github.com/nicolinc/iommufd/commit/5e17d270bfca2a5e3e7401d4b > > > f58ae53eb7a8a55 > > > -------------------------------------------------------- > > > Changelog > > > v2: > > > * Integrated the uAPI into VFIO_DEVICE_BIND_IOMMUFD call > > > * Renamed the previous set_rid_user to set_dev_data, to decouple from > > > the PCI regime. > > > v1: > > > https://lore.kernel.org/all/cover.1680762112.git.nicolinc@nvidia.com/ > > > -------------------------------------------------------- > > > > > > > Could you add some words why changing from passing the information > > > > in an iommufd ioctl to bind_iommufd? My gut-feeling leans toward > > > > the latter option... > > > > > > Yea. Jason told me to decouple it from PCI. And merge it into > > > a general uAPI. So I picked the BIND ioctl. > > > > > > > 'decouple it from PCI' is kind of covered by renaming set_rid > > to set_data. but I didn't get why this has to be merged with another > > uAPI. Once iommufd_device is created we could have separate > > ioctls to poke its attributes individually. What'd be broken if this > > is not done at BIND time? > > Oh, sorry. He didn't literally told me to merge, but commented > "make sense" at my proposal of reusing BIND. So, I don't think > adding to the BIND is a must here. > > The BIND is done in vfio_realize() where the RID (dev_data) is > available also. And the new uAPI in my v1 actually gets called > near the BIND. So, I feel we may just do it once? I am open to > a better idea. > IMHO if this can be done within iommufd then that should be the choice. vfio doesn't need to know this data at all and doing so means vdpa or a 3rd driver also needs to implement similar logic in their uAPI...
On Fri, Apr 21, 2023 at 08:07:19AM +0000, Tian, Kevin wrote: > External email: Use caution opening links or attachments > > > > From: Nicolin Chen <nicolinc@nvidia.com> > > Sent: Friday, April 21, 2023 3:56 PM > > > > On Fri, Apr 21, 2023 at 07:47:13AM +0000, Tian, Kevin wrote: > > > > > > It is in the commit message of the cover-letter though: > > > > > > https://github.com/nicolinc/iommufd/commit/5e17d270bfca2a5e3e7401d4b > > > > f58ae53eb7a8a55 > > > > -------------------------------------------------------- > > > > Changelog > > > > v2: > > > > * Integrated the uAPI into VFIO_DEVICE_BIND_IOMMUFD call > > > > * Renamed the previous set_rid_user to set_dev_data, to decouple from > > > > the PCI regime. > > > > v1: > > > > https://lore.kernel.org/all/cover.1680762112.git.nicolinc@nvidia.com/ > > > > -------------------------------------------------------- > > > > > > > > > Could you add some words why changing from passing the information > > > > > in an iommufd ioctl to bind_iommufd? My gut-feeling leans toward > > > > > the latter option... > > > > > > > > Yea. Jason told me to decouple it from PCI. And merge it into > > > > a general uAPI. So I picked the BIND ioctl. > > > > > > > > > > 'decouple it from PCI' is kind of covered by renaming set_rid > > > to set_data. but I didn't get why this has to be merged with another > > > uAPI. Once iommufd_device is created we could have separate > > > ioctls to poke its attributes individually. What'd be broken if this > > > is not done at BIND time? > > > > Oh, sorry. He didn't literally told me to merge, but commented > > "make sense" at my proposal of reusing BIND. So, I don't think > > adding to the BIND is a must here. > > > > The BIND is done in vfio_realize() where the RID (dev_data) is > > available also. And the new uAPI in my v1 actually gets called > > near the BIND. So, I feel we may just do it once? I am open to > > a better idea. > > > > IMHO if this can be done within iommufd then that should be > the choice. vfio doesn't need to know this data at all and doing > so means vdpa or a 3rd driver also needs to implement similar > logic in their uAPI... Reusing the VFIO ioctl is because the device is a VFIO device. But doing it within iommufd could save us a lot of efforts, as you said. So... +/** + * struct iommufd_device_set_data - ioctl(IOMMU_DEVICE_SET_DATA) + * @size: sizeof(struct iommufd_device_set_data) + * @dev_id: The device to set a device data + * @data_uptr: User pointer of the device user data. + * @data_len: Length of the device user data. + */ +struct iommufd_device_set_data { + __u32 size; + __u32 dev_id; + __aligned_u64 data_uptr; + __u32 data_len; +}; +#define IOMMU_DEVICE_SET_DATA _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DEVICE_SET_DATA) + +/** + * struct iommufd_device_unset_data - ioctl(IOMMU_DEVICE_UNSET_DATA) + * @size: sizeof(struct iommufd_device_unset_data) + * @dev_id: The device to unset its device data + */ +struct iommufd_device_unset_data { + __u32 size; + __u32 dev_id; +}; +#define IOMMU_DEVICE_UNSET_DATA _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DEVICE_UNSET_DATA) Maybe just like this? Thanks Nic
On Fri, Apr 21, 2023 at 01:20:13AM -0700, Nicolin Chen wrote: > +/** > + * struct iommufd_device_set_data - ioctl(IOMMU_DEVICE_SET_DATA) > + * @size: sizeof(struct iommufd_device_set_data) > + * @dev_id: The device to set a device data > + * @data_uptr: User pointer of the device user data. > + * @data_len: Length of the device user data. > + */ > +struct iommufd_device_set_data { > + __u32 size; > + __u32 dev_id; > + __aligned_u64 data_uptr; > + __u32 data_len; > +}; > +#define IOMMU_DEVICE_SET_DATA _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DEVICE_SET_DATA) > + > +/** > + * struct iommufd_device_unset_data - ioctl(IOMMU_DEVICE_UNSET_DATA) > + * @size: sizeof(struct iommufd_device_unset_data) > + * @dev_id: The device to unset its device data > + */ > +struct iommufd_device_unset_data { > + __u32 size; > + __u32 dev_id; > +}; > +#define IOMMU_DEVICE_UNSET_DATA _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DEVICE_UNSET_DATA) > > Maybe just like this? How would the iommu_ops backing this work? Jason
On Fri, Apr 21, 2023 at 10:09:35AM -0300, Jason Gunthorpe wrote: > On Fri, Apr 21, 2023 at 01:20:13AM -0700, Nicolin Chen wrote: > > > +/** > > + * struct iommufd_device_set_data - ioctl(IOMMU_DEVICE_SET_DATA) > > + * @size: sizeof(struct iommufd_device_set_data) > > + * @dev_id: The device to set a device data > > + * @data_uptr: User pointer of the device user data. > > + * @data_len: Length of the device user data. > > + */ > > +struct iommufd_device_set_data { > > + __u32 size; > > + __u32 dev_id; > > + __aligned_u64 data_uptr; > > + __u32 data_len; > > +}; > > +#define IOMMU_DEVICE_SET_DATA _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DEVICE_SET_DATA) > > + > > +/** > > + * struct iommufd_device_unset_data - ioctl(IOMMU_DEVICE_UNSET_DATA) > > + * @size: sizeof(struct iommufd_device_unset_data) > > + * @dev_id: The device to unset its device data > > + */ > > +struct iommufd_device_unset_data { > > + __u32 size; > > + __u32 dev_id; > > +}; > > +#define IOMMU_DEVICE_UNSET_DATA _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DEVICE_UNSET_DATA) > > > > Maybe just like this? > > How would the iommu_ops backing this work? How about the following piece? Needs a test with QEMU though.. static const size_t iommufd_device_data_size[] = { [IOMMU_HW_INFO_TYPE_NONE] = 0, [IOMMU_HW_INFO_TYPE_INTEL_VTD] = 0, [IOMMU_HW_INFO_TYPE_ARM_SMMUV3] = sizeof(struct iommu_device_data_arm_smmuv3), }; int iommufd_device_set_data(struct iommufd_ucmd *ucmd) { struct iommufd_device_set_data *cmd = ucmd->cmd; struct iommufd_device *idev; const struct iommu_ops *ops; void *data = NULL; u32 klen = 0; int rc; if (!cmd->data_uptr || !cmd->data_len) return -EINVAL; idev = iommufd_get_device(ucmd, cmd->dev_id); if (IS_ERR(idev)) return PTR_ERR(idev); ops = dev_iommu_ops(idev->dev); if (!ops || !ops->set_dev_data_user || !ops->unset_dev_data_user || ops->hw_info_type >= ARRAY_SIZE(iommufd_device_data_size)) { rc = -EOPNOTSUPP; goto out_put_idev; } klen = iommufd_device_data_size[ops->hw_info_type]; if (!klen) { rc = -EOPNOTSUPP; goto out_put_idev; } data = kzalloc(klen, GFP_KERNEL); if (!data) { rc = -ENOMEM; goto out_put_idev; } if (copy_struct_from_user(data, klen, u64_to_user_ptr(cmd->data_uptr), cmd->data_len)) { rc = -EFAULT; goto out_free_data; } rc = ops->set_dev_data_user(idev->dev, data); out_free_data: kfree(data); out_put_idev: iommufd_put_object(&idev->obj); return rc; }
On Fri, Apr 21, 2023 at 10:37:22AM -0700, Nicolin Chen wrote: > How about the following piece? Needs a test with QEMU though.. > > static const size_t iommufd_device_data_size[] = { > [IOMMU_HW_INFO_TYPE_NONE] = 0, > [IOMMU_HW_INFO_TYPE_INTEL_VTD] = 0, > [IOMMU_HW_INFO_TYPE_ARM_SMMUV3] = > sizeof(struct iommu_device_data_arm_smmuv3), > }; If we need more than one of these things we'll need a better solution.. > rc = ops->set_dev_data_user(idev->dev, data); Where will the iommu driver store the vsid to sid xarray from these arguments? Jason
On Fri, Apr 21, 2023 at 02:59:37PM -0300, Jason Gunthorpe wrote: > On Fri, Apr 21, 2023 at 10:37:22AM -0700, Nicolin Chen wrote: > > > How about the following piece? Needs a test with QEMU though.. > > > > static const size_t iommufd_device_data_size[] = { > > [IOMMU_HW_INFO_TYPE_NONE] = 0, > > [IOMMU_HW_INFO_TYPE_INTEL_VTD] = 0, > > [IOMMU_HW_INFO_TYPE_ARM_SMMUV3] = > > sizeof(struct iommu_device_data_arm_smmuv3), > > }; > > If we need more than one of these things we'll need a better > solution.. How about adding ops->device_data_size to store the value? And, since we have a few size arrays in hw_pagetable.c too, perhaps a new structure in ops packing all these sizes can clean up a bit things too? For example, static struct iommu_user_data_size arm_smmu_user_data_size = { .device_data_size = sizeof(iommu_device_data_arm_smmuv3), .hwpt_alloc_data_size = sizeof(iommu_hwpt_alloc_arm_smmuv3), .hwpt_invalidate_data_size = sizeof(iommu_hwpt_invalidate_arm_smmuv3), } The hwpt_xxx_data_size might be in form of arrays for multi- HWPT_TYPE support. > > rc = ops->set_dev_data_user(idev->dev, data); > > Where will the iommu driver store the vsid to sid xarray from these > arguments? The ARM structure packs a vsid. For example: static int arm_smmu_set_data(struct device *dev, const void *user_data) { const struct iommufd_device_data_arm_smmuv3 *data = user_data; struct arm_smmu_master *master = dev_iommu_priv_get(dev); struct arm_smmu_stream *stream = &master->streams[0]; struct arm_smmu_device *smmu = master->smmu; u32 sid_user = data->sid; int ret = 0; if (!sid_user) return -EINVAL; ret = xa_alloc(&smmu->streams_user, &sid_user, stream, XA_LIMIT(sid_user, sid_user), GFP_KERNEL_ACCOUNT); if (ret) return ret; stream->id_user = sid_user; return 0; } Thanks Nic
On Fri, Apr 21, 2023 at 11:19:23AM -0700, Nicolin Chen wrote: > On Fri, Apr 21, 2023 at 02:59:37PM -0300, Jason Gunthorpe wrote: > > On Fri, Apr 21, 2023 at 10:37:22AM -0700, Nicolin Chen wrote: > > > > > How about the following piece? Needs a test with QEMU though.. > > > > > > static const size_t iommufd_device_data_size[] = { > > > [IOMMU_HW_INFO_TYPE_NONE] = 0, > > > [IOMMU_HW_INFO_TYPE_INTEL_VTD] = 0, > > > [IOMMU_HW_INFO_TYPE_ARM_SMMUV3] = > > > sizeof(struct iommu_device_data_arm_smmuv3), > > > }; > > > > If we need more than one of these things we'll need a better > > solution.. > > How about adding ops->device_data_size to store the value? https://lore.kernel.org/linux-iommu/cover.1682234302.git.nicolinc@nvidia.com/ I sent a v3 that includes this replacing the data_size array. If it looks good, we can drop the other two data_size arrays for hwpt in the nesting series too. Thanks Nic