From patchwork Tue May 9 04:51:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 91367 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2632207vqo; Mon, 8 May 2023 22:15:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ab0Yv8ZJGMI7RzPbWcDj15UZoCG+AvTC61AsKcAJybtaRo2h0YWt6TYWP7nDqe6kpPL6J X-Received: by 2002:a05:6a00:e8f:b0:643:a6d1:b27 with SMTP id bo15-20020a056a000e8f00b00643a6d10b27mr10900112pfb.15.1683609358711; Mon, 08 May 2023 22:15:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683609358; cv=pass; d=google.com; s=arc-20160816; b=lN/ks1bqcKQOVM34zUBDzY3NJhMS+Hzv9pPhARmg2wIbTK/3yTs/iLA4DSxqNu0xa7 nbwYfbo74Hflx+jSANXN/ZucB3JdT4wcIGpyz4lxG5T2V4lpCiOoJqs2ZbCyoettKzPs Hk7HeKYgg4F4eq3yu74ZgFraNXB2noHFT54aqVQiMO7s7gmD+gzEal1qXWVGvJgP4hO2 ZY8MWs85hiu5MeN9VF/hv5dO1QQHhOx7fL2tXW+GfGCrjgPfSeipXat6T/aau7BCSbcx 490HITRpwq4a2VugXUIqhmxzvqdLXffg3MrLg3ep2TOCuLjtmeiplhKJtbI8a6TaKGC8 qRww== 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=pKUMrMClBvMFabvSmciN9jU21OPJcNHVS6oQNUMcJ9w=; b=hjHkp7RIlls/qFGW0xudvOwLuEbTUO9lxUiP+JIocZMCWenB+Kg20hlrB1qZRRuogj 2CyhOYzt5eUFRIJh5UAGfx9+eY8ksh9e0bLZ9g5GmOp8n0fXuuM7tu+J0Ng4E2UPy9W9 mdBEFJLghuDk2uzS/m0UKySgVf4JRBjrQRrp7vswCe3XH6JEns1YcYZEmvlQFrlRdaea SOpjBKA2denv24R/gdLw3sYBwNWzPSdl+ePYQuvqq/p8lzfRdWPVbkRcGe9mo93OWcjH n9qaNiaxocK5AZJCKJoe4R5jycvi9E2eBtjGVnIVetdfy3l8UA72btH/CHPwi8Tu2WDO Ogzw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="G4sdyky/"; 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 77-20020a621850000000b0063d2b810fcbsi1607157pfy.208.2023.05.08.22.15.45; Mon, 08 May 2023 22:15: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="G4sdyky/"; 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 S233641AbjEIEwU (ORCPT + 99 others); Tue, 9 May 2023 00:52:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229587AbjEIEwN (ORCPT ); Tue, 9 May 2023 00:52:13 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2044.outbound.protection.outlook.com [40.107.223.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B538A30F7 for ; Mon, 8 May 2023 21:52:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E/cIrhuskdbkJP5k5majVmDbT6qUbC7oTnBvHKp90+KrS1jXMpNxhpCADEisjDvylM/FhmiAChnCrGPEx2in/No5OBB7svSCUeckxyarbVkx0ffS5NWUmhCJasjgqIadgTqGun0uMxWjKoA/ozKAHJHhxZvxcgd8yDwrvLqM4yEES66i36kvv/vIoHlUQdlzJpWCkTb7tk1wSV4kOyVjjOcojiJjftBY8YlbbBZzxlvFYAcN5yiZH/vtLPRZcOrdlOZzgV76Qp7ifKY3U9aDRepNHwKYLPLpc7hQTdDTC4T7kKIfcci4aUa8/VseYhMLRe3swGoi5VVojs2K908YFQ== 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=pKUMrMClBvMFabvSmciN9jU21OPJcNHVS6oQNUMcJ9w=; b=ASgoQEVakC7sLFFmn+HvZDPyWL1xUa9jVzDStkAkcRwPRfOCzdQDMOMzbkL53eWT7h7aSIhGPYrtGodzhCiwNQa/y0TuDn2WbS6l9KmICLSrhLPXSjBpYXwVBbFTOqrzCvSzhXQJJFpdn1uIUY2R8HxfTB9nCX0mmpcd4Pdxkee9tloNsEtc4jQwKfaZlnRfgL7BHrBmbpO4f5aBs4flshPhYuUdRcXNvSYs56jiu3y9H3858cqt4+LbK2V/ylv0xf3M5Fgf0tSW9YbNtYTSNadZXR/ZDUorH21uFx3khCqbo2Bb7Bkeo4dpPDjmxCz8nw8rdYUVNb25EmTJUACiYA== 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=pKUMrMClBvMFabvSmciN9jU21OPJcNHVS6oQNUMcJ9w=; b=G4sdyky/TAQnMRd8lMXh+szO4MsiooV20H/Kl5iZwKrqzgAb++ZB9DBAsB6V/6V+Vd2IY4DrSYMRJgK+SDnXrzkf8TMZiptsClJID/DExVM/qj9KZDS01iHgWH6HvL8A9p+c0K2ogcrDSl3rvYQl5EK1+HdHROEAU9CMS32zFSwMYQbb056+8wJ0frH5UR93XFzWDdDXAAnFJJ6dfNzXPjL2MQMqBKIUTizpUmJOI9YBkY6sJf1p0w10h/bpArfX6gJjmTJX1LQ5fuLoW2VskU2k59AJDZJOp2XxG11nC/23g0Zaj3WfsbhcOI5kVHvRI81pbomDZ2Td2lhm4wYbZA== Received: from BN0PR03CA0033.namprd03.prod.outlook.com (2603:10b6:408:e7::8) by PH7PR12MB6933.namprd12.prod.outlook.com (2603:10b6:510:1b7::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33; Tue, 9 May 2023 04:52:09 +0000 Received: from BN8NAM11FT078.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e7:cafe::16) by BN0PR03CA0033.outlook.office365.com (2603:10b6:408:e7::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33 via Frontend Transport; Tue, 9 May 2023 04:52:08 +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 BN8NAM11FT078.mail.protection.outlook.com (10.13.176.251) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33 via Frontend Transport; Tue, 9 May 2023 04:52:08 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) 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; Mon, 8 May 2023 21:51:56 -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; Mon, 8 May 2023 21:51:56 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Mon, 8 May 2023 21:51:55 -0700 From: Nicolin Chen To: , CC: , , , , , , , , , , Subject: [PATCH RFC v4 1/4] iommu: Add set/unset_dev_user_data ops Date: Mon, 8 May 2023 21:51:47 -0700 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT078:EE_|PH7PR12MB6933:EE_ X-MS-Office365-Filtering-Correlation-Id: 40c8e7c2-1559-4be3-f825-08db5049250c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BsDvrWoEAkPALmw0TGPTuR4WDETZeWi0qMFRg0vLSfcAABT4qRl7kzgbnfwKQ/dbJ420NipPf4nwUSw1iSTx8aWJyEqP/5DSsM9PI+58HMTaCSTSCAz0fmhwjT1zx3MxRGvsi05w4uFuVdMPk+364QTTmUwLU0XvOoLaBRuAjNiRO2N1+rDymrOjzYLgD9vXXuL+d9JZS/mGcv+fUUT/9SVekFOdqcuux+ne1fOFtBg7bvFhLcyzRwA2cZswETG6kaLZu4xx++56pskhL1PqK2FyU2Z7AlFsG50tJ9G3REQNRXVmFGLHG8Vk/hvz48doUjG0yv39EOcq87dlGnEJzWKhTmjYKTGppxN7t5QxsEjWjTDTbgMpOah2hg1qyvwiNHpWGJFi9IkY0SfQf8i0sMK5H2voe2b3OdtOHBFjcJezc+omCls/EyGiO3roIjNPFDN2d6cY/l9lWO8zTp3r8pBycuMUZBIxNzvP/Em2x7/eowrMZFgmahm5W+f/l7ZGQ6+EutNA7N+GnRL2H5N0Kg0THxLejIqjPgDXB0acO9P24gRSUYUh/eKI4bMXvf4kcM1726xIyrDT8gN6GI9/dCrYxY6048UHecnenFmqBZ3PURi+qrueivmZIqiLTe+qwfh8alMZ7HF7ek6EoqfB72RnwyJGvbDs0r5EbuXTtbOt4ubUCdpaJyXhYyy4Bl4PnaWZN4W8n2naOmabUmml4A== 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)(39860400002)(346002)(396003)(136003)(376002)(451199021)(46966006)(36840700001)(40470700004)(82310400005)(7696005)(6666004)(5660300002)(7416002)(40460700003)(8936002)(8676002)(478600001)(54906003)(110136005)(82740400003)(7636003)(40480700001)(316002)(356005)(41300700001)(4326008)(36756003)(70586007)(70206006)(2616005)(86362001)(2906002)(186003)(83380400001)(47076005)(336012)(36860700001)(426003)(26005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2023 04:52:08.5623 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 40c8e7c2-1559-4be3-f825-08db5049250c 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: BN8NAM11FT078.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6933 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,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765392366865929161?= X-GMAIL-MSGID: =?utf-8?q?1765392366865929161?= 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 1131476017e2..1e1124f79b56 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -260,6 +260,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 @@ -307,6 +316,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 Tue May 9 04:51:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 91370 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2632766vqo; Mon, 8 May 2023 22:17:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4/yGth8ZB5bPTXslHZcwyVQ+dpaA9srOQowOJDYux+m4OQcZioHkdj0i9jGUpQvCfrqIpz X-Received: by 2002:a05:6a20:a129:b0:101:38f0:1a90 with SMTP id q41-20020a056a20a12900b0010138f01a90mr1584778pzk.1.1683609449472; Mon, 08 May 2023 22:17:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683609449; cv=pass; d=google.com; s=arc-20160816; b=oTymmPLavPVWbxxlNc/lHi5j43yEZwQ9JODHeGNe4QilvybYuBbyUsoOlHnrjTWTsg WPXCehcpPZ1eeUSPvs6+y1/c2Sxh5Anz7BQF6Mx/wFBG0vLU+aB3Jr0Fb59QmiNsiME7 EGkjl/bwg0V3S9O2CAn5xa2vn2GI9ug6sAZRyEdD+CAquCpkNK3A6skde+I9Tr+KxOJ9 TmhageDWc1bT0vqGKxIk5ydAatYbDbeW0KviJokEqwb7scLpy5BC0sVFQMdOOz3PCZ0s w/HsgnO9f2sxsgVvnS00iwuVphlcgp5dAJCUclZNxUAAfv5AG/6s92LywNd6wEfi0WDr 1BDg== 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=qqeG6xI/4LdEZnRI5ulmNiNG6l3Vbq04jAj6Uq86cFg=; b=MQ83qdE6UhSJVqH6jDj2GT4ez9VlGSQgIU08E4nUPUA4OIrZ9T5/GdNolVVq+h9RYH h046rW5EkG5m0Svquf0A960SsZhzevVb22hYIN3nVdjk7KN9bME05Rpgqtpsx2xCSdZV aT8mj1+Tqi3SVDTQOtwoo+RG6lXSmKKUCqyuZgFEX2wqe0D3E2McVwNcd0L749lLJX07 TyHTwyolzzIm4F3MJSgbdvOIzV4OEqLp6yOoaiKlGThodJK1VScQO8TDzmdUYG3OVtpp sEB3yqZS19xyH1VqHUoZ+9b514ynsQtKFmeGbW+EnNpmS1OdTixTDC2Rx4Oi85sTkmHN 8UEw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=lCjRO5lF; 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 d30-20020a63735e000000b0051394ccd19csi752587pgn.55.2023.05.08.22.17.16; Mon, 08 May 2023 22:17:29 -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=lCjRO5lF; 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 S233960AbjEIEw2 (ORCPT + 99 others); Tue, 9 May 2023 00:52:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229952AbjEIEwO (ORCPT ); Tue, 9 May 2023 00:52:14 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2058.outbound.protection.outlook.com [40.107.101.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE23730FB for ; Mon, 8 May 2023 21:52:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RU6Mzs1XGyRPhHlHic2XsPdm5+H1rMuUHlQdcDEV0ziUU4Qq67F5PYLLPziJL1SI3Qwz940QB+gWH+I9lAFO7zTjhyBETQq1tJJ8GS4G/RfOdn+DlT4F8aNaZ2xoaHBGrk3/BBQ+kG7YqCo5rojAMAuAOnoaL8W1vpljEuaGmERINHv8du8FjzVpqruPsFNevvaB2/w9HX61WiHiBJi/aYjEKbxZQFfuBZkrq6V9QW97VWgdyKqopyihz/J40jJ6fpQph08i1Ztlx8pSVLHZ7RaPzM1ToFfBjk16eV98r69YOgWt7HbBxibyMuydahg6VLW7/pT1rFl+dhyBWlr+kA== 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=qqeG6xI/4LdEZnRI5ulmNiNG6l3Vbq04jAj6Uq86cFg=; b=HqRDLwh5MGPhTjDPltHKLfhgzKBTez5ZmIVcG8u62jXL34pCVFk1LajOrGfBUmA69YehDgjQBLVHwLkWQGhgh4x8Ip/QQUc5F5DyTNMG+eYpqLUC5QUHx7EGt8wXPqJmduX3E5nFFuo/iqqriYZWA/ay1icvChVOcYgV6lrUwvxenN6fTVMwP/c3juLMzgR1E6rNN/zFR04tDf59Px1C9n7YiKKWtZ9PqwE0pnjKJHZHdlWR+lqm3982HjbVzqq56oVgqXm4YnFVyF3RH0dEJ9ujlNQZ/HrlbEBckG6FmnTTNfOpqU/gpAazWJ0OhmgWkNa0NGK4xaQw2O9dQ0fXBg== 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=qqeG6xI/4LdEZnRI5ulmNiNG6l3Vbq04jAj6Uq86cFg=; b=lCjRO5lF5nhbcgHqG9NSYKErPV/6VasC9jKaO0c1LVja2ASqsflYECNjr+SuGHn03+RILdwAG+JPMxCrjfclyzLbCwdDO9zwM+1l3+DvFmD1uYpV6+WhQs7Z8TSQMmAmq7LrQJJmLm09m3ANv84cY8KRZ+/lAqDoOZS0BvwK45/gGZmpE9VjIEMgXJ32cM8DUKxUx2KTlNshBWt4rjieQMA3zx4Ow3m9hgtKE01dUzmxyFK8NmjVXYVJmabZYWCUk1/jfoKz6Wglq//zkhBKz9vSG/XjLg4mbeL8bjO9cccUTwjhBzivh4+Wfc8zppxumrGX2kFLet4NXf6wCntHyA== Received: from DS7PR03CA0063.namprd03.prod.outlook.com (2603:10b6:5:3bb::8) 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.6363.33; Tue, 9 May 2023 04:52:10 +0000 Received: from DM6NAM11FT045.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3bb:cafe::5b) by DS7PR03CA0063.outlook.office365.com (2603:10b6:5:3bb::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32 via Frontend Transport; Tue, 9 May 2023 04:52:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by DM6NAM11FT045.mail.protection.outlook.com (10.13.173.123) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33 via Frontend Transport; Tue, 9 May 2023 04:52:09 +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; Mon, 8 May 2023 21:51:57 -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; Mon, 8 May 2023 21:51:57 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Mon, 8 May 2023 21:51:56 -0700 From: Nicolin Chen To: , CC: , , , , , , , , , , Subject: [PATCH RFC v4 2/4] iommufd: Add IOMMUFD_CMD_DEVICE_SET_DATA and IOMMUFD_CMD_DEVICE_UNSET_DATA Date: Mon, 8 May 2023 21:51:48 -0700 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT045:EE_|BY5PR12MB4131:EE_ X-MS-Office365-Filtering-Correlation-Id: f2681aa8-ab64-4eff-c843-08db5049259e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 119IYNbx6xjZ1wrJ5b9eDDNKQlzzoDPiHhiN3uRjvKvuiQv6Xjg8RGA/MtHFl+uk8r2Dam507Kaws7pYuffPP4bEg9UzvmhUXAuwFobD8dh6l/pTgCwyLppLQFMr3s3H7kjLHgubx6PVKt8LIO91ZQ74sG+XQa08tfyr7w8mSAa5BzDiR+nTSpG3hOFFnnhaHf3IGK+D6BOq2fuq/CgyowgpTbE/9S5RJGDXIxp2eghvtUOSgqcx9do7itCCJSJjiMm0ohPujzLB0l+3nv647e+2DxH35/ek2Bx+YmkTYe1HN8/+AtyzCmn6C44bxPO46p2tpjkrTPrcaclc5QIl2XfJRMn6CP1rpVEt5YndF6oIjHjh4kJagjFOMtpXFxar34hNJFqx1ivPGVzuAEes9qLiXSlijn00Q/UbvKhJmekDJ3P5iINGeDuDGcxXrT0ddK/dNz1NKsmJPpC1xn0TUTRG76EecibhzY4rmh3m+NFTbSHq37C3Gp4l9S6nmlATrrIewqUo04tWutVXCxTU/68Lkn5xl9FqMHlz5ueBLSmX0K4hRi3PO6lXx7bw/c08dWCmUFouQbB/h+nQYZW8AiNjEh7Ooy13U4Bs3Xz7cOf/X0QtYzWGSIR17OPwOJPPxDI8xB6o9cJENwbbJq9Lu7zljcmz5vV7QFCpV3F6kpHthzqECctjHwcvhMf+mNcA1VAIPIuIhLf01RmTv+JUiA== 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)(39860400002)(376002)(396003)(136003)(346002)(451199021)(46966006)(40470700004)(36840700001)(86362001)(36756003)(110136005)(54906003)(316002)(4326008)(70206006)(70586007)(478600001)(7696005)(6666004)(40480700001)(82310400005)(8936002)(5660300002)(8676002)(7416002)(2906002)(41300700001)(82740400003)(7636003)(356005)(186003)(2616005)(26005)(36860700001)(47076005)(336012)(426003)(83380400001)(40460700003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2023 04:52:09.5648 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f2681aa8-ab64-4eff-c843-08db5049259e 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: DM6NAM11FT045.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.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,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765392461749882489?= X-GMAIL-MSGID: =?utf-8?q?1765392461749882489?= 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 790e94baf11c..e40f576fdf0e 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 (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 6392f94af179..30f91ea1c5a5 100644 --- a/drivers/iommu/iommufd/main.c +++ b/drivers/iommu/iommufd/main.c @@ -324,6 +324,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 bc9b08baeb1e..8b4268107c66 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -48,6 +48,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, }; /** @@ -478,4 +480,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 Tue May 9 04:51:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 91373 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2636603vqo; Mon, 8 May 2023 22:28:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6L3m+A1p/ZGvnr18L9QkEFg34ccp6pQ23fMl5SaVSt1P0TzTW1A2jqutdgPSvH0aTu03vP X-Received: by 2002:a17:902:e888:b0:1ac:77f0:41c0 with SMTP id w8-20020a170902e88800b001ac77f041c0mr7047416plg.14.1683610126948; Mon, 08 May 2023 22:28:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683610126; cv=pass; d=google.com; s=arc-20160816; b=x6kPHFNgJZqrClTjPY+52MaeWWzg+7Dnh1bHcSkK7P9wRYPOaWmX/+Uv0YbLf5VXWp Om2ex3EvsWDTUvLM7UYk5BQw4T7fkoWJfTo1MiQh8Kl0ju75ld8IFCFWXVN1y0QMkCfM dk0Zh1j7kMV3dNKkZ4GgeSTqCIUxHadwrqL+6eemKIb3VNoqoYd03aQoZAYTrL0jv2Nj WT4PChY0G4gsgfk3MXTZ/8w8c5nSYr5vkgpoAZw8L5p2hyqlyNODc+9sva8Rws7nIkOl 52871saAz7GLonyLtNZw1Hx6BO+FSTajdDmavmGAbkDqJ0KMC3Z08MgO5/KdpbWJGKyr XDMQ== 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=whyV+1ypaFjM7PJhtYvdNFA55/krPie68ZvBso9S9go=; b=eNFvTfyw1saBQZp0AC3KcKaE/V+SxbOf9AjXkesPp854s1EUcw0HxVOx+Yzzp8+bxt 8vVgbjxSgNWHT6AXguiUxsaHk9BS3PvD/YGrLpvu1yOcY65o0O6Bs5Mkcq27681h+TEh ol8k8u9A8xqaDSFT/jiUPWppMwwDkvHYef9Fq7cyat0uJbUN7MqxYw3Y3qJlHQFgRyf+ Z5M1MKDuF7DrlN2QE1XPljObBDaPvcciMBTk10lJTT97yXkdNJUSefS1hD2zS7HV00zt 8cSLCq+W2kKjv6TXs5bjuYs4SJ46uBzRbEomeK//uC1wH9aYl0Pqklg7AfeD+pdNdwj9 ACUg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=C6WLYKK3; 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 b9-20020a170902a9c900b001ab1ba2572csi680285plr.240.2023.05.08.22.28.31; Mon, 08 May 2023 22:28:46 -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=C6WLYKK3; 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 S233835AbjEIEwg (ORCPT + 99 others); Tue, 9 May 2023 00:52:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233260AbjEIEwQ (ORCPT ); Tue, 9 May 2023 00:52:16 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2046.outbound.protection.outlook.com [40.107.94.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2BE930E3 for ; Mon, 8 May 2023 21:52:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E61OnIdanhN1/gWddEL2UJcOQCI+i3zpLT2ts8bK4uMmPn4KIaU8bzndGSdaDeKW4lOFKRIcCXUbuxluos34Slq+ojAGS5+9BhD3Z+QktHZBu8ubH95UMnF5Xb9MvsCs0X/YF9BDaa2DXz/k2deIRpPQdrOE6LwtMuH/E/CgGn+0X6Vjbbr53qKgXg/0qP8uDPgJQavBnhmOqezAvHkh5OPNRNr85Tj6S7ieasFvR/l9Z7AigY4JWMWUP+LGrDBC9r7uzdiVBx1tJkj/HotsQ23SQXYZ0nQOD/soUd9aGVWOLe/TpkhhRFEnz9NsgQKRh21onOiLAvYNUm5OIuUuvQ== 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=whyV+1ypaFjM7PJhtYvdNFA55/krPie68ZvBso9S9go=; b=jxltSW4nJ3G49QM6D8E9JofT1gcf0WVwrwl8zSj7CLzColnqS78PQF0KbXW2l8NfY+1tr9rfJtdpSXPnlcyg4KSKlcv9RtRjcyeDjDTY0IzdHYcI5N7Xjcfi7uw+XYtn6q4xkMgCqIO0x4fSU13YUYDm/LqYzKENnPSjSM02xeSt9kFcKJr+Zb0EReetoCGCZK7hnmTMoKXx+vslF2nvbgKf4JodKz9/UD4wz0CX5aH5h51wLgMrkiAhrUv3WE48UgXJJUUbOBsxhA7nINi1Xlv6MDCItkMZejNYvgqHEYt/bfNBIc9dRog+bWgkKCpGdNU2NnAIbwvirfh4PbFvzQ== 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=whyV+1ypaFjM7PJhtYvdNFA55/krPie68ZvBso9S9go=; b=C6WLYKK3V1xUL9JKGZkw03d610Y7zDAm9itkgv9qwL3adJtyCcWxrslXk5oTDvGz1yLwWMfArT2J2TZ+aqYjAD/zW+eD/xdYRAu/BR1kNVn1WQq3RFfostBDxuox7cNreWLROJpaOcRBLUQJPTrobJ7TRl2A8jFeXuZayiKzTP3BQHMHmeEgOpM7QG+cTDD13lFtUSGvzLRW0fJJOnlr6RQF8nGbmXpYC0XGBzhWMj9IP5Zs1sT7A8LZhlTzfvuoQ5LjKMeJ6ibt6nAzKrWyjoJxNCj8RHocelJCdMEqM1LS4yaCtos8GuoatHxjcbiSk7oj2xWEZ8OUThkjEU25+w== Received: from SJ0PR13CA0183.namprd13.prod.outlook.com (2603:10b6:a03:2c3::8) by PH7PR12MB6468.namprd12.prod.outlook.com (2603:10b6:510:1f4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.30; Tue, 9 May 2023 04:52:13 +0000 Received: from DM6NAM11FT088.eop-nam11.prod.protection.outlook.com (2603:10b6:a03:2c3:cafe::96) by SJ0PR13CA0183.outlook.office365.com (2603:10b6:a03:2c3::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.17 via Frontend Transport; Tue, 9 May 2023 04:52:13 +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 DM6NAM11FT088.mail.protection.outlook.com (10.13.172.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33 via Frontend Transport; Tue, 9 May 2023 04:52:12 +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; Mon, 8 May 2023 21:51:59 -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; Mon, 8 May 2023 21:51:58 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Mon, 8 May 2023 21:51:57 -0700 From: Nicolin Chen To: , CC: , , , , , , , , , , Subject: [PATCH RFC v4 3/4] iommufd/selftest: Add IOMMU_TEST_OP_DEV_CHECK_DATA Date: Mon, 8 May 2023 21:51:49 -0700 Message-ID: <0783fcf9eca9fa2dc462a43574c4a0ab76d367fa.1683593949.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT088:EE_|PH7PR12MB6468:EE_ X-MS-Office365-Filtering-Correlation-Id: d394e0a6-5261-46a0-80a5-08db50492764 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +pDoeb5qJYDzopixgg2oDEuJ5jNj12Zus0PyYUsZmHjsjo4bLjIUXR+YEmGw0C6qE+j/7IdbagkR5NXx2M6uob6bgzZOXUv+DOmVhgkwMDAtP3FRhIGclsSJo7AqDAQzgpdv6rLLrn0pbmsiAGphXcVkW71mw1ebGz8PFnI3FzGNFH6EAp+ZWxZgzP+fEsfI3ed+MnrPL1VYSvWkSeA3LeUgnyyDt1o3tZDAo+1GL8w5YXhGMmRDf3dGdVPmfrM6eoA+bWyWiih3ZWazbMTe86UC6kuhxxEAq1/t9AEaV5qBoh/SQ/i+2X2Jz3UQMs67yQShBpzJmA8+FSxx5SIr0BbT2czAKML3aHd8ei5v4f+qVfzgHVxVAIZjjynh+Up6O6mNAf0JU9uB099pS9Owiv6ominn/Qrr44HsoldDkrpzaOvF6EtaOzhYmtw6IWItGsiOxc7VKWQq1Wv7XIBPTaZi4iKwEGbd3II9k/S1bzHOi6IF8EaCteDdZ/FZ7G8qCYL6P0bCL4H2qQxFvlQQehuOgCGg0s4fDb9ImUebjK9XLOD5emoRA1sC7Jas/qfBHrkCZbjnDq8uph+lPZAI+Dearr2JOnlZyvtA5iKvz3qJHda2tCOuHutsmz8T+B22sIwb/5aEmSLhluIfQXMQD1XtCaPGF6zIRYB0blWRc2ZoH7kHWlqs95YniMkKxYGmk3okJ31Hg0SlASMg2f5fhg== 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)(346002)(376002)(136003)(39860400002)(451199021)(36840700001)(46966006)(40470700004)(4326008)(41300700001)(70586007)(8676002)(316002)(70206006)(356005)(2906002)(40480700001)(7416002)(40460700003)(5660300002)(82740400003)(8936002)(7696005)(36860700001)(26005)(83380400001)(6666004)(426003)(7636003)(82310400005)(47076005)(186003)(336012)(36756003)(2616005)(478600001)(54906003)(86362001)(110136005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2023 04:52:12.5227 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d394e0a6-5261-46a0-80a5-08db50492764 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: DM6NAM11FT088.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6468 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,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765393172641974758?= X-GMAIL-MSGID: =?utf-8?q?1765393172641974758?= 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 99db8ee9daee..10a04631797c 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 0xdead #define IOMMU_HWPT_TYPE_BITMAP_SELFTTEST U64_MAX diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index dbc5cc44c80e..ba3b578ac5a6 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; +} + /* * Note that having IOMMU_HWPT_TYPE_SELFTTEST (0xdead) ends up with a very large * array. But this simplifies the core when handling the user data. And the size @@ -353,6 +371,9 @@ static const struct iommu_ops mock_ops = { .domain_alloc_user_data_len = mock_domain_user_data_len, .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, @@ -717,6 +738,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; @@ -1133,6 +1172,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 Tue May 9 04:51:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 91371 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2634455vqo; Mon, 8 May 2023 22:22:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5JIwTHWIi3y/e2EnjhrVlUb63xfwraoUoqvEzpAymogO1wiI7D0pbGuUnmZORfy+hhDz10 X-Received: by 2002:a05:6a20:7348:b0:db:b7:fe3f with SMTP id v8-20020a056a20734800b000db00b7fe3fmr16430932pzc.10.1683609739574; Mon, 08 May 2023 22:22:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683609739; cv=pass; d=google.com; s=arc-20160816; b=gINC33WqWqbfmH/jpl6//l0Bal4IfT5GUp9hBbJRiu73uNqq3U/r4mAlRNOKfT9xv8 4dRPVGXFUZ7fLLXFHFkQrGS9yeocHrc45QTflaIfQNhgv58jwCr3lA0kYG74yYqi9kqY apsNNouI/NfP1Of5AHqGz2u2SJSGVbIL1WoinVAg5rQtDDpc2MUiWRSvUEPO9FBhRevo QEhCaVOy7m3vokE+cWkjE6HDjabdjhq9n7cdzoBeRIRXASS5bsJsnsqeUwLC4m3zEM83 Rt34NID29N0NOROAJMyBYcP6WYoyOwvHRWaYRLxjc2WMEedC8HIXUEbEU6dKqo5LX3my Zcdw== 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=f94slq4ZIEql9YvVc/21MmU11JQ0VTeFHEumHYXAy/Y=; b=z/9iNJVQysaN6Z5nkpZWwmyUJpqtC8YRgeQNEQBQYX8mPg6LQHMfap04WUnbW7YeUw oXD4rnAyv057XOGRIIG7Yu/OwGmYF08I7zHA1nwfXFBZEsoBiyu1XM+JquFnDOH112g6 LtZmNoa2mpmxwB2mWBYnn6v9/mfLm1J9i2O2xkHwteQ00/PaSDbK2vY2rAlHO7wcy/La yxBfhRjKI96c2tO6REce7SZT9y2KO2HjbQKwwFraUTw1k+2NQ2ueJnFpSPj3GYgtdhcS 86Cycp+stPxVGC0f05h+4315GsuT/boKbiF8mmRVwCshY6wc/5mykj/thya0nm8jBBQx dd4g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=e6HI3IxQ; 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 u190-20020a6385c7000000b00525037a363asi737606pgd.328.2023.05.08.22.22.06; Mon, 08 May 2023 22:22:19 -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=e6HI3IxQ; 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 S234413AbjEIEwc (ORCPT + 99 others); Tue, 9 May 2023 00:52:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232511AbjEIEwP (ORCPT ); Tue, 9 May 2023 00:52:15 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4737230F7 for ; Mon, 8 May 2023 21:52:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bCed5Epf8IpeykM7XT2Dh5/r12X5SDa28V7XUlUKNbdTpWvx6ElDLcIUF9qHME15S9pQ761Ra4NcM1GWPHTJF6n1P27maW0dNPz5FPnRyq7iE4AsV4caxZ5Y6ph+kkYQMoLJTQ/KlkfKfKqd79S3CWKh8IYlZ8d6K/Ty/8BstZWsJZryUhTcOB6p8yMS8Hp0w6Fyw82RglpdP36+D5WWq7d4S2qSh2PTfGkpbvp4cqRYSXIrq1ubboAsNumBUrOqQharrODJ3MITVMrudH7wdSf5wIxefh6ZRjqk3A4dVnBFsaoIVHwtHb9qiXlV/v6CBsHdIikg3wlfgJXg0I27gA== 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=f94slq4ZIEql9YvVc/21MmU11JQ0VTeFHEumHYXAy/Y=; b=Sglh6W4WzXY4fRGz28ZiEObDf4l2XdSK0s8DAPAvScbf9u3s69V46TLvM/uBDa7LXMwv3IlR8E6NKVOftu768jGH0MiPHR6BvnNNVr6w33yaXXymIBVICD/ho1C70zsMROiutXws9g1No74TYuYjGlIjjRcg02COcCb7Cx7ls674Cr4yPFYGi8ADdzQwTPZqCuPv9TyDPVTBQJEc1kd6F4gKfWIXcuThDx/v079kVjICfEd3LhCEeFeqVpiCiV/2aNwSBrglNg/dOR6fXptO/tV3ScYThqBZTY9oat65P6hEfxtxtohp26azfPnTd+NuusGWhnVNsmjfN6nHXVLhwA== 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=f94slq4ZIEql9YvVc/21MmU11JQ0VTeFHEumHYXAy/Y=; b=e6HI3IxQw3qq5TLKdUK2XCEwYGedd/Ap3pNSklZAwTqkDVXZWEM8Tscu9wqRuU03uDC/YJorrwY7XK+coKlXK1yPxES12mD2ubTqUu/JO8ZbTh1RWUjlQeh7QcmFTaugXTI/wE+HCRS7x1lf4KjzBqZsui8ikw/4xrLk4lRShtYf0BaNj4P7Y8AU0Q2juCCrOYDMxlk7yiP3Ete74aH+3myZxChnVWaTpgXUg/+GFKJuHg/HoY+N5cjy83ydtPvzLok4lKVlpIi/sjMX/w+iDOAqYpBnm8WUGvn7P82Vz9/b6fuDEnwSxTgEcIKmVi0hQSicakUH5zphjxV537ePhw== Received: from BN9PR03CA0727.namprd03.prod.outlook.com (2603:10b6:408:110::12) by DM4PR12MB7741.namprd12.prod.outlook.com (2603:10b6:8:103::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32; Tue, 9 May 2023 04:52:12 +0000 Received: from BN8NAM11FT040.eop-nam11.prod.protection.outlook.com (2603:10b6:408:110:cafe::1d) by BN9PR03CA0727.outlook.office365.com (2603:10b6:408:110::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33 via Frontend Transport; Tue, 9 May 2023 04:52:12 +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 BN8NAM11FT040.mail.protection.outlook.com (10.13.177.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33 via Frontend Transport; Tue, 9 May 2023 04:52:11 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) 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; Mon, 8 May 2023 21:52:00 -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; Mon, 8 May 2023 21:52:00 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Mon, 8 May 2023 21:51:59 -0700 From: Nicolin Chen To: , CC: , , , , , , , , , , Subject: [PATCH RFC v4 4/4] iommufd/selftests: Add coverage for IOMMU_DEVICE_SET/UNSET_DATA Date: Mon, 8 May 2023 21:51:50 -0700 Message-ID: <688dc847fd15e92c9fadd72d1dc92c2f15161606.1683593949.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT040:EE_|DM4PR12MB7741:EE_ X-MS-Office365-Filtering-Correlation-Id: 151435a1-5270-44b8-f685-08db5049269d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r0a/ao+ykzGe+/YwzsTcVX2fl3E8QDvpiJEgO+ArRLDk9bgZoVYqi/m+x49exiRWFvLkweeuKWyAdUrV+mFIrErEmCVoWxPtcRlkX0R18p8/i2PAmErY6f1bwlD4p2DgFMSddC55N4WvkKyZFLg0IyjEcOedVDSnztSm++aEjHc5v+nrFSQnij9yO+URnwlfl/TYdDTxnrlqVJBm45VfAwGatji3kXT4e26fylZwx68beuOkmy3nEBKA9LVeUFNEfhhzwlmynI2tVKgYx4oJvPuCadNXzwCwvcK9ZiP5jw1mssVc962lFH3YWgwx3W1ochN29QEYoCC5lI1OfREDiBZ2ZCVjHNSC3zD412v6G3khqBbaDTsBB3+mQ2ytn3MzmHP048wZw08fH6vfrl83nada2y7pBkpBYykLZqmUK133UL0/JT5c2IdfGVnHKQ0iIUAUCUReeusr7xpnTLGhZXwj6FHZGPOrHE3IsTRd8996/yGzP+R/VxEvLNhuQuNl3rA4GhsRT+LaFLqHJxa3UEp0cW6x3nReP84/CGj48QgZkk6c7ihBlJ6jx/xeqT+dTl2aOOMccg9yZbcDo9B6TuQBz2ZtTvxGabT+1b1xMONovJRhsNYWtr4xLkUgjvBzNT3z1i1pDn73jD3nMBWUK4N8lx/7slWwsqUfMyxEcRjxf83xKzmwp+ZZdtvSQ77GU6kuc5GgjuRJUIycNRHpcQ== 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)(396003)(346002)(39860400002)(376002)(451199021)(36840700001)(40470700004)(46966006)(336012)(36756003)(86362001)(54906003)(110136005)(478600001)(70206006)(4326008)(6666004)(70586007)(7696005)(316002)(82310400005)(40480700001)(8936002)(41300700001)(7416002)(8676002)(5660300002)(2906002)(186003)(356005)(7636003)(82740400003)(83380400001)(2616005)(26005)(36860700001)(47076005)(426003)(40460700003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2023 04:52:11.1903 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 151435a1-5270-44b8-f685-08db5049269d 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: BN8NAM11FT040.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7741 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,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765392766429187213?= X-GMAIL-MSGID: =?utf-8?q?1765392766429187213?= 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 031e222cebf9..2987e8603418 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -1517,6 +1517,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 fef17fb46160..487d45c29c6d 100644 --- a/tools/testing/selftests/iommu/iommufd_utils.h +++ b/tools/testing/selftests/iommu/iommufd_utils.h @@ -444,3 +444,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))