From patchwork Thu Jul 27 21:09:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 127214 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp41207vqg; Thu, 27 Jul 2023 15:15:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlGbKBVXhQMumJ2Ehci0NNkqmhfAqjENs3lrXKao/bCnEQ7QSKDYqy0xk3Spl9gN4cxZ4IBs X-Received: by 2002:a17:902:744c:b0:1b8:1bac:3782 with SMTP id e12-20020a170902744c00b001b81bac3782mr595805plt.6.1690496136611; Thu, 27 Jul 2023 15:15:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1690496136; cv=pass; d=google.com; s=arc-20160816; b=0JXYa6l2OV/bNZMH6XWwPxQ/gmVQ43rGCcuSxATO24goLrM7IB68+Gzxy7fKDLZxjk oUwAaMFLjfrmY2Y81oTBfXNawaGngLHgF13MUzMPC6pwwEBqN/2o3zMK0YGEr9hF8ed6 sUAgHj8CvQUQFF3R3GpxNxjoqxL9NoxiBdR3tXDhc2mrJdxdooIEVuqkGGphWBdpUfhX pbU98aT9QR0UOXzKLrGEqP4GckkfHYMi5X95Gu1gZBZDGKJW8QivsLmi9zDiJA/hKt/x Kb8ZXZIVolfYKBWRLH+H2Gr9fusgTfJh3Fv7QBdDEHWOdA0nY0kQRbrjtch98QCWdvqq vZVw== 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=Ri7L3Hw/A5KeDrdH3l0dkLhCMQTNk23gWQFUjAXFL1o=; fh=ULXK5IZ3LFNv7cj0QeIPGDeVQmCtgYU3woQ+rdcEpbI=; b=0j3ek5nhr+L7E0m8qf6jIy5PC7XPj5g/iWgh5lH/4plTqdpkydsn5YYafZKHZMxbY8 Rt/vqvbptHImuPuQ1QkR1FEd0nj7tCT25KaUB6LgK7YC0kA0atYUmgU+sMd4zgvygB9g WNn0GPzPU/YEY2hTCSGg18zqj6lTsGHYU3XPD/lz4wwNYOemHAfONZXgUAF6g4rfNkQs 1OWwS4sZY16IiLo77zAZKOJmM+9j+KQoDVJJj1IAfQ5X0kyqyBi+lVTEbIgqg0mu76Cx QLvZccNM3c5cq6bPquyK2DGN7klRR1Qk9PfD5RwigMbSRqeTJvi+V4DE8z2vcKWAQBO0 S1/w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=X7gLSfff; 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 e15-20020a17090301cf00b001ac6d4e1d72si1892106plh.149.2023.07.27.15.15.23; Thu, 27 Jul 2023 15:15:36 -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=X7gLSfff; 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 S230379AbjG0VKW (ORCPT + 99 others); Thu, 27 Jul 2023 17:10:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229965AbjG0VKN (ORCPT ); Thu, 27 Jul 2023 17:10:13 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D965D30DC for ; Thu, 27 Jul 2023 14:10:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aPktB2Xbk53KJ/0QScfStOI2DhRVPJWC+DAylmg5uYicofbTBQuLOOthvQR4XtsSJJv2Lflgivr2hA6uuqkZIwKxRA2LVFeSyZDubZTN4NpJZWk6ayv6Q6jFEJj1Eeib4S87Ss2Yf8QhY2pXMNtnqXXZ2Rvi/3AqR0N6eRuZ3SF8M+pzlYFUuDpUDrxu/H7BGHJI85iLhECvnv5caj7ffHcGVY0YAG/Xj6XXRrWbz3JULgH4T+WTwc+kNLE+56VtlKvFwP26oKLJhC8XxE++cs1ypKceAGMJMEBfBj38sDMyXeabApaniMFSxn84xV5i5Mu1/OlcyzGXw+dYbJCcpA== 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=Ri7L3Hw/A5KeDrdH3l0dkLhCMQTNk23gWQFUjAXFL1o=; b=mCHNVkPO9OMIDoZ6ZCKEIILknNbL9B8hyZPxupKun194je1tKKiTJhbYyjBM8rISvt12akhaPnfFNGyDQVVh3IDh0MbyFudN1vD7XZnuzngGdPBeaV0QnOn9XOJppHCX7YKCIBe+7lo9aNtNdUI4cEPkk6C/yNJZEYCiSVwcUfKWhikIzecSfTc+gMUhnQ530ZFiAQDgAwmFELXNEd1f8z9DUxgHfnGk0pBc9bZZ6M+nz/IJ8v+Rad6YWuh7AlxfJs5GmDC/f76tQ2J0zHKhO6LuaNIU1MYst+4NFRM94mvE6zeqkuNMEnQq+Ck4bA9M7EC8ig7HBzVzgcxtLb592A== 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=Ri7L3Hw/A5KeDrdH3l0dkLhCMQTNk23gWQFUjAXFL1o=; b=X7gLSfffnCuYovbJNRoEpTIzdA86eJj90RHZH28dotUsHSHCgkS0OxHmaCAjZb3u1UJTPVZy+6n5F3qhuvFhOXJL8w1G9GkTpXxts1WUzWtpVpCXRJsI8XlFHLZqyRCKTsjvFLmqY3r0/4NjIzU0GKwFF5Bv9rDYEoOKzFGsBKyRPk6s2Nwwov0WiEUwLrAbKwQPHxk7lNmq1XTpgrdZjEqGWIStIWS2Qk3FzL12yI4Ad+CvPYBWMwMNtwYlrZfUcdzC690yiUxJ8r9eYoiPNIj290C9YeQNDAzQRnHBSdIrKp2uvijp7o1dcWSCWLuRCx91aqIpvGnl+w3i0ZQ5ag== Received: from DM6PR03CA0076.namprd03.prod.outlook.com (2603:10b6:5:333::9) by DM6PR12MB4436.namprd12.prod.outlook.com (2603:10b6:5:2a3::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Thu, 27 Jul 2023 21:10:09 +0000 Received: from DM6NAM11FT010.eop-nam11.prod.protection.outlook.com (2603:10b6:5:333:cafe::c2) by DM6PR03CA0076.outlook.office365.com (2603:10b6:5:333::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29 via Frontend Transport; Thu, 27 Jul 2023 21:10:09 +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 DM6NAM11FT010.mail.protection.outlook.com (10.13.172.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29 via Frontend Transport; Thu, 27 Jul 2023 21:10:09 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) 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; Thu, 27 Jul 2023 14:10:01 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Thu, 27 Jul 2023 14:10:00 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.13) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Thu, 27 Jul 2023 14:10:00 -0700 From: Nicolin Chen To: , CC: , , , , , , , , , , Subject: [PATCH v5 1/4] iommu: Add set/unset_dev_user_data ops Date: Thu, 27 Jul 2023 14:09:40 -0700 Message-ID: <6772ccfb71cd1eb3d402d82836ae7e98a853a793.1690487690.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT010:EE_|DM6PR12MB4436:EE_ X-MS-Office365-Filtering-Correlation-Id: 4aa2da08-4126-4f0f-8a98-08db8ee5dc0d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7T05ls9kJ24Zsidefw9jYSUw22VJ6gIcXkYLaD5OCKh8MVdhBs7JbP+Xmu9Mm6a1VSj11E09WNhyHKyAP3nckjHQABf0YyXI1FJYev3R3HbHRc3ZhlxXs4pb5CsFL41kkRSr7uJEL2ghjSBttBYoP1QhCs8HgjxNQQyIsvZCMgRUFm+cO39zSHdBXBIbdNn/Ma0jJPopVsDeY28WiAeCb34Dus0BOgPQF7qRag/3kXropz9b5TeYr4/6nlCOoNdzmmb8oM+9eerfS3jHGg3pWeyKZ1iJO/RaDljnta69dBWYSo824itH65zubnGybaiIuAtc4zZe1A6rVwhnFClHdMxdNWuSkvOJ1pz2QtFWP9iXz+vbheyMS1CXuhOtckBFxeNo1QkGOr6cZKvEqGT084aPdCnSwRLlqgsy7yhf+2vZPnOTgXGK4APxz5boFyovyVuMAc7yT1uOkyc/IFmbKeFkxXE6V+GpeC7GJdraKhFPRq5ALXwwnovN5zeCMjj2mgjN9m1B+PGpxk4RKq62CrCg45N8fVSVs3Zrhm+eHMOEz3mfkU4iaW6HjTOMA4q9u5ex7JBFnegLYLB8RfZdZ3CHG48K/8A/g+yyjTh2YqERHueg+/VFM2GLZKX6pHWE5Hqr4Soq/HPtpzU4NL73jpzY/5bV+1UIcBPx4AnTsmoM9yblNFJHbyOt6Dx40GUPSQyWHPL+72rgXcsDwKRTtL02wcBw5pJV+viYLYWZgq8GdhH3cMpeJqnp0LQToC2H 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)(396003)(136003)(346002)(39860400002)(376002)(82310400008)(451199021)(36840700001)(40470700004)(46966006)(83380400001)(36860700001)(478600001)(5660300002)(110136005)(54906003)(47076005)(8676002)(7416002)(8936002)(36756003)(86362001)(426003)(2906002)(41300700001)(2616005)(7636003)(70586007)(40480700001)(70206006)(356005)(316002)(4326008)(40460700003)(336012)(7696005)(26005)(6666004)(82740400003)(186003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2023 21:10:09.2024 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4aa2da08-4126-4f0f-8a98-08db8ee5dc0d 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: DM6NAM11FT010.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4436 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772613676866105379 X-GMAIL-MSGID: 1772613676866105379 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 e4835230d5f0..231920efab84 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -281,6 +281,15 @@ union iommu_domain_user_data { * @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 @@ -326,6 +335,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 pgsize_bitmap; From patchwork Thu Jul 27 21:09:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 127191 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp22151vqg; Thu, 27 Jul 2023 14:31:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlE10sD05+BfKJvjPSeB2NT6UBoye26lYarqKo4Lv5HPbIqejxF6rS95Qd+YxR5rzOnBhSRk X-Received: by 2002:a05:6a20:d40a:b0:137:40ba:d91f with SMTP id il10-20020a056a20d40a00b0013740bad91fmr298120pzb.10.1690493476799; Thu, 27 Jul 2023 14:31:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1690493476; cv=pass; d=google.com; s=arc-20160816; b=oC9qmZBOExpL4pWr1KyBF5MoGKov1C2L4CkCqNsgsh6tWpexEx1uTYJgNQckzYEu0b lnK6x02yudhtPIqdHsQ/8Drh9212nHg3h0ZOWo76PDGakXsY2pOA6kfoRH86y9u9AHzt IP1Apd3kNDVXU06HbncucaBnUSit6CWkRgzIaus6kd4kUoSG0aBbOeHmXC6bYQ6lFXkF 7qh/lH7otNzweC2mcXMAsmJbcD7h1g8ywzrtfUDd6u+DvKsONNuDMonk9U0H2WwV0i36 lQsGy7YhTbFuhzc5cYUecs8zfqYItVvehS7kTGwIiiby6e28eCUI0noyd1rg7uRfjutV X4dw== 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=TPtzgSNN1DVBfV1HRnOQyh1oJme15U55RGAgDKNIn4I=; fh=ULXK5IZ3LFNv7cj0QeIPGDeVQmCtgYU3woQ+rdcEpbI=; b=lKQaf3IJ4LGea5Lt6vESmX8Yn25Dvu9Q+QkYYJHd27g+SerHhIhdyP90Us2GccnTL9 x9zstsp2t0FIWieGH5S+jYG9KYpuuiH0tBbdSsY2R+VV0q+3OAMD2nLDhKdL4XfguXB7 mBGd8GmIDYN/PeD3dRY14tMQKvheZEOkUqC7HU6d+C5LRxB2i2ah1kRF5wOFVTZTIlKz Jhj51wcPmqtCIc+rbClhasp8XhgMQoTnB8OYEpiaKRkx7QwOo8NPisnC00BV+xB7Caww dSLY7iDyRG1fdO624lshIZ2DrXXlwfJ/xhu4YKnYcKrEckkLDBbgdZEii/tZ0QbYqf7V xrpw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=hJ1SaDlm; 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 n127-20020a632785000000b00542abcf2ce4si1812580pgn.623.2023.07.27.14.31.03; Thu, 27 Jul 2023 14:31:16 -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=hJ1SaDlm; 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 S232119AbjG0VKg (ORCPT + 99 others); Thu, 27 Jul 2023 17:10:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230385AbjG0VKW (ORCPT ); Thu, 27 Jul 2023 17:10:22 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2049.outbound.protection.outlook.com [40.107.220.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E69C230E1 for ; Thu, 27 Jul 2023 14:10:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ntA5uPuwtrQYbVfBHVm+Hhn+2nXugfDZ4ikxu/4Y7yG31Mq+rS5cfYanDxkrnuz1xjBNTnMjGrOGpl8YyG4gVNH/yxN/d60rIi4AgeromLNWLSYbOuTmdzy5fpW/2MtocCfUJJkmQPZ9MrqTxQdRf0nzOi5oJP8zYKy378aS2a6Jw7lxhc1rK/oMPrkjh5OORiOx02n8AAJSLVXfynn6iGcrEKl2onogQgYN30nUBUzuct/3xBu96UWlk7t2qrcWBVKMg4kie8eG5Dk5IK2T7ALBRZb5iwRiwa+hqBPRSpB3JamqUcH1LQq06sZ9dAyFVk2ATtIW9vLMSqjlDWfZtg== 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=TPtzgSNN1DVBfV1HRnOQyh1oJme15U55RGAgDKNIn4I=; b=R30j6LMZJlrfdz8UJzWvd+zIpFM1GV7zvVcLT6Dt+P54Zb4RVNoBFVL3KS4WoX1PVNzlT8JnMFCCX0tJeeqPZ2Fg5DufQ9HwYt1m0HXfMyRp2J9LVJzys33AHRrXSUnwuO31FzOvk7e0IAswK/zMjVYW7MnzVGNWHoSNA2Ju5mvWoMGVCNhxR3OQ2h3QK1fbyN1MUc7W4tvYrUIORiwWxGmeGOnJ169C91Qi8wRcMnq8+q3Q/YX4A93SoE4KnHYvilj1sejOnOlSnrHRNL7EbF+Dt8PWfTL7ZFbm099nLdxxphM86CgzsDjG5KqToK1uH9YaFk4EEkCXuWzpZRCZFg== 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=TPtzgSNN1DVBfV1HRnOQyh1oJme15U55RGAgDKNIn4I=; b=hJ1SaDlmRZ2tfT6BE70k/GzlRdaGCpR+ITuGXJRSVU15uaecEVxNiRICqLbQk1KMIIxWdIcAxvj9AQV8Ao1shTcsfdYaDD2H8Musg3hVg9iKN6iQnjuHP3rYzUNjAHWkU7iGQM4wBOOhM1emZhzdH7Dmk97fP3x1FdSQjU6/RdkryhE664QdIbr1QXKgXTkOpmmHXeuCCNQhEy8Eq15Ytxf0jUcpYRZEec8trtMG14s2kHqnfuUV7oJgrjsL+LUlEL5yBp/dJmFiOV0+EcbqkdhIKHp1KLwJyC8ztGE9853ZfbNXF6wGmaFoIJ+R+/0p4Ox3Bw8ksBDK5LUP5+FIVg== Received: from DM5PR07CA0061.namprd07.prod.outlook.com (2603:10b6:4:ad::26) by DM6PR12MB4122.namprd12.prod.outlook.com (2603:10b6:5:214::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Thu, 27 Jul 2023 21:10:15 +0000 Received: from DM6NAM11FT115.eop-nam11.prod.protection.outlook.com (2603:10b6:4:ad:cafe::3d) by DM5PR07CA0061.outlook.office365.com (2603:10b6:4:ad::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29 via Frontend Transport; Thu, 27 Jul 2023 21:10:15 +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 DM6NAM11FT115.mail.protection.outlook.com (10.13.173.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29 via Frontend Transport; Thu, 27 Jul 2023 21:10:15 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Thu, 27 Jul 2023 14:10:02 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Thu, 27 Jul 2023 14:10:02 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.13) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Thu, 27 Jul 2023 14:10:01 -0700 From: Nicolin Chen To: , CC: , , , , , , , , , , Subject: [PATCH v5 2/4] iommufd: Add IOMMUFD_CMD_SET_DEV_DATA and IOMMUFD_CMD_UNSET_DEV_DATA Date: Thu, 27 Jul 2023 14:09:41 -0700 Message-ID: <664cae4552da90eceacf02cf00bd29183cd1960b.1690487690.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT115:EE_|DM6PR12MB4122:EE_ X-MS-Office365-Filtering-Correlation-Id: 09a0c027-147e-4ffa-d1b3-08db8ee5df9c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TLEz+9/Vs2xamO8UtBAmS2ORWJaXN3AYH9SwWvACIdY4GOQn5f3Ma1XaGndaCJpo9N5nJpkydKSDKrtSbLJ28fbtkTeF6yFBag5GwlAgG5g7U7GLCwdY8ZoC5EkGRVbUhdg+rAl1OLONUvpzw5nNVpkYM3baTDgNrK4e+7CQNQiLUVi4q3vrlzovvxGuTOr9Kz1uQ8H7C/InTOZgqH9ZRNMndNqf3Ru7iDrGU5RMpXPJ/G96UlC9QHwYn1PsuhUevTtG71mus1g8gRsx1wC27zwdq5deLlmlPODOh1UMQO52yAurZWe9zUSBvBC2TRDU4sN0sy+iQsczKDq9ZB+R2SmPF75ufNZdXRmLQxvo3xnNB0/z8u9t6yETTaBr5WbabVsBcguKo//6jYCAySU2cXuSQRlnTCp2i/NPhHKYAry8tstV9WJRrHV5ZPZWmT1YbXsXmWpCyJXN7aerWEehrD3g//pNV6Rjzr33I3+iIF3TIv8Wq9gETKSuKD0NNc62lYqafNdW5RwnDj+Kok6ExQKwgp0ow4R2z+c37TKnwIN02UVSS19ndFddKGWiHsWYAJ0xL5+rTtRWtg8VIp4B553FNCFzgm3Ea9t26ASfp3Hjbc0har9nn0qeVjuKyZ6FrUhu10CxiRHSWDi/be6VbVuOMo1op1B0Hb4Y0iHv2wYdKgOC+XehSN3Pk+I+T5CcSsk7X7jlv8+LAyqLZXs3GZzILr2GaIg7Gav3zIU8EFwuZCoq7BVQSPwca9iAT49O X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(136003)(396003)(346002)(376002)(39860400002)(451199021)(82310400008)(36840700001)(40470700004)(46966006)(83380400001)(5660300002)(36860700001)(478600001)(54906003)(110136005)(356005)(47076005)(8676002)(8936002)(426003)(36756003)(41300700001)(2616005)(2906002)(40480700001)(7636003)(4326008)(70206006)(86362001)(70586007)(316002)(26005)(40460700003)(7696005)(82740400003)(336012)(186003)(6666004)(7416002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2023 21:10:15.1746 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 09a0c027-147e-4ffa-d1b3-08db8ee5df9c 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: DM6NAM11FT115.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4122 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772610887644345086 X-GMAIL-MSGID: 1772610887644345086 Add a new pair of ioctls to allow user space to set and unset its iommu- specific device data at the iommu that a passthrough device is behind. 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 | 2 + drivers/iommu/iommufd/iommufd_private.h | 1 + drivers/iommu/iommufd/main.c | 85 +++++++++++++++++++++++++ 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 7f238c583b61..37a234371645 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)) diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index 9ae6edea697f..b8abf664d3f8 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -313,6 +313,7 @@ struct iommufd_device { /* always the physical device */ struct device *dev; bool enforce_cache_coherency; + bool has_user_data; }; static inline struct iommufd_device * diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c index 255e8a3c5b0e..d49837397dfa 100644 --- a/drivers/iommu/iommufd/main.c +++ b/drivers/iommu/iommufd/main.c @@ -387,6 +387,85 @@ static int iommufd_option(struct iommufd_ucmd *ucmd) return 0; } +static int iommufd_set_dev_data(struct iommufd_ucmd *ucmd) +{ + struct iommu_set_dev_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; +} + +static int iommufd_unset_dev_data(struct iommufd_ucmd *ucmd) +{ + struct iommu_unset_dev_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; +} + union ucmd_buffer { struct iommu_destroy destroy; struct iommu_hw_info info; @@ -400,6 +479,8 @@ union ucmd_buffer { struct iommu_ioas_unmap unmap; struct iommu_option option; struct iommu_resv_iova_ranges resv_ranges; + struct iommu_set_dev_data set_dev_data; + struct iommu_unset_dev_data unset_dev_data; struct iommu_vfio_ioas vfio_ioas; #ifdef CONFIG_IOMMUFD_TEST struct iommu_test_cmd test; @@ -446,6 +527,10 @@ static const struct iommufd_ioctl_op iommufd_ioctl_ops[] = { val64), IOCTL_OP(IOMMU_RESV_IOVA_RANGES, iommufd_resv_iova_ranges, struct iommu_resv_iova_ranges, resv_iovas), + IOCTL_OP(IOMMU_SET_DEV_DATA, iommufd_set_dev_data, + struct iommu_set_dev_data, data_len), + IOCTL_OP(IOMMU_UNSET_DEV_DATA, iommufd_unset_dev_data, + struct iommu_unset_dev_data, dev_id), IOCTL_OP(IOMMU_VFIO_IOAS, iommufd_vfio_ioas, struct iommu_vfio_ioas, __reserved), #ifdef CONFIG_IOMMUFD_TEST diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 034da283cd3a..ede822e5acbb 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -49,6 +49,8 @@ enum { IOMMUFD_CMD_GET_HW_INFO, IOMMUFD_CMD_RESV_IOVA_RANGES, IOMMUFD_CMD_HWPT_INVALIDATE, + IOMMUFD_CMD_SET_DEV_DATA, + IOMMUFD_CMD_UNSET_DEV_DATA, }; /** @@ -508,4 +510,34 @@ struct iommu_hwpt_invalidate { __aligned_u64 data_uptr; }; #define IOMMU_HWPT_INVALIDATE _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_INVALIDATE) + +/** + * struct iommu_set_dev_data - ioctl(IOMMU_SET_DEV_DATA) + * @size: sizeof(struct iommu_set_dev_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_UNSET_DEV_DATA), before + * another ioctl(IOMMU_SET_DEV_DATA) call or before the device itself gets + * unbind'd from the iommufd context. + */ +struct iommu_set_dev_data { + __u32 size; + __u32 dev_id; + __aligned_u64 data_uptr; + __u32 data_len; +}; +#define IOMMU_SET_DEV_DATA _IO(IOMMUFD_TYPE, IOMMUFD_CMD_SET_DEV_DATA) + +/** + * struct iommu_unset_dev_data - ioctl(IOMMU_UNSET_DEV_DATA) + * @size: sizeof(struct iommu_unset_dev_data) + * @dev_id: The device to unset its device user data + */ +struct iommu_unset_dev_data { + __u32 size; + __u32 dev_id; +}; +#define IOMMU_UNSET_DEV_DATA _IO(IOMMUFD_TYPE, IOMMUFD_CMD_UNSET_DEV_DATA) #endif From patchwork Thu Jul 27 21:09:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 127200 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp29178vqg; Thu, 27 Jul 2023 14:48:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlH/Q+7kPFuxQY4xDRj6Gk+qtW+UJE6sG9ajutn62zroYBsNJK1ourXMwITPmWa0ntMZXD5Q X-Received: by 2002:a05:6a20:430f:b0:136:ee92:9c11 with SMTP id h15-20020a056a20430f00b00136ee929c11mr415057pzk.31.1690494535508; Thu, 27 Jul 2023 14:48:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1690494535; cv=pass; d=google.com; s=arc-20160816; b=rgQ7ir7Fx0GLKp13l8lRJ5Ww/gjDqamMYwAc9Vjv6dcCODgLojs3uR7pW0rO0nThU7 LD9GUSATLixQj60KoHPsWCSjfEapIstW8x2GdiTDQveRIL1B1xqS4HN5MUFoJ0d5Msbi Te5Mq0WI/2giaaFN7q2cYB22VH1Z+/z1mankQwnAh3Yuz9oz9M0oiVt3YmeGuC+a9GgM RjzGhRKV0jqKsK9aH/ZdUOzHFx7o7mxK+cRXW1JfGy+U/it8Xe6bLhvBsfFTA1ZjdZS7 1a6mJcEe2dSdf//k8A2/nH3xvvjHLK/WcVjRvWBpbOEhE7xlN3GK5Hgoln0bBsskfGri y/XQ== 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=FVUp7tyth7M0dMVM+B5NVgjDD9OgyJpbL/BoepjgWIg=; fh=ULXK5IZ3LFNv7cj0QeIPGDeVQmCtgYU3woQ+rdcEpbI=; b=cz7/za+YNMcXg3vmpqmaQTCFbwJTqVkqfAVu9M33cs3Es+NGMo6IYx8Gs5VNqwgXmE P+DTh1G+YNDLGW6OIBR0avCZTK6o1PdDYzfToYmHRu1dm9tV4+9l5Dh6rnq7mxOnUtUC D//3KOfJv2JaiUSPVcUNbzuEAD0a6shENU71Dtl1JobuJCGDXvtb9pm2HynTjOzVJDO0 /MNpZbD8VII3MGDymzCLViwqMYH9XAkyyUwbPaFPuSHS78NsOBz8VSIGbx/Ast1ekCOS tWssqsnQ4ls5RsB2lRAMhqQhoWunVIlqOpXpfmbFulbgLO6Z6EE1Iv6UUAjbsN0ODsQK uVhw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=c2gBRigC; 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 e24-20020a635458000000b00553854417e2si1736934pgm.244.2023.07.27.14.48.42; Thu, 27 Jul 2023 14:48:55 -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=c2gBRigC; 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 S231666AbjG0VK2 (ORCPT + 99 others); Thu, 27 Jul 2023 17:10:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230147AbjG0VKU (ORCPT ); Thu, 27 Jul 2023 17:10:20 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2053.outbound.protection.outlook.com [40.107.94.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A760130E2 for ; Thu, 27 Jul 2023 14:10:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LHV71sn2ox1AcWuqZ12UxE14ZqYIjmqU/feimkvLhJhxoKDU2PgiOW0GjwfaVnMSxwfE8r0+ZE6itjNLiHAwQGLuaM42Bs3H2lhrkOoC9qIMAX5beVJWlYCGfQ6apdx8w9FXWLgZVAeatrYkDGzjAskmgIqyh3Me0Db1zFOatJzHHPoIKdpYsPPpCYVe5VBO9O3B18Poa+NpU/XfsZRU0O9AeOZ894txvMghe172AIcn/9x34cK9JXrOwHAPqajLkcjxNn9+um14Lyg8jaCb3w5MhJjoq/yE33u0CmEDGbBcGGKGA22vdhVlaHuJmFdaB6z4bEvNxEch2Hy/zIh7Xg== 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=FVUp7tyth7M0dMVM+B5NVgjDD9OgyJpbL/BoepjgWIg=; b=WVPmDmhO1giWQnwVZMY0FKNQY4nxD/Mq78aXkr44MqQH2nIrCtYrDDQI2/+NVTZzAdVqrFlqv49pY+C+zabqcn0cGg8llO2ulcd9/dcStVPMjDYBhBTa7pz72TW6IRRkUylVfv6jj0bAmeYkiW8CNoNRHWKJEQkJMNnlQgGKyfNRZKCXLt/RB10DXBHQvW31IWPeI7idmSk5PVedfQvF/86pA4wG1IJ7/WwlzS1XD4pd9mMP9QWhftBqzHrv9Hh97mxQ7hIxozfWfTwhSdIKYGWBrdmrDshIx0VQkiJOZusKKOikF7nj6ZXI4/T5DymxvGoINsUuJ1YnOTPqTe+gjQ== 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=FVUp7tyth7M0dMVM+B5NVgjDD9OgyJpbL/BoepjgWIg=; b=c2gBRigCV6T/+ianLCbfwm2t/Gs9vx5l7srsHY7IjTu+gOWGaJ+WAuEq8AWYp7MPXRbQ3G1kV1pLI5XzAnnc0Qx9/HzaUdtYLkLXUS0cnMVFpgiiAU759Y+DKmEhTfLTtzz4ER6Eo5XNSWsA0eTqdg3jFBs/95gH4Nau6hAeXLehCNWRxSj7CY67wAHHq6Cv40JFSExtfJYRXyvEv8LSCMeuPgFJeqPhr8r0W6IDUZC1QGNR3kvksiOmojTdHfLB4aXvBuyAcM/MZxTbBmsOVpOa9NQpT9S1k8109x72/HnJglQnBzI7b+OiZva+Kjdb9cbwXz5LdfIM44+ZIlWFdQ== Received: from DS7PR03CA0220.namprd03.prod.outlook.com (2603:10b6:5:3ba::15) by BL3PR12MB9049.namprd12.prod.outlook.com (2603:10b6:208:3b8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33; Thu, 27 Jul 2023 21:10:14 +0000 Received: from DM6NAM11FT049.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3ba:cafe::6e) by DS7PR03CA0220.outlook.office365.com (2603:10b6:5:3ba::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29 via Frontend Transport; Thu, 27 Jul 2023 21:10:13 +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 DM6NAM11FT049.mail.protection.outlook.com (10.13.172.188) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29 via Frontend Transport; Thu, 27 Jul 2023 21:10:13 +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; Thu, 27 Jul 2023 14:10:03 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Thu, 27 Jul 2023 14:10:03 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.13) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Thu, 27 Jul 2023 14:10:02 -0700 From: Nicolin Chen To: , CC: , , , , , , , , , , Subject: [PATCH v5 3/4] iommufd/selftest: Add IOMMU_TEST_OP_DEV_CHECK_DATA Date: Thu, 27 Jul 2023 14:09:42 -0700 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT049:EE_|BL3PR12MB9049:EE_ X-MS-Office365-Filtering-Correlation-Id: 044d7da4-35ae-446b-4f29-08db8ee5de9c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Q2nCkDJeaIDaZYKs5ficREnaN5aQAX+EsYyxlv/aEf1hkQso9uBL6dI9UkR36+nCQIz2c7QNNI4+q1TiDhLXZkU9dVSceZOtqefkeyJfJ3XLyUOjrAx39QM3Yl0q74SXXqyl/MseE2X9z8cmZ+7oTfmo3BcWXUsDp+9gQVEpm0hs71PhnuLKu8TJRi+UIq6pzMBMiIz+XMXa/dIDyRVOrDiocY+q8aHmkSU844HqP0mF0w4T2gO/5q8X+qNRsfQY22tEDHPNlZAaIgYIpvEKjVdJmmz0yxedPFctvJWnTr59OAsFENbjPr5ya/qZr2DQ6mzIQ/FAocMnxp+c/yh0Ple4gQ4FcoM4RC1gS0qAJbInz2jmBfmbnc6+HQ4qeodj5yuw/byKDQWAUaT+QW/M5HdAHTrxVPydAPQI+zOFSe/jYo6oguLKGzsTlfMwG+ri0aUMdG3cIqssVSRR+go5oZ1RUGiPywowUjWLlhpnZurHC9vX8BAj3ZLju+JiggVw2MpxmDJhvySW1SOqk7tr01qrq83C8tKInp7Pn4gxEb9Et6rEKxHjIPcpISbrcK84NMrXhuC+AYyWQ6U67OZYfzkDQyvpFNnwi6nHfLXFVhkKTb2b/K8gPkYuAuD+OxLOQtZN0uKINlpmmlCTdy/ttyUjbmAF4DOtdzP/CxeSNHCTvxzoI9Gvh/Ex1SmiD+RoA3CnMg0IYZ80pC2xjN8wniV7auC8rY9gQovW+H0fi4BA3tQFDgmq2UJLgbWU+8zN 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)(376002)(396003)(346002)(39860400002)(451199021)(82310400008)(36840700001)(40470700004)(46966006)(426003)(316002)(7416002)(40480700001)(40460700003)(356005)(47076005)(86362001)(83380400001)(70206006)(336012)(26005)(41300700001)(186003)(70586007)(8936002)(8676002)(4326008)(2906002)(7696005)(6666004)(82740400003)(5660300002)(2616005)(36756003)(54906003)(110136005)(478600001)(7636003)(36860700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2023 21:10:13.4935 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 044d7da4-35ae-446b-4f29-08db8ee5de9c 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: DM6NAM11FT049.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB9049 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772611998052547274 X-GMAIL-MSGID: 1772611998052547274 Add mock_domain_set/unset_dev_user_data and iommufd_test_dev_check_data to allow testing on IOMMUFD_CMD_SET/UNSET_DEV_DATA ioctls from the 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 9768d0c9e347..b191d7417719 100644 --- a/drivers/iommu/iommufd/iommufd_test.h +++ b/drivers/iommu/iommufd/iommufd_test.h @@ -22,6 +22,7 @@ enum { IOMMU_TEST_OP_DEV_ADD_RESERVED, IOMMU_TEST_OP_DEV_DEL_RESERVED, IOMMU_TEST_OP_MD_CHECK_IOTLB, + IOMMU_TEST_OP_DEV_CHECK_DATA, }; enum { @@ -105,6 +106,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 diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index 5f3e1f2a24e7..526ec6066d17 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -97,6 +97,7 @@ struct mock_dev { struct device dev; struct rw_semaphore reserved_rwsem; struct rb_root_cached reserved_itree; + u32 dev_data; }; struct selftest_obj { @@ -375,6 +376,23 @@ static void iommufd_test_get_resv_regions(struct device *dev, up_read(&mdev->reserved_rwsem); } +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, @@ -385,6 +403,9 @@ static const struct iommu_ops mock_ops = { .capable = mock_domain_capable, .get_resv_regions = iommufd_test_get_resv_regions, .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, @@ -833,6 +854,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; @@ -1255,6 +1294,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 Thu Jul 27 21:09:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 127222 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp43769vqg; Thu, 27 Jul 2023 15:21:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlE4htDJlqHXMvDFZBF6SjNeLD6FsQ0dWcE0VHLFtmwSxps6GsneMFiGBF4KmXPqSdW42GQW X-Received: by 2002:a17:903:25cd:b0:1bb:9bc8:d22d with SMTP id jc13-20020a17090325cd00b001bb9bc8d22dmr591605plb.16.1690496501467; Thu, 27 Jul 2023 15:21:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1690496501; cv=pass; d=google.com; s=arc-20160816; b=kKLRnJ3jxI+iSuyw+JvQfkPzbt6heAan8vkikG8wyOdjGNSVfJZPnazgA3LUfCdOf5 ylnURG2raskXKCEgX+u0ucpyHQ9JF3LPKjigWGF+tZRA7OWL7xsrezy5/jM+xXkP0rV/ E5paZdFPZHfVQxXYOAFPGnFiE0T0ZY/r6fvMyCSWM4jb4bjnot2UAURYdOzuk989K9QQ gomlLqwU+YSXS7jv805Hc6jP+ay9hJfKHxKHzHo4l1LKofxOQ2aKnRbJtrYlr5LhAxV8 QURzEtedAyJUot/UcgQz0hWd1l3Mqy3xiMjbUWtMCZInI5YqimxRkoMY/dGziyklFOGM YLSg== 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=vxHpZOXrXPISX7kfANEyB4/sA9KUi6B6vgPuNZZqFdI=; fh=ULXK5IZ3LFNv7cj0QeIPGDeVQmCtgYU3woQ+rdcEpbI=; b=vBpzbWN6Aj5T9vTC6WAWG9AgMig07XqvpO25o4etPltld7WtR5YS48NMupI9igenzj jiFduvIrkAdQNKfssEgP8b1dNmagyjfEA6lmH2mPFeORH4l1wMBTLX3Db3yFy44QBbqv HsMt4SAbZuzBojuvRcMTkQG1FkcRT/pe/dhFAdZNcxA3AL7nrr/7hMtZgzDBt4xGbY35 ENu+/8ZArxd77DENxtPIaS8QbbGBoSShzwRakXUn41ZrVNZd43/ke0B3XuhE29u2uc+d dRM3p0ajaywXAXftyM2mcUoaXduH6c6lIhAEZT6++3BPtd7Davwqc6JuNrkzbOMU9S+6 3hMw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=iU8XLqco; 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 d9-20020a170903230900b0019c354055d0si1926506plh.304.2023.07.27.15.21.15; Thu, 27 Jul 2023 15:21:41 -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=iU8XLqco; 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 S231789AbjG0VKc (ORCPT + 99 others); Thu, 27 Jul 2023 17:10:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229590AbjG0VKV (ORCPT ); Thu, 27 Jul 2023 17:10:21 -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 1024030E8 for ; Thu, 27 Jul 2023 14:10:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hju7zAfzntqKqJyObzsJOZahojfNvUh6tK03CugQ/Flvha39RtF1ikXjWBCc4HEiKH9utrk9rEBdy+KvYtFEITMrgqLhx2KJKRbI053Xsk06+IkRbHkM2RYfJmkAHx2WI4lW6QuFGbKGzFIH8w1qN3DnM5763z/29vsJJWs9UvnjIhFvlG/l1sV59OrZ0CLtu6scbcXOJjZPWB36QbOBugThNV+QvEy4eWDT+gOVEerNjMJncObP2M3+dzniJDcARmcsCG8igOwNkoeKfunqLIBVz0+Ofv21L9cs1xu/CD/nNwveJrsEtGG+BqPDMf1ysodzYQZcGEmoqaI3l2pLvQ== 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=vxHpZOXrXPISX7kfANEyB4/sA9KUi6B6vgPuNZZqFdI=; b=flyu+3xqtJ44xyXFDRTdwmyCyZ4cQa3OWmbzbDNRTeb0+Qj/kOY3q9t0cWqs2djSwdaAId119WIQWApbZh41oBCiC/LA2HlDSbuF2D3UOBQ4tYE3qjNM4duxdiYY4S1kVVj9tzVgjdqWFZY/pqFPZBMpwyOgl49tbHP55oUVDLZTXw/s/AXATs+ZK3IuAa4ziOgMvZTvtTepoS9vgQFkufCvtRsQYo31RUQLtnD7pdpZCr0RlhlVovVtmiwnib9PiE3BcKTjYqNjm5eC3mCz8bHqev5eC6kIfPCXDD3SZJGHxW+dy2Rtv3IKAbz66oHMUJj+pT9Tu8LqR0e4gU2tlg== 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=vxHpZOXrXPISX7kfANEyB4/sA9KUi6B6vgPuNZZqFdI=; b=iU8XLqco5+BjywZe8+9woeUstWpcb1ZHclYzEvdZFCAh2bp86smU1K55p0/6jqrJ3v3hxLwzWNczGf8J6xCctju6QEDzzxEasCo0a2O7XGZZXGufnUcv5zTvG1vsj8ubtnwAp1LCnnzfg3lOaTSXTopB8FOqxOR2NmX1np0WoYBHTrAtkcbc0Rfe7FB+v8UEtMhZyZHuSY5o4++xAB6LUcyDNZZTr1GRo/9MydTVJRgdJo5vQpZzsgPg9onkYJCnJNyj80u/vugIwomSW8tE/fSUP6EDpANg7bKa24o1EWA1EcthyOq8ji4K1jepbQGGsuIWzj04t4npRg2VbUcWjg== Received: from DM6PR02CA0086.namprd02.prod.outlook.com (2603:10b6:5:1f4::27) by MN2PR12MB4455.namprd12.prod.outlook.com (2603:10b6:208:265::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Thu, 27 Jul 2023 21:10:19 +0000 Received: from DM6NAM11FT065.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1f4:cafe::40) by DM6PR02CA0086.outlook.office365.com (2603:10b6:5:1f4::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29 via Frontend Transport; Thu, 27 Jul 2023 21:10:19 +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 DM6NAM11FT065.mail.protection.outlook.com (10.13.172.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29 via Frontend Transport; Thu, 27 Jul 2023 21:10:18 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Thu, 27 Jul 2023 14:10:04 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Thu, 27 Jul 2023 14:10:04 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.13) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Thu, 27 Jul 2023 14:10:03 -0700 From: Nicolin Chen To: , CC: , , , , , , , , , , Subject: [PATCH v5 4/4] iommufd/selftest: Add coverage for IOMMU_SET/UNSET_DEV_DATA Date: Thu, 27 Jul 2023 14:09:43 -0700 Message-ID: <5b192832f6a8a02e24ba0712b1f9ab20735fd583.1690487690.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT065:EE_|MN2PR12MB4455:EE_ X-MS-Office365-Filtering-Correlation-Id: 0aa4579a-ec9f-441d-c6e8-08db8ee5e1b6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +fNsa/t6YnpsWPRb3H9BRXbViLqL6NwuF7ZPdE7lXPYnqBNOwbS1OxvGbbh5wAGPanKO62jUJUgqk6TLwOzHS9HNltyFiTtYkHQndg9LDh75x5RzBKuChLGn48D4qoWjewkQm4XwWVftNW2qCEjufETziTWyaTAlo7CUd/eGtR30uuqMeepO9A+qHKliyTKyqp50nMGY1Nn0Z5xtgkLvN/M7rVJSRziCnl77YQ/e51MBDv850pxrwqO4ntQ+WvLgf5QqC9u3EZCPIjTH/7bD0hohlBN+GFa9udeFXoSMF2TRyPx9RiX49LLs/hXO4KL60gNaetEv3zZDVJkVZR6T2Vkz+tifuUZCX9NIkwVipamkfV9EY96ElYLtTIM9ID1kKag1T3utGLWQypf1l++Mo34epiFpeHSHcd+upMH7wTPRB/9sgfEeI501vOfK0B0LgjEOeatFQJfsyeIZb+5bfvJmNALwk4JtNwD6KradSHTWYDRkTXVQvKZn4fUS0VkdKGYf3Ta4OAKx+LcHpkEFlxm1l5fskJFkSmSx6Izo29Tqsq1mDvIbuRu7+BuaK85aUSifXhBj2HdJEiy/73ZA5yplPvtkZAwWwEqFzdOhcGJV3WsmUmvV4b9mSufy8tEVdLxv8ULtiPj3SJfSnSak6Uh6hr0o/gWjb6p4iKuQVW9yBtjZM7r5PpqTFKS13AwxjHXoU8A72cu67DgArlM/I7d2peLG9476Yt5wOVRDTw0yXmyzoVmSV2eNPcclkG/Z X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(376002)(346002)(396003)(136003)(39860400002)(451199021)(82310400008)(40470700004)(46966006)(36840700001)(6666004)(7696005)(356005)(82740400003)(83380400001)(478600001)(47076005)(26005)(70586007)(7636003)(4326008)(54906003)(70206006)(110136005)(336012)(2616005)(186003)(36860700001)(426003)(5660300002)(7416002)(8936002)(8676002)(40460700003)(2906002)(41300700001)(316002)(40480700001)(86362001)(36756003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2023 21:10:18.7158 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0aa4579a-ec9f-441d-c6e8-08db8ee5e1b6 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: DM6NAM11FT065.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4455 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772614059740620447 X-GMAIL-MSGID: 1772614059740620447 Add a new IOMMU_TEST_OP_DEV_CHECK_DATA to verify whether the dev_data is properly set/unset by the IOMMU_SET/UNSET_DEV_DATA. Signed-off-by: Nicolin Chen --- tools/testing/selftests/iommu/iommufd.c | 22 +++++++ tools/testing/selftests/iommu/iommufd_utils.h | 59 +++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index bf0082d88a38..b437b890e4f5 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -123,6 +123,8 @@ TEST_F(iommufd, cmd_length) TEST_LENGTH(iommu_ioas_copy, IOMMU_IOAS_COPY); TEST_LENGTH(iommu_ioas_unmap, IOMMU_IOAS_UNMAP); TEST_LENGTH(iommu_option, IOMMU_OPTION); + TEST_LENGTH(iommu_set_dev_data, IOMMU_SET_DEV_DATA); + TEST_LENGTH(iommu_unset_dev_data, IOMMU_UNSET_DEV_DATA); TEST_LENGTH(iommu_vfio_ioas, IOMMU_VFIO_IOAS); #undef TEST_LENGTH } @@ -1517,6 +1519,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_set_dev_data(ENOENT, 0, &dev_data); + test_err_set_dev_data(EINVAL, self->idev_ids[i], NULL); + test_cmd_set_dev_data(self->idev_ids[i], &dev_data); + test_err_set_dev_data(EEXIST, self->idev_ids[i], &dev_data); + test_cmd_dev_check_data(self->idev_ids[i], dev_data.val); + test_err_unset_dev_data(ENOENT, 0); + test_cmd_unset_dev_data(self->idev_ids[i]); + test_err_unset_dev_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 9b3e5f36c4a3..eb756fffbc89 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_get_hw_info(int fd, __u32 device_id, EXPECT_ERRNO(_errno, \ _test_cmd_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_set_dev_data(int fd, __u32 device_id, + struct iommu_test_device_data *dev_data) +{ + struct iommu_set_dev_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_SET_DEV_DATA, &cmd); + if (ret) + return ret; + return 0; +} + +#define test_cmd_set_dev_data(device_id, dev_data) \ + ASSERT_EQ(0, _test_cmd_set_dev_data(self->fd, device_id, dev_data)) + +#define test_err_set_dev_data(_errno, device_id, dev_data) \ + EXPECT_ERRNO(_errno, \ + _test_cmd_set_dev_data(self->fd, device_id, dev_data)) + +static int _test_cmd_unset_dev_data(int fd, __u32 device_id) +{ + struct iommu_unset_dev_data cmd = { + .size = sizeof(cmd), + .dev_id = device_id, + }; + int ret; + + ret = ioctl(fd, IOMMU_UNSET_DEV_DATA, &cmd); + if (ret) + return ret; + return 0; +} + +#define test_cmd_unset_dev_data(device_id) \ + ASSERT_EQ(0, _test_cmd_unset_dev_data(self->fd, device_id)) + +#define test_err_unset_dev_data(_errno, device_id) \ + EXPECT_ERRNO(_errno, \ + _test_cmd_unset_dev_data(self->fd, device_id))