From patchwork Sun Apr 23 07:40:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 86666 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2074310vqo; Sun, 23 Apr 2023 00:42:52 -0700 (PDT) X-Google-Smtp-Source: AKy350YkpwBeaACK3B2vxsm/j1GvR3osWigznVKKnQ2Sczn8mDUNy9DAMgt1tLpU9C3dTnyCl/JX X-Received: by 2002:a17:902:e752:b0:1a6:955c:6329 with SMTP id p18-20020a170902e75200b001a6955c6329mr14179351plf.22.1682235771929; Sun, 23 Apr 2023 00:42:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1682235771; cv=pass; d=google.com; s=arc-20160816; b=kcOoj+6g5KRATY7Rp1qfufjwlxfek/3ZPhxWCPAzYi+QW003DysCXizdtGC0tAfjUB Sc0DD8uz8ecF7c16b0tkMY6Z87a62N3/L4xFqHUizN75ymn/6mvOl4qDv9G9+X+i7XNm XctGINl4To79zbMHSFjc4qIaGcv2wMQl7GvlAdj1HkylSUBICZp5NsrRyzcAI1dz/Ziv q/NlNXECyuDZBo8+jXvLCLRRv3yqrspDu2qtXVt93qrfdGwCEgop+npzsgeCrBIfWCCt TAHTgn1htLh9QZCJMdjSDM6s2rJ+9s8FvLqABcqpoqCKy7YCjejLlevVYRSI22n8AQzv WT6w== 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=ba7B2OHFYMEYz/AQFnUwp4+uykVtWQbYYCfz4zdvST8=; b=wsMnjzU1Z69PRvf3qfgvxjLT/pIdgLskwvt2N4BfQJDtOIW09JW/X7iiLiVguJhBr8 +Tud1vJ0jrPo6+FS4apvlaKtiKxsMB3NjymXg1mMyPOLkqz9cJ9acz2sQ7QHvtJK3Ri1 Hi2MYDzKQvmjCWeLztrdn6Xeg+kcjMAmfmqftfs3bbdLSt2Qe8J2vve5LBGVVxqcZoGE dX0R7K8kg6Qz4UEiXp81/RBi/Avai96hIaMH8gMCGj33e2fV05BYyHVk3KfZjVC4oRg3 II8NjKRCpQJjr6CAJUOGe/J7/9Q6K30MY8ETdOWWY1+w2lcc/ZH1t65fBmZ2ftVUb4Tn dGrw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=mAamBfwe; 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 q3-20020a17090311c300b001a1b0a828a8si8857880plh.621.2023.04.23.00.42.40; Sun, 23 Apr 2023 00:42:51 -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=mAamBfwe; 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 S230005AbjDWHl0 (ORCPT + 99 others); Sun, 23 Apr 2023 03:41:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229854AbjDWHlW (ORCPT ); Sun, 23 Apr 2023 03:41:22 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2071.outbound.protection.outlook.com [40.107.243.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 727E81FEF for ; Sun, 23 Apr 2023 00:41:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HZL3o2g39Q4H4UT+p7jAwO+tiopEnVasfk9wEUVcbpDHZqnpIvqrGl4iyAHepQZE5j2sAoyN6ULXTl+gqGnMY8NVi6uXqG4MRe+yz2h0JFrmbQZZ1mjPT5d8rSvs4yM6TxQ3vOW0OvVlPfyy+LKDe9JRtq7Ocu/UnvQZqspik+rVQWRosfwlJmRkOZaCah2lyZbDsNWDBwoJFcKLxTpHJItZURTiIhniHKwTEEJ+rMA0vUXG9RX2CNMXXijRrvKlM0+s+1LTheYRjLVMdCeXpJsA7AEu/+YH5X9w0XcVQgVbtQRQoST+0N6JOP8N9ngZzhY/hsTOBhmQCLBfOTxFuw== 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=ba7B2OHFYMEYz/AQFnUwp4+uykVtWQbYYCfz4zdvST8=; b=fnqXbU5eIE8EzUYYT4VtZK9166QDFImgEPzrUZBHnuIzFTWmrt8OJHa+1NMGmPBW9BXmOa7t/9cbca5j90xp77CIZPP1QIOQzTKtPUVsYyx6rqf8yAuv/0EQWuzuv/cm2Nzl6dc6ShtNTBC7TDAG/khhmIUb8E0S1cXNJIVhneq+DOnNlB7w3Yx2G1YNqgVliF+r7kICVu5wiflYq9ce1Rj2EwappHgudrSNyU/wS0TkMhE+aZqIyo3O8sEO05KsC6690qA88DuMGLBZJUAJ7E49rHBI7thWQTea2OODsS4ekXOSalpFJ77hZE3IkX2d61fA1T1iwNNCiYAxiV/pxA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=ba7B2OHFYMEYz/AQFnUwp4+uykVtWQbYYCfz4zdvST8=; b=mAamBfweD4nk4pQuXfjhfNp+1eRra4MwU933ThJAfwtWWHQfr3WKzrnkDco2uRCBUzWbJAVbTps4iptm+LfyfL7SHnC1a5nurR803yipIjEq/cVyddS5Pu0yniggc4lmSYCkClOPo+kp87K24nAuN/Qg857JojsYyHvf2NiXdEEaeNGiAY/F+GCPUFtOVdEE/gmTBtsXYEGJ+WHIShKMHIH7j3LXTxhgDvu+jo4Y1bnfOd/s3CNy4lh6dQjzut0R+kAfO4mx0byJptYUVcTQWxN5u10A/hVfFn9g1BjMSCwXq/iL7xqS8MUCGTHzRsWn0MOr9FvecwoGcGiVVCh+AQ== Received: from MW4PR03CA0166.namprd03.prod.outlook.com (2603:10b6:303:8d::21) by PH7PR12MB5688.namprd12.prod.outlook.com (2603:10b6:510:130::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.22; Sun, 23 Apr 2023 07:41:17 +0000 Received: from CO1NAM11FT028.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8d:cafe::47) by MW4PR03CA0166.outlook.office365.com (2603:10b6:303:8d::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.32 via Frontend Transport; Sun, 23 Apr 2023 07:41:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CO1NAM11FT028.mail.protection.outlook.com (10.13.175.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.18 via Frontend Transport; Sun, 23 Apr 2023 07:41:16 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Sun, 23 Apr 2023 00:41:09 -0700 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Sun, 23 Apr 2023 00:41:09 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Sun, 23 Apr 2023 00:41:08 -0700 From: Nicolin Chen To: , CC: , , , , , , , , , , Subject: [PATCH RFC v3 1/4] iommu: Add set/unset_dev_user_data ops Date: Sun, 23 Apr 2023 00:40:31 -0700 Message-ID: X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT028:EE_|PH7PR12MB5688:EE_ X-MS-Office365-Filtering-Correlation-Id: 091d7648-9c50-4458-9a72-08db43ce1f43 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: knqzOrVNz+MvWfR6iPRxLDkD/aQOs2k8sJOzDAzAMrgb1sOTSZpovMOq2fKRyw3XJchDgnhtJs/XNgm6Rrq8EoF0T4RF7jeawvAqmxGT/rrlbEfDRLNdWs/rmquaxNseTq0VGhWN8JdSQqVampufhFWTJZsDm0pDU5KCvksBhpQLR/KJx2qJ2OPNd8C703d3znYamvu87QlHUm5sv+b3DRi/ScT7FI6KPB1Ms1oX17NSleOr5Q3pcxl8oNyXQBVOXcYsV5Jgh/l2KZ3iTKaaOpp6GiJvFz6y1dRa0kbhK3tdcOz1X9UDaZh08K7Z77j20mdHuIWBamQUG0zEmXb+d2wqLHTGrshlVzQkiSBRtymefBjuYOpUKytrxFnt1rQ+Ds8mzmk8NES+rr7NIMs6dE4JGmWyKAnrayIDedPOyjQTWdO8ZUscc9UEFClRp7djzWNtkd29cTnICZbMG8WWC/o0p0/6cLBVTuFymgw83qp59h5UbcdsXWpg7jca3Z20/dwVCJdMtWAjsmZRQyyaJktKtUZzGtvfd5tIVfxDZHK0jQ/PTxvutaxQfBPPvW7IMxmCO50vH2s49zr+gHTS2XH+LjoW8JStNuibWIuhmPrpCR4S/k35r5vm5yIuRkJRUgNXzCcbdxO/xhKvSPxmyQETfpKpMok/w2L3wV1cSx1l1fXkqBbK2KH+aJexraVH4LQZhAcO/o+v05EsKGG0JVa88Rff0qydWyTyN9fZAfI= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(376002)(396003)(39860400002)(136003)(346002)(451199021)(36840700001)(46966006)(40470700004)(86362001)(36756003)(82310400005)(2906002)(40480700001)(6666004)(7696005)(36860700001)(34020700004)(186003)(2616005)(47076005)(426003)(336012)(83380400001)(26005)(4326008)(70206006)(70586007)(110136005)(40460700003)(478600001)(316002)(41300700001)(5660300002)(82740400003)(356005)(7636003)(54906003)(7416002)(8936002)(8676002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2023 07:41:16.8499 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 091d7648-9c50-4458-9a72-08db43ce1f43 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT028.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5688 X-Spam-Status: No, score=-1.9 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=ham 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763952057023534941?= X-GMAIL-MSGID: =?utf-8?q?1763952057023534941?= The device behind an IOMMU might be used in the user space by a VM. So, it might have some user space data. For example, a device behind an SMMU has a static stream ID. In a virtualization use case, both a host environment and a guest environment have their own Stream IDs. A link (a lookup table) between the physical Stream ID and the virtual (user) Stream ID is needed when the host handles the user cache invalidation commands. Add a pair of new ops to allow user space to forward user_data of a device via iommufd, and a new dev_user_data_len for data structure sanity done by the iommufd core. Signed-off-by: Nicolin Chen --- include/linux/iommu.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 5c99aeaccd1d..33b11d87b374 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -257,6 +257,15 @@ struct iommu_iotlb_gather { * @remove_dev_pasid: Remove any translation configurations of a specific * pasid, so that any DMA transactions with this pasid * will be blocked by the hardware. + * @set/unset_dev_user_data: set/unset an iommu specific device data from user + * space. The user device data info will be used by + * the driver to take care of user space requests. + * The device data structure must be defined in + * include/uapi/linux/iommufd.h. + * @dev_user_data_len: Length of the device data from user space (in bytes), + * simply the "sizeof" the data structure defined in the + * include/uapi/linux/iommufd.h. This is used by iommufd + * core to run a data length validation. * @hw_info_type: One of enum iommu_hw_info_type defined in * include/uapi/linux/iommufd.h. It is used to tag the type * of data returned by .hw_info callback. The drivers that @@ -303,6 +312,10 @@ struct iommu_ops { int (*def_domain_type)(struct device *dev); void (*remove_dev_pasid)(struct device *dev, ioasid_t pasid); + int (*set_dev_user_data)(struct device *dev, const void *user_data); + void (*unset_dev_user_data)(struct device *dev); + size_t dev_user_data_len; + const struct iommu_domain_ops *default_domain_ops; enum iommu_hw_info_type hw_info_type; unsigned long long hwpt_type_bitmap; From patchwork Sun Apr 23 07:40:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 86667 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2074588vqo; Sun, 23 Apr 2023 00:43:54 -0700 (PDT) X-Google-Smtp-Source: AKy350b0OdU/oAcimctgkQvHDGJ9Z55veTps2E4c/s8f99o+AnqQ2eXRTBBqP+CNOoMUuSWhAkES X-Received: by 2002:a05:6a20:7f84:b0:f1:1a44:dc55 with SMTP id d4-20020a056a207f8400b000f11a44dc55mr13779890pzj.10.1682235834368; Sun, 23 Apr 2023 00:43:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1682235834; cv=pass; d=google.com; s=arc-20160816; b=r2czyDju95n4gL3UL/QTfJ0txdql9cUgs8AyY+L75dbMVnSyINP7nupsAr+2H3M8Cg Qc/J2rZhnlgNEN+QSuM7WwJiibeS52ZUKW3NR5lsWlPpnV1Qx7yRcIX0bqINaGcrmFfK AA6aW/7gX0a2uxP3CM1oW5kAyinGeub5u0Rf3BetQMtB0/p7A7KUhZGLVXp80h9VrouS Z0iZoMgSTUFSnhyHopB/mYeP1ZgSRiF7A33naDOImFJ6zyh7PyKyVHxy/jjroCqoJ01U ebxV/5hiavJRDAaKIbiDbo1Hwytn2Q4C3Wgb+fIt10sIPFV62ktNeg50W8v8W2+BAwS+ 3F6Q== 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=AbdE4D/g0b6iv249wekdyBf/yAnvC5a9SkPSARvHk1c=; b=s/UnOoqbDYXAFKN1+A+RGQ26mtXLKZ1qRNX+W9kZ7KWq3Py/VNDLsP5u5reYPxBaf9 KGgGBbl8Tj9ECu50NCAYAPrt2FPmpEBheleATmL7DW4AP7Hp8Jn3VMqIM8AlBim3GYLa RWvsOdUksXV90SudZm1VJRI/sebfXSIABmVvezS3hJ0eHhR79YL5p9DSaXuYQNzPHo53 DTrn/uB8i/nLIFDfvCWIdFZcBZgHU200s5ahI5ygDR5egAVnSwgp1GD8DMf/Jw+KXX7W 2plGnGzX84TzGUUUjSLzXryARWkAtq+rVHtCGwCVqno+3Cpmb68V4gZVJnRtUH+j/LLZ +RnA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=tojOsmmK; 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 x187-20020a6363c4000000b004da377c33bbsi8426792pgb.85.2023.04.23.00.43.42; Sun, 23 Apr 2023 00:43:54 -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=tojOsmmK; 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 S230159AbjDWHlp (ORCPT + 99 others); Sun, 23 Apr 2023 03:41:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230045AbjDWHl1 (ORCPT ); Sun, 23 Apr 2023 03:41:27 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2062.outbound.protection.outlook.com [40.107.100.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3563D268C for ; Sun, 23 Apr 2023 00:41:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B9ppGJ/O0a/QFj6G1I12KontsE7LyeReDA9GvJ22kviCWONQeWlrr6C+Ns+DHgHU9HPxenm5GZ82YEUv7J9tjGYAKHxflWY4mSKkZh4M147OfdQuU+qdE08UEVtvNudEs/GLhERVkX3jnBCdnARSt6pN5p/rPJ/WIz9tXbbjP1dKnywl1AMbxm+SBhDe8bmFy4/Uo+FQX6LnMKqJ6VXX+0J7BWCI2gfd5ChokSneyUWZLUsz4RTXGQj7zopQFS54jIDcn94DcStKPWLQOZaDFIN4eKIo8fVKZ12dl36HWcVqto8Ngo1Qzf70G9s7rwUSZiMysnIGIdzXfDwtvY3ROQ== 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=AbdE4D/g0b6iv249wekdyBf/yAnvC5a9SkPSARvHk1c=; b=ayfBVmrLElyRu0GnFMZIhUebQXQJp2UgjtAgk7vJ4KVEx3KQ6Iu/SPSbu9o4m0y0chfblaJ3MwIKMB0Mhev9HDwEqNwExOv+Wc+xjCVLVCu2BPlVk5nm0x0VvRnOv9YIgy6bhpYXdyMjzvYdWEsX9cppc5j8sqhWE6WvwE9j20PuUaLxXKDzbQWnCCWNxE/1MTzqB0rZPIzTOqqmutO2S/q7m1QemnMJhTqpagyXz9Jv08oqjelZvLqZu8qLAlnWSBobShrtx4KvN9DXyxrVGubgohn1A8koJZaJO+Rakyoj5/283x2HrjkI2y7r7Tveqo/0Cnxotu86fOzdNNvptw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=AbdE4D/g0b6iv249wekdyBf/yAnvC5a9SkPSARvHk1c=; b=tojOsmmKlzLvQ8DzeaMXc+pCwvUAcdcMBgjHnjdDC17+4oikFmHKSKzVcN4sjG/D5/tjoZs/3MKeoYV+16d7MfQXsXfwiOYGQd735YavoqhK6C+SZpcJSqhScHKzQJ8SHwAfNQNwUfs50KxGhZwRgJK+HVmbnjDLOZY5gS8M6mm9PCLyl2IdhI83X6MXc70z5t3RwPor5U1O01onSUDTesoErF8phU6nAIjj5emI/H2CmffaD14NEgr00WvAXeKL131YkVhLuiA2H7Wyq0m/OkxQd2LcyVoxKzzIekQjxnjKOpk6uLoQU5GPAIrg5EewmD9ez8lZa6690EdZsdew/A== Received: from MW4PR04CA0329.namprd04.prod.outlook.com (2603:10b6:303:82::34) by SJ2PR12MB7800.namprd12.prod.outlook.com (2603:10b6:a03:4c1::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.45; Sun, 23 Apr 2023 07:41:19 +0000 Received: from CO1NAM11FT104.eop-nam11.prod.protection.outlook.com (2603:10b6:303:82:cafe::a3) by MW4PR04CA0329.outlook.office365.com (2603:10b6:303:82::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.32 via Frontend Transport; Sun, 23 Apr 2023 07:41:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CO1NAM11FT104.mail.protection.outlook.com (10.13.174.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.18 via Frontend Transport; Sun, 23 Apr 2023 07:41:19 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Sun, 23 Apr 2023 00:41:11 -0700 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Sun, 23 Apr 2023 00:41:10 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Sun, 23 Apr 2023 00:41:09 -0700 From: Nicolin Chen To: , CC: , , , , , , , , , , Subject: [PATCH RFC v3 2/4] iommufd: Add IOMMUFD_CMD_DEVICE_SET_DATA and IOMMUFD_CMD_DEVICE_UNSET_DATA Date: Sun, 23 Apr 2023 00:40:32 -0700 Message-ID: <08604f9f4835d5a6b0d2d75de69722194abf7747.1682234302.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT104:EE_|SJ2PR12MB7800:EE_ X-MS-Office365-Filtering-Correlation-Id: 494d4e2b-d118-4fb9-ecb9-08db43ce20b9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Hg5w6B2ZqhdmhHs0QygyoZFrYnYScyRrPDvvgjhLs+HpmoSXXbGaspWRSJpgsmnL0K2/xc2JocDerZCIjDt/d9VzUdDMWG21PAQMswGsz/bLzkX4ji1F4wPrfPAtDEvLsh1NIgZrZ/cG7wHQRGUxrUYWNtjw584EZC5/JCCVTEOdDczY68NJPHvyZf8xixGGUVYxpmweY+DQwk11wiPYCxrXiSiZW9N13kt32ORxY5e6gh1ql9VQWRPJoPeKEpxNPWRojTxA6pH7hl5zOQeXbNJFbdXiMxOnIxhpUGZrxI4aaeEFWaAbtKDLGcsZYxk+iZVMvsVmS3Y71Nk5O5fLH5qdotdfv9HhoUCKwDtbaj+ALqAW2q3xrwtQYvM8ycp68OdqiMRItRD3wV/jMliFOP89IiICnLi4XqheKiQ+dclft0q9Fs3fHec0yaXBIeA9OQ8jo+vSDzUdoy03Nn6ShgB+QeZahu1agW5V1F8+H03BlYmykVNWAmToD4n+LyPRiCZfwNktYdVmkPodA0WnhDUPpvMzBdsUhsXBJNScoVOS1jjSqFgWtaT1VjOdNH2xcTT08TcxJ8mdhqiYFS3Z5cKc2z/+DcxUVw2NhjRX94ni5fGo9Z+iCbyLHlMU+jRV4Ao00FsZQGid2CfWA/NEEZ+rXhB/BzlxglHnqwhVnuSEmYtDUUo1Sj5qgkJ1Fcb+UQ4X08/d7UNJ0WSl6pmawRs+8Ikn/h4JMg+ze5zMFDk= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(376002)(136003)(39860400002)(346002)(396003)(451199021)(46966006)(40470700004)(36840700001)(356005)(82740400003)(7636003)(6666004)(7696005)(34020700004)(478600001)(110136005)(54906003)(40460700003)(2906002)(40480700001)(336012)(83380400001)(426003)(47076005)(186003)(2616005)(36756003)(36860700001)(4326008)(82310400005)(5660300002)(70586007)(316002)(26005)(70206006)(7416002)(41300700001)(8676002)(86362001)(8936002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2023 07:41:19.2874 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 494d4e2b-d118-4fb9-ecb9-08db43ce20b9 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT104.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB7800 X-Spam-Status: No, score=-1.9 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=ham 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763952122191845193?= X-GMAIL-MSGID: =?utf-8?q?1763952122191845193?= Add a new pair of ioctls to allow user space to set and unset its iommu- specific device data for a passthrough device that's behind the iommu. On platforms with SMMUv3, this new uAPIs will be used to forward a user space virtual Stream ID of a passthrough device to link to its physical Stream ID and log into a lookup table, in order for the host kernel to later run sanity on ATC invalidation requests from the user space, with ATC_INV commands that have SID fields (virtual Stream IDs). Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/device.c | 81 +++++++++++++++++++++++++ drivers/iommu/iommufd/iommufd_private.h | 3 + drivers/iommu/iommufd/main.c | 4 ++ include/uapi/linux/iommufd.h | 32 ++++++++++ 4 files changed, 120 insertions(+) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index c649a3403797..9480cd36a8bd 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -136,6 +136,8 @@ void iommufd_device_destroy(struct iommufd_object *obj) struct iommufd_device *idev = container_of(obj, struct iommufd_device, obj); + if (WARN_ON(idev->has_user_data)) + dev_iommu_ops(idev->dev)->unset_dev_user_data(idev->dev); iommu_device_release_dma_owner(idev->dev); iommufd_put_group(idev->igroup); if (!iommufd_selftest_is_mock_dev(idev->dev)) @@ -726,6 +728,85 @@ void iommufd_device_detach(struct iommufd_device *idev) } EXPORT_SYMBOL_NS_GPL(iommufd_device_detach, IOMMUFD); +int iommufd_device_set_data(struct iommufd_ucmd *ucmd) +{ + struct iommu_device_set_data *cmd = ucmd->cmd; + struct iommufd_device *idev; + const struct iommu_ops *ops; + void *data = NULL; + 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); + + mutex_lock(&idev->igroup->lock); + if (idev->has_user_data) { + rc = -EEXIST; + goto out_unlock; + } + + ops = dev_iommu_ops(idev->dev); + if (!ops->dev_user_data_len || + !ops->set_dev_user_data || + !ops->unset_dev_user_data) { + rc = -EOPNOTSUPP; + goto out_unlock; + } + + data = kzalloc(ops->dev_user_data_len, GFP_KERNEL); + if (!data) { + rc = -ENOMEM; + goto out_unlock; + } + + if (copy_struct_from_user(data, ops->dev_user_data_len, + u64_to_user_ptr(cmd->data_uptr), + cmd->data_len)) { + rc = -EFAULT; + goto out_free_data; + } + + rc = ops->set_dev_user_data(idev->dev, data); + if (rc) + goto out_free_data; + + idev->has_user_data = true; +out_free_data: + kfree(data); +out_unlock: + mutex_unlock(&idev->igroup->lock); + iommufd_put_object(&idev->obj); + return rc; +} + +int iommufd_device_unset_data(struct iommufd_ucmd *ucmd) +{ + struct iommu_device_unset_data *cmd = ucmd->cmd; + struct iommufd_device *idev; + int rc = 0; + + idev = iommufd_get_device(ucmd, cmd->dev_id); + if (IS_ERR(idev)) + return PTR_ERR(idev); + + mutex_lock(&idev->igroup->lock); + if (!idev->has_user_data) { + rc = -ENOENT; + goto out_unlock; + } + + dev_iommu_ops(idev->dev)->unset_dev_user_data(idev->dev); + idev->has_user_data = false; +out_unlock: + mutex_unlock(&idev->igroup->lock); + iommufd_put_object(&idev->obj); + return rc; +} + void iommufd_access_destroy_object(struct iommufd_object *obj) { struct iommufd_access *access = diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index 35d1294b2f06..98eaef9c41d3 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -309,6 +309,7 @@ struct iommufd_device { /* always the physical device */ struct device *dev; bool enforce_cache_coherency; + bool has_user_data; }; static inline struct iommufd_device * @@ -321,6 +322,8 @@ iommufd_get_device(struct iommufd_ucmd *ucmd, u32 id) void iommufd_device_destroy(struct iommufd_object *obj); int iommufd_device_get_hw_info(struct iommufd_ucmd *ucmd); +int iommufd_device_set_data(struct iommufd_ucmd *ucmd); +int iommufd_device_unset_data(struct iommufd_ucmd *ucmd); struct iommufd_access { struct iommufd_object obj; diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c index b84b22487b7d..bd4753512990 100644 --- a/drivers/iommu/iommufd/main.c +++ b/drivers/iommu/iommufd/main.c @@ -326,6 +326,10 @@ static const struct iommufd_ioctl_op iommufd_ioctl_ops[] = { val64), IOCTL_OP(IOMMU_VFIO_IOAS, iommufd_vfio_ioas, struct iommu_vfio_ioas, __reserved), + IOCTL_OP(IOMMU_DEVICE_SET_DATA, iommufd_device_set_data, + struct iommu_device_set_data, data_len), + IOCTL_OP(IOMMU_DEVICE_UNSET_DATA, iommufd_device_unset_data, + struct iommu_device_unset_data, dev_id), #ifdef CONFIG_IOMMUFD_TEST IOCTL_OP(IOMMU_TEST_CMD, iommufd_test, struct iommu_test_cmd, last), #endif diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index ac023ea6040a..b39b0e2e46b1 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -51,6 +51,8 @@ enum { IOMMUFD_CMD_HWPT_ALLOC, IOMMUFD_CMD_DEVICE_GET_HW_INFO, IOMMUFD_CMD_HWPT_INVALIDATE, + IOMMUFD_CMD_DEVICE_SET_DATA, + IOMMUFD_CMD_DEVICE_UNSET_DATA, }; /** @@ -626,4 +628,34 @@ struct iommu_hwpt_invalidate { __aligned_u64 data_uptr; }; #define IOMMU_HWPT_INVALIDATE _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_INVALIDATE) + +/** + * struct iommu_device_set_data - ioctl(IOMMU_DEVICE_SET_DATA) + * @size: sizeof(struct iommu_device_set_data) + * @dev_id: The device to set an iommu specific device data + * @data_uptr: User pointer of the device user data + * @data_len: Length of the device user data + * + * The device data must be unset using ioctl(IOMMU_DEVICE_UNSET_DATA), before + * another ioctl(IOMMU_DEVICE_SET_DATA) call or before the device itself gets + * unbind'd from the iommufd context. + */ +struct iommu_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 iommu_device_unset_data - ioctl(IOMMU_DEVICE_UNSET_DATA) + * @size: sizeof(struct iommu_device_unset_data) + * @dev_id: The device to unset its device user data + */ +struct iommu_device_unset_data { + __u32 size; + __u32 dev_id; +}; +#define IOMMU_DEVICE_UNSET_DATA _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DEVICE_UNSET_DATA) #endif From patchwork Sun Apr 23 07:40:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 86670 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2077841vqo; Sun, 23 Apr 2023 00:56:58 -0700 (PDT) X-Google-Smtp-Source: AKy350ZTSXZON+bSQeVt726nulYhcsznD37uu+S8+zx0wfEytqyfVZCNB6ijs41hUKenp/I5hmXd X-Received: by 2002:a05:6a20:7485:b0:f4:c0d6:87e with SMTP id p5-20020a056a20748500b000f4c0d6087emr823703pzd.1.1682236618265; Sun, 23 Apr 2023 00:56:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1682236618; cv=pass; d=google.com; s=arc-20160816; b=jExliEn9x9YEWvQMKA4PnEt3f+i2PvZ0xaCH5+OjMFkA0BFJuLGnkEIoYw/+OEOlIv Zq4FdGXceYxjL5pTHxuoSJwPuIFuHzRtEcZrX0mfAGyrgACfXNxz/qqIJGlv1zakUok+ 5lN0soIlONXUR6+K3RYOn5KesVDR/txDt62I8irh6+JZV5NxHwT9uN/gNOFZxhFXm/N3 KPyD6EvAryNX3G3u+2+bptoGkFkLj5ZmtB7Yp1hLI9ok53sMFVw32oGc7TxQYinqvu0x 82OC1swwfpGOygUDQXLi06VhvDZ5AYuYkntszpHjUzxKK1wD01klUGvIHJvi8uZcT/AI mrkw== 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=npTtfCWluekQWpwb0rMYbbNRmEY6+WZAZVvBuX9pgBg=; b=yKQ7yifOUz0gjFzhE7f7QgqKToYWSN2tg9ny0NTNAUmtzeDva2/fm7ZZfC16/GSAGP MgpsSiHv2dbsq0dcnKd0WtfsRPaUmHcLu+xu683Va9mXU0ZvcOO3Xq0fZIL00ElrSvw+ BSGZC9thMCfPW05zxOndVjI19bCcdp8l/SHILA3Cibl2ub+gdEfbOWPS4PeEYyXrkO9a W8C26kmRbFT1a7Op42fn3BiyyIlC/Ptcw5n2foMH+3NscpAs3ucJsgbYPDHcAZxoSUGd 7vdZehrz+gEh2Jh3EMagye9/v9WiIXAqJg7WuXG+KQ0Sf+WB6tw4Y6r0ZJhbIQ5OTY+B HIAA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=CWoAabqt; 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 k191-20020a6384c8000000b00520538cbd30si8222281pgd.682.2023.04.23.00.56.45; Sun, 23 Apr 2023 00:56:58 -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=CWoAabqt; 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 S229556AbjDWHla (ORCPT + 99 others); Sun, 23 Apr 2023 03:41:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229516AbjDWHlY (ORCPT ); Sun, 23 Apr 2023 03:41:24 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2081.outbound.protection.outlook.com [40.107.92.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B0271FCC for ; Sun, 23 Apr 2023 00:41:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tt32G3nn80nC8Pa7TEpJB1ev4BMWkub65TND1p+XObupAgtuROka9pUFtHPMXqgZ/JVzUGgYZslTqJmc0fBMjirbXTqWiHEIPFakiTCbOuPjv5hRLVAiU11tlTFiOjbiziWXz+CD24Y0eHuTkLtkA7jisYWMA6ArJNOsrSh3cOa7itYnsDHAUP0v+NPNTQb5QDP4wCkpLU2r+DQeuYM2z1xqFdiTZ5VTr5Se0oCrYLaNp9Imf/uZCjt9Uc5ZNBDUisP1fV1lmY9k2Eo2Cj5ZYwS4Q3+A9c+OBiJ8UC6JvZtXR0KyGwCLaPbcgqIbTeIaCDPo6fDPU0NL3xH62GIrkg== 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=npTtfCWluekQWpwb0rMYbbNRmEY6+WZAZVvBuX9pgBg=; b=VSbtaUUR5nVl7cks17ut6W3LRj8fs6ElSZ6wL4eivQOt83eqzekjySd6/xt912qdJfsFstq9fnfHZB0FbwYXCt17wT7JLRRyrABOTMiYU7sfq94E3O3p197HeVAEYy0vOasZhQl4Nf1/wDTCc6QX77eZvRCkVkaUYFbvf6rBz6WQOFxEXLNATcPhAwxSl7HBz9y/7NpHBydwqf7CFyc7PaO2HwyHx2M24L9LAurylwR5SdCF60aC+hDP1RlOtj7IwifD1WbzMdWwK7ZRRFDqFMucMQTcWxSvWkNlaSER9GNW9cns6aQRR6DbR0LJUo6/sDhMDBlYn+bf5n8bxdwU7w== 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=npTtfCWluekQWpwb0rMYbbNRmEY6+WZAZVvBuX9pgBg=; b=CWoAabqtyyqCrysttzjY7bCEtz973Q7/fjZ8vSs1XtBT1oa80EUX8pM1LceSWQPbG1JCCXOWLb35LbXc38jC6oIkuS+KX6YfaKqkrP2AXy4SfD0nE8yXHPO8ggHgWOntoulJfrkwkvWNqx4g2rMxyTXEMXbNcpSpqZQyqObLoX1+SPWWJQSGvg3JyrrTC8eKLA1vaApy81Lamy6M8G6H/o6h/oJpmzbQcMZHsZdzkdAvygz/jfOjBvSb9a9zbeu5Uts/7XKPGcLFTT2V1k57J/i5i2GDyplaIugPAdtkiRGnL694Tp/Hkt+beKeCKwg+aqkoLNW8kTVvmP9pgrRlzg== Received: from BN9PR03CA0498.namprd03.prod.outlook.com (2603:10b6:408:130::23) by BY5PR12MB4131.namprd12.prod.outlook.com (2603:10b6:a03:212::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.22; Sun, 23 Apr 2023 07:41:20 +0000 Received: from BN8NAM11FT105.eop-nam11.prod.protection.outlook.com (2603:10b6:408:130:cafe::f8) by BN9PR03CA0498.outlook.office365.com (2603:10b6:408:130::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.32 via Frontend Transport; Sun, 23 Apr 2023 07:41:20 +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 BN8NAM11FT105.mail.protection.outlook.com (10.13.176.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.18 via Frontend Transport; Sun, 23 Apr 2023 07:41:20 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Sun, 23 Apr 2023 00:41:12 -0700 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Sun, 23 Apr 2023 00:41:11 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Sun, 23 Apr 2023 00:41:10 -0700 From: Nicolin Chen To: , CC: , , , , , , , , , , Subject: [PATCH RFC v3 3/4] iommufd/selftest: Add IOMMU_TEST_OP_DEV_CHECK_DATA Date: Sun, 23 Apr 2023 00:40:33 -0700 Message-ID: X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT105:EE_|BY5PR12MB4131:EE_ X-MS-Office365-Filtering-Correlation-Id: d61e8a51-f0ed-460d-87bb-08db43ce2131 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: v20ozb9YKVtiUxjmkupSGShBjlKDS/Pip2p934/fPxrAGD0GszsMI3xbLYlMwTSC5sjJu6Qna8NJGeNOvd87qAXPlmdyEK4xy8WWgzfpQNQnvHpHVvQ2NApgN8UOZjjTOvdji/kdfp82GtRhZN/rgRxB9kDZRsYUA3LzkgJ/9zSht2sMGcJuBOyKeH4dGOrncSGV1QEpbp+ttnRjhYNv21dygbFcZKD40xdHiDnXptwzQsE0APj5B25971NOwDoEd1vr7Rhp9cD7OTBGzfmfUY9QzLiNTz9po6BPeN2sZexz6JArndh5g2+EYYVvWbZG1GHFb88Wgm6tUXIQ1d3Vq9W7DwXEnFRUQBxLv039lXLYBR/WxjE/pNwNigQ/4uXrH75W2VaMNSZzE2fdIQjBTioOhi1BXob/TMtS7OzB6WIOjlDnt4d7XSH97x3eF6B9IZIdi6okP4cL/7nM3yvonbHHDaiX07C7fJAP8xafEW6AFR/FhO9pH1FASjt9Vrlp7oEBqT/VoDAtTdq2xDpFV3B6TRpmVP965qUyADQrvgXVrV5sIGsLa5POGF9RUxtWRBCim7jDsMyp9jXEqf5qCUeyiNfzL4gpmabtntJ0AXpQgDld8uwaz1ZQwWWzGNthKpkIl8x/SL4gmovHVUxUbrRDjPCWMFSEovNQ8ga4sjXADDvjtVBKKmxlqahiDiNsFusEqcG0FY3B3rMqYtJtJA== 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)(396003)(136003)(39850400004)(346002)(376002)(451199021)(46966006)(36840700001)(40480700001)(36860700001)(6666004)(4326008)(70586007)(70206006)(478600001)(8676002)(316002)(54906003)(8936002)(5660300002)(110136005)(7636003)(356005)(7416002)(82740400003)(41300700001)(336012)(47076005)(186003)(426003)(83380400001)(2616005)(7696005)(34020700004)(26005)(82310400005)(86362001)(36756003)(2906002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2023 07:41:20.0244 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d61e8a51-f0ed-460d-87bb-08db43ce2131 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: BN8NAM11FT105.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4131 X-Spam-Status: No, score=-1.9 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=ham 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763952944600069176?= X-GMAIL-MSGID: =?utf-8?q?1763952944600069176?= Add mock_domain_set/unset_dev_user_data and iommufd_test_dev_check_data to allow testing on IOMMUFD_CMD_DEVICE_SET/UNSET_DATA ioctls from user space selftest via IOMMU_TEST_OP_DEV_CHECK_DATA. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_test.h | 15 ++++++++++ drivers/iommu/iommufd/selftest.c | 42 ++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/drivers/iommu/iommufd/iommufd_test.h b/drivers/iommu/iommufd/iommufd_test.h index 8f93d83fb52a..b27db4cfb230 100644 --- a/drivers/iommu/iommufd/iommufd_test.h +++ b/drivers/iommu/iommufd/iommufd_test.h @@ -20,6 +20,7 @@ enum { IOMMU_TEST_OP_MOCK_DOMAIN_REPLACE, IOMMU_TEST_OP_ACCESS_REPLACE_IOAS, IOMMU_TEST_OP_MD_CHECK_IOTLB, + IOMMU_TEST_OP_DEV_CHECK_DATA, }; enum { @@ -99,6 +100,9 @@ struct iommu_test_cmd { struct { __u32 iotlb; } check_iotlb; + struct { + __u32 val; + } check_dev_data; }; __u32 last; }; @@ -119,6 +123,17 @@ struct iommu_test_hw_info { __u32 test_reg; }; +#define IOMMU_DEVICE_DATA_SELFTEST 0xdadbeef + +/** + * struct iommu_test_device_data + * + * @val: Should be set to IOMMU_DEVICE_DATA_SELFTEST or unset to 0x0 + */ +struct iommu_test_device_data { + __u32 val; +}; + /* Should not be equal to any defined value in enum iommu_hwpt_type */ #define IOMMU_HWPT_TYPE_SELFTTEST 0xbadbeef #define IOMMU_HWPT_TYPE_BITMAP_SELFTTEST U64_MAX diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index dc2b696acf2a..698976547d2d 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -95,6 +95,7 @@ enum selftest_obj_type { struct mock_dev { struct device dev; + u32 dev_data; }; struct selftest_obj { @@ -332,6 +333,23 @@ static void mock_domain_set_plaform_dma_ops(struct device *dev) */ } +static int mock_domain_set_dev_user_data(struct device *dev, + const void *user_data) +{ + struct mock_dev *mdev = container_of(dev, struct mock_dev, dev); + const struct iommu_test_device_data *data = user_data; + + mdev->dev_data = data->val; + return 0; +} + +static void mock_domain_unset_dev_user_data(struct device *dev) +{ + struct mock_dev *mdev = container_of(dev, struct mock_dev, dev); + + mdev->dev_data = 0; +} + static const struct iommu_ops mock_ops = { .owner = THIS_MODULE, .pgsize_bitmap = MOCK_IO_PAGE_SIZE, @@ -342,6 +360,9 @@ static const struct iommu_ops mock_ops = { .domain_alloc_user = mock_domain_alloc_user, .capable = mock_domain_capable, .set_platform_dma_ops = mock_domain_set_plaform_dma_ops, + .set_dev_user_data = mock_domain_set_dev_user_data, + .unset_dev_user_data = mock_domain_unset_dev_user_data, + .dev_user_data_len = sizeof(struct iommu_test_device_data), .default_domain_ops = &(struct iommu_domain_ops){ .free = mock_domain_free, @@ -704,6 +725,24 @@ static int iommufd_test_md_check_iotlb(struct iommufd_ucmd *ucmd, return rc; } +static int iommufd_test_dev_check_data(struct iommufd_ucmd *ucmd, + u32 dev_id, u32 val) +{ + struct iommufd_device *idev; + struct mock_dev *mdev; + int rc = 0; + + idev = iommufd_get_device(ucmd, dev_id); + if (IS_ERR(idev)) + return PTR_ERR(idev); + mdev = container_of(idev->dev, struct mock_dev, dev); + + if (mdev->dev_data != val) + rc = -EINVAL; + iommufd_put_object(&idev->obj); + return rc; +} + struct selftest_access { struct iommufd_access *access; struct file *file; @@ -1120,6 +1159,9 @@ int iommufd_test(struct iommufd_ucmd *ucmd) case IOMMU_TEST_OP_MD_CHECK_IOTLB: return iommufd_test_md_check_iotlb(ucmd, cmd->id, cmd->check_iotlb.iotlb); + case IOMMU_TEST_OP_DEV_CHECK_DATA: + return iommufd_test_dev_check_data(ucmd, cmd->id, + cmd->check_dev_data.val); case IOMMU_TEST_OP_CREATE_ACCESS: return iommufd_test_create_access(ucmd, cmd->id, cmd->create_access.flags); From patchwork Sun Apr 23 07:40:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 86669 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2077458vqo; Sun, 23 Apr 2023 00:55:21 -0700 (PDT) X-Google-Smtp-Source: AKy350YmzXHXCN4I/Mxv3Qf6uwlir0ABOMSpapu+GalOOerCwqg/qwQO6kf8q0dHr30q2I3rmvNj X-Received: by 2002:a17:90b:143:b0:247:ad6d:7250 with SMTP id em3-20020a17090b014300b00247ad6d7250mr11173330pjb.12.1682236521557; Sun, 23 Apr 2023 00:55:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1682236521; cv=pass; d=google.com; s=arc-20160816; b=tN3phNy+GXTLNvHUAGwpUiG7shzs6dUN6uoTHgyjGipoi7eyI8tIkWVZppsoK0DWcc 7bN+EoKhux4nLet5rXTqZSe1dSVMB8QXrtpq9oW2EXay892M4mO6q6CfLaNdwj1f/xZo 2w3gb27aNGNAsEHWHSEg6aXXKQPlgj2kNs/scJP7J5oBs0MiyCjQ5LsnMhZYNawRV9Pv tAYRGMKUZXegyNo2eDBrVDtc2Td1gUx1UI5u5ugorh9QZiod5hSLa+Pm0DkWzCvTZvDT RLRxCa+RMosJFwh1fBsdV92TELHOibsHYbyhMUZ92LRZ9/keAsNqg6tH+MTxj/JcXt8K dP0w== 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=sqZhqt0b08JYj1JYZFArb+zrEwKlF1ko5nnULbdPVXI=; b=rm+Ot2GNIBKfD1GEiAaRLsaPDz/k+HChsktH6ypkUzjPful2nyt/yOAxLjhTSmCxnT dUQgIkH9RmBIWAMm95ooWOQcOPIF5AYAKiZJwTZBgkk2CtFVn8ejT3SLJa0MzUXTjYfu E/3l857bcAjOMKY0SghR+f5wRKb4jJP1fi2k9hek7BKeWH2CQinnNvasmBvkvqVHcTR3 4jQ7YAv2s2zY1wBUV1tPvc9US/Vfgz/WkqmjBs8TfL2pBmgV6ahSWuRJ1VQJJYn02ONO HMhZO8BMIdi0m+nTuJPacOpPi9++3rk5klx2YXtAkAec4E/nnfV3tV0DcVRQFuLjA6rd Ln7Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=h0OpL4yo; 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 x16-20020a170902ec9000b001a1efc91917si9020208plg.634.2023.04.23.00.55.04; Sun, 23 Apr 2023 00:55:21 -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=h0OpL4yo; 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 S230059AbjDWHll (ORCPT + 99 others); Sun, 23 Apr 2023 03:41:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230001AbjDWHl0 (ORCPT ); Sun, 23 Apr 2023 03:41:26 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2066.outbound.protection.outlook.com [40.107.93.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03DB72132 for ; Sun, 23 Apr 2023 00:41:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DxHCM2C7QAf7Va8pAVmsOSMAaA99DGoT9/aipFZ1OlyiUeod/ARNMp+uWInbX/eQp/AWV7UD53Xx3+MFmWcaCh4DhcDLcGwAq47w/hq2x4KrqcjAKKiV5exr0gLcbQLAFmzMYjSV4lf24Zyx8j3mH3ne4Qi//L63P9RRXxQAlw/27HMjP+6AKUlBgn1fBUX4Cn/2DBVl98cCSWJ9RwzhozLMyMWd3+10WKXHkF9I8gJuF8lDpygKjSrzO02qmp+es4XkhxcShb/jL1bfTpnHOGWi37ionLQtj2B+D/7yvywEL71tzY+18HE7TKnhKIMTh3LnG829IXDx/MOG86ezig== 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=sqZhqt0b08JYj1JYZFArb+zrEwKlF1ko5nnULbdPVXI=; b=TA8QlqIdZGLUydd0HGA8xYGNdOTXutowrTw0uUPzpwb0uJBhDJOrwXoF11bbVMG5jaTjdWzvhgl6k5Vku02JKd3TE6HkPYWnly1BRkpuBumQQBCSSLP2/SenElRMHDnRJLMUllvbCh90JI2RYIu77T4/vH+phjBAZKFJJhmap7qeaCuPXXvN0tfjP9LaswI3YzFCt30dJKdlyFFci2U7EeM1I25wo0lPGMm9lxPioQDaLvyMypC5qw5SKcR3Y48aMetZvDct1+yAKhagWlet4p0S1vpQIkGXocl/nY9JZwSz8AvNFlyWVyDq2EFMYUSK3xSFQ0yD81ODd9BvVtk1NA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=sqZhqt0b08JYj1JYZFArb+zrEwKlF1ko5nnULbdPVXI=; b=h0OpL4yo/3UNFLB6fLz4ZsrEe4ow6EW7Q7fQgV8H0uUL3K595ICyau8BR9i2C7xycqyPx9lZFcYIRzqywZKBRqqsDq3K1+iIA1zOTiU1hHB96o1mEziNQIpAq99EwLL4/WbTNqhEhErsHXC1U4AjHgBh9YyopYoZrF+K1lwwlVmRLxFeDdTOyU4mobmH2yb1G61Z+YZk1mUkKJrcgSxJEQzJUbdFDKj6Z+zdzKHm/meo3Afa9sP7S5J1NnUswGbf9Y482KH8p8Fe9FH22lwamWtSZXY9cmjEXBuooR/NJl7vmoUIRkd7C7UbgCEFG77NosPTthibUJAYKeJ3JRBuMw== Received: from MW4PR03CA0125.namprd03.prod.outlook.com (2603:10b6:303:8c::10) by SJ0PR12MB7036.namprd12.prod.outlook.com (2603:10b6:a03:483::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.32; Sun, 23 Apr 2023 07:41:22 +0000 Received: from CO1NAM11FT115.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8c:cafe::2a) by MW4PR03CA0125.outlook.office365.com (2603:10b6:303:8c::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.27 via Frontend Transport; Sun, 23 Apr 2023 07:41:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CO1NAM11FT115.mail.protection.outlook.com (10.13.174.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.18 via Frontend Transport; Sun, 23 Apr 2023 07:41:22 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Sun, 23 Apr 2023 00:41:13 -0700 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Sun, 23 Apr 2023 00:41:13 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Sun, 23 Apr 2023 00:41:12 -0700 From: Nicolin Chen To: , CC: , , , , , , , , , , Subject: [PATCH RFC v3 4/4] iommufd/selftests: Add coverage for IOMMU_DEVICE_SET/UNSET_DATA Date: Sun, 23 Apr 2023 00:40:34 -0700 Message-ID: <6df9a4e5ad00b1386220f984ec640cab6237ca37.1682234302.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT115:EE_|SJ0PR12MB7036:EE_ X-MS-Office365-Filtering-Correlation-Id: e07730eb-9097-408d-8f52-08db43ce2291 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: S5BOnazjnPZ4fkCfdnoehtwjlEbxlOVDCjn7SUEtjWNLHQPtqAWkIwGvwEa0X/Yw2Yx+5+xS8DAXoer8HTq7Uxs5J/kajOLwsASLdyFXXQWwP/F2D+RIiZ24HDjhMZTSesYUTxPjn2v779gHsnpISFE0DybMhWAF99oJOKy9aZcD/o0C935vq80V5B8lhAAOGnS++lPNhaCOtUPBqN+2T+UTt/El1QVSzgb8o5IZ/RA6c6SR9w5XS3T6M215cztFP2RnAVM5VGv9aue5pxgDDbOCi/WEG7UdP9flYfan71DEcu5pmIAniAYZWv+Y9TKIiH/zgKir1aCXnVDDp8lYip6juTGPtTRY8Z52CRAsZFHi+1itnpavvpeLliCnqOu/LayRykOicRDV4gGIcsxjIJzMDsibQEDo9uFcEWR2Pu6gKN/Un7uJYT/NWF3N6mGoeUNJOW8Drnelx5LOnz6YDZTZC3KMrF09AhTb9ylBRYGUvWiQhILpOLkpM/D/TooiDkGl/+Ulwl0Yk666NLVEu/hCgURlasPnyzLNEFh8iYEpl30ZsnuFOrAJkCQn0kJvMkwdSKANwmZRrDlGocu/Ia8hcvDa+w7OJ+zKhtxzKFhl3HrsK7gBCMKy5Lz5ABhvwNZ2b8qQXa28mkLfgoRuUAi//u+gBGcD0pPLVkxFUBGPqbbjMhYn7UgkvmjbtM9+YO1Hbc/EQdCPY/4CCs67MCEpexFvcsVkpb9yOXWlDNw= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(136003)(39860400002)(396003)(376002)(346002)(451199021)(36840700001)(40470700004)(46966006)(36860700001)(34020700004)(186003)(2906002)(36756003)(54906003)(41300700001)(110136005)(2616005)(26005)(426003)(336012)(82310400005)(83380400001)(47076005)(86362001)(7416002)(5660300002)(7696005)(6666004)(82740400003)(8676002)(8936002)(40460700003)(316002)(7636003)(478600001)(356005)(70586007)(70206006)(4326008)(40480700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2023 07:41:22.3783 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e07730eb-9097-408d-8f52-08db43ce2291 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT115.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB7036 X-Spam-Status: No, score=-1.9 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=ham 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763952843131099174?= X-GMAIL-MSGID: =?utf-8?q?1763952843131099174?= Add a new IOMMU_TEST_OP_DEV_CHECK_DATA to verify whether the dev_data is properly set/unset by the IOMMU_DEVICE_SET/UNSET_DATA. Signed-off-by: Nicolin Chen --- tools/testing/selftests/iommu/iommufd.c | 20 +++++++ tools/testing/selftests/iommu/iommufd_utils.h | 59 +++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index 7291e1c4242a..8265ec6a0606 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -1483,6 +1483,26 @@ TEST_F(iommufd_mock_domain, alloc_hwpt) } } +TEST_F(iommufd_mock_domain, set_dev_data) +{ + struct iommu_test_device_data dev_data = { + .val = IOMMU_DEVICE_DATA_SELFTEST, + }; + int i; + + for (i = 0; i != variant->mock_domains; i++) { + test_err_device_set_data(ENOENT, 0, &dev_data); + test_err_device_set_data(EINVAL, self->idev_ids[i], NULL); + test_cmd_device_set_data(self->idev_ids[i], &dev_data); + test_err_device_set_data(EEXIST, self->idev_ids[i], &dev_data); + test_cmd_dev_check_data(self->idev_ids[i], dev_data.val); + test_err_device_unset_data(ENOENT, 0); + test_cmd_device_unset_data(self->idev_ids[i]); + test_err_device_unset_data(ENOENT, self->idev_ids[i]); + test_cmd_dev_check_data(self->idev_ids[i], 0); + } +} + /* VFIO compatibility IOCTLs */ TEST_F(iommufd, simple_ioctls) diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h index f8ba7b09078b..da04f802c675 100644 --- a/tools/testing/selftests/iommu/iommufd_utils.h +++ b/tools/testing/selftests/iommu/iommufd_utils.h @@ -445,3 +445,62 @@ static int _test_cmd_device_get_hw_info(int fd, __u32 device_id, EXPECT_ERRNO(_errno, \ _test_cmd_device_get_hw_info(self->fd, device_id, \ data_len, data)) + +#define test_cmd_dev_check_data(device_id, expected) \ + ({ \ + struct iommu_test_cmd test_cmd = { \ + .size = sizeof(test_cmd), \ + .op = IOMMU_TEST_OP_DEV_CHECK_DATA, \ + .id = device_id, \ + .check_dev_data = { .val = expected }, \ + }; \ + ASSERT_EQ(0, \ + ioctl(self->fd, \ + _IOMMU_TEST_CMD(IOMMU_TEST_OP_DEV_CHECK_DATA), \ + &test_cmd)); \ + }) + +static int _test_cmd_device_set_data(int fd, __u32 device_id, + struct iommu_test_device_data *dev_data) +{ + struct iommu_device_set_data cmd = { + .size = sizeof(cmd), + .dev_id = device_id, + .data_uptr = (uint64_t)dev_data, + .data_len = sizeof(*dev_data), + }; + int ret; + + ret = ioctl(fd, IOMMU_DEVICE_SET_DATA, &cmd); + if (ret) + return ret; + return 0; +} + +#define test_cmd_device_set_data(device_id, dev_data) \ + ASSERT_EQ(0, _test_cmd_device_set_data(self->fd, device_id, dev_data)) + +#define test_err_device_set_data(_errno, device_id, dev_data) \ + EXPECT_ERRNO(_errno, \ + _test_cmd_device_set_data(self->fd, device_id, dev_data)) + +static int _test_cmd_device_unset_data(int fd, __u32 device_id) +{ + struct iommu_device_unset_data cmd = { + .size = sizeof(cmd), + .dev_id = device_id, + }; + int ret; + + ret = ioctl(fd, IOMMU_DEVICE_UNSET_DATA, &cmd); + if (ret) + return ret; + return 0; +} + +#define test_cmd_device_unset_data(device_id) \ + ASSERT_EQ(0, _test_cmd_device_unset_data(self->fd, device_id)) + +#define test_err_device_unset_data(_errno, device_id) \ + EXPECT_ERRNO(_errno, \ + _test_cmd_device_unset_data(self->fd, device_id))