From patchwork Thu Apr 6 06:25:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 80071 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp813279vqo; Wed, 5 Apr 2023 23:31:26 -0700 (PDT) X-Google-Smtp-Source: AKy350brGrZOJngoBkGbVGuhNEw64BspAhUpkTc2DXTokYJb5CeXyfMcxazH42ftN3Tg0zMsBTJn X-Received: by 2002:a62:1795:0:b0:5df:421d:1962 with SMTP id 143-20020a621795000000b005df421d1962mr7819408pfx.2.1680762685932; Wed, 05 Apr 2023 23:31:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1680762685; cv=pass; d=google.com; s=arc-20160816; b=MpsVDzhz7sCiGFYpCB30IaAa+ELbupdWGmpDcHPlsvpqsDskl0G+7sjdT6NRZmFTdn vLHoVipboTEAYVrmHuH7PKoHLMSdiDLj2DT08/u3uoKhwsAu5H6v9l5ROvkiyYtrenDc E4RCenZ60Qnup030ai9Jr/BkQPbIBEiUpgSzaX9cyt4Hm5ft4riT71rVEh0FsPYhGyZ+ TtW/FdgXXg4tCRlYM9QMliGiroN6AS8xWaIffox3qycjKmuMkCMBTExiy7jbhDjAEVPd rp6QxhCj3ZB4xbZhL21SwrSdtXbDd+qduPcdWLWvf4eCS2U4BpY4V+mi1ZvQ+icN2coN kI9w== 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=hfYrwGLhZXyOzEPzO/lU+YoRB4gD5bgyS2QNeKyQH0M=; b=PKft7pPki5wJRKdkg/WMCEG3kh69HlK4Yf+Ag6kbevfXp5glGJEKoHFmEle9r7bbjK /a4qTrbHDfBUP7oACmsx3rQ1B98rd76+yqYrnJPJ3ZlJt5cnVGCNR/Tx0C+6YAHl3sVU 2ghbmDNbNoqbp7kEUogXJVtSJaPUb0BRo+LLKF0UMQRA+6M0SPVZQbbfLo2BZReRaKgm htyj+jRsr6EAAQCX1pKD68YwKGWSZ3TPQFE7X05eQthtRBcHbyU9hgq7zO91N+id/ENn 3h6MKNOCL6DbmiVU+X6N9ztfL/sMBRZXgB/XbwRUnFlfpVY9mEKymrmdGkGmu3r6HyUx xusw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="JDZk1/dE"; 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-20020a632785000000b00513b3372e28si537983pgn.630.2023.04.05.23.31.13; Wed, 05 Apr 2023 23:31:25 -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="JDZk1/dE"; 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 S235308AbjDFG0r (ORCPT + 99 others); Thu, 6 Apr 2023 02:26:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235237AbjDFG0p (ORCPT ); Thu, 6 Apr 2023 02:26:45 -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 259E29772 for ; Wed, 5 Apr 2023 23:26:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eGA7Br04d1gtgipSkMm4Uvouel3i6YJtw3SaERIPmqJ+kOBuQwcgLBoNztBxHCnnRSBBB11vYCWYD0bqTS8d/N0W+WTjAgUH05AvG8Wh7+VK28LMab+LCfTVPUZsTH5F+ZjffJp/R5ZlH6upM2fyHx8MqfGTl46LDsDrpOXXwFPBQZOS0VEcpXEhr5z6C1ENvvl38K7IkogLKPgU+/R519nUnyQZK8X9GcXcV9QnnH31Sh06gl+Rv3MQAjjs/Dmez+RNBT/TGqgd0Z8eZr3VtxM22yUIA/zf/1z5Abv0bLYT7O4VCuq2cQtMQqb2JFjR9MMWxhOMHZiIBQxQ5fyfIQ== 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=hfYrwGLhZXyOzEPzO/lU+YoRB4gD5bgyS2QNeKyQH0M=; b=WXF3Fq5+I77WJembUd1hwWQbDagwFiRCQIkynV4W/BiBRrAOjz6JZezI9lWw4BAM/UYcpSLrSnA1yEFlhOFBxDn4P9fILiEIZFAQxy91mlAry3Wdm3jcvSrgdMxIidDcuZTaZquJrgmjP0f9IXo0Xuk/tFRGOam3ur8blQi1hfOYEAFK2bDeeJzNi+ERSvgK+h+d/eTxFRxv9H+5bwZo23V7xNW43fbpVoVs6oLbMSORkAo7/jTZ9VsetQndCvtOa0AOPaEBAsK4TtuzqDRRv96pa7T0dFouP1/do70yDHeO2OVmiaQrbFbF78jHPIWU3q498pEw+NjbD5+yCEy1cw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=arm.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=hfYrwGLhZXyOzEPzO/lU+YoRB4gD5bgyS2QNeKyQH0M=; b=JDZk1/dELkyMbDrD3C3sUaadx8ishlwEeaJg0JHCymt8rWVIpUgaJKatbQqwGQsSx8vsB2zbnOlHNANshlez3++bxS+ZAKMQ+3UmkViUa/FE5bFiqJTqosuy33osUdWtkmaB/Qj6UPDRssH7iqEAOQUscFKi65qNWF7K3zMhzSbVsU7EMM0Re0SFKJrsrVe0taJkkzH+3TqvbV9w9Udjk/z6lkBC2BB7DkPZkXqkqp5qozQ+dcNSoIx/NuBMgYaa1XxdSpFa+tyHH0ASLdHbWTlw8Qnib3emQJBJVpCKxr8z8GVVQXPV14DIh2sJqcrVEJnVlkUzgyoaOPB/dqYfIw== Received: from MW2PR16CA0061.namprd16.prod.outlook.com (2603:10b6:907:1::38) by IA1PR12MB9031.namprd12.prod.outlook.com (2603:10b6:208:3f9::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.33; Thu, 6 Apr 2023 06:26:28 +0000 Received: from CO1NAM11FT012.eop-nam11.prod.protection.outlook.com (2603:10b6:907:1:cafe::e1) by MW2PR16CA0061.outlook.office365.com (2603:10b6:907:1::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.22 via Frontend Transport; Thu, 6 Apr 2023 06:26:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by CO1NAM11FT012.mail.protection.outlook.com (10.13.175.192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.30 via Frontend Transport; Thu, 6 Apr 2023 06:26:28 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Wed, 5 Apr 2023 23:26:21 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Wed, 5 Apr 2023 23:26:20 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.13) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Wed, 5 Apr 2023 23:26:20 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH RFC v1 1/3] iommu: Add set/unset_rid_user ops Date: Wed, 5 Apr 2023 23:25:34 -0700 Message-ID: <1944e8b2226585e309081a541e51addc137e6684.1680762112.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT012:EE_|IA1PR12MB9031:EE_ X-MS-Office365-Filtering-Correlation-Id: 23d3829a-a1b7-46a2-ce89-08db3667daaf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: W/ySf+sZ+mfeWOL/IPD78V5amjBGkoBXmVViB+YJ+gmZJI4RTJssNGAQ94ncAAUJ5QHcf+4+6tNaoHyJx5thSCYNlcEBVjQgMDctCIobGjMBgWXf/HH/SeBy5SoqpRuJk5SydUd+pBrljR7/LxUPc3IuYZoZRVkjoSc6KHMefCUrqBYDnSmwaQCSnktvQOSNIFr/y70i5rl/goz2aDWblzY0Q2s8WxnmAttjpNZA8tCCYSoIBkCr5PY2d5J9hg1IISF1i7EarN8FXWpMZec+L2gpezYsCnhcAaA24nybQab8K91H0qmarJYgLQKjFTQ0MGzwPT4xtUF5R/xg5XaJtFNSQJIRSGBR68KEBOgwOirTNlLBSMXlAUOUj/z/YxRVs/1bwVWkPo2hsa7qkHYAvzkFMhmMam8oT/9cWBSZ4cPHHNw2xZXKAIfYOCJ1aBrS69TAhhWF6kKE31rAXIvaAH4VFT1T6xM6fGUyNFLznLj8q1vMSJEAiK6exTsI8+m+VOuWmMpp9N+DtpXwbu6Iu5QEBsl9gOoEZ1c+MJuHCdFlRq11bHgBSl07n+34cu/LJpyejlGDuozGVAMRRVqonLevU9qXvMEZkoVHoLAU5FNzMB7BxB4hvhEGwITZHuwVIOS1bqpqwmxUAkxPr+fz1Fz5QC6O6I4BMlTSKIhtBlB1uBBRTs0d2PmfSYlR5aUvjAlhRqpzvqbMZOr8IQBGkR7XKX8QXS6KZczEI3XptQkR3zmMSOPD88kHWTZdOzOg X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(376002)(39860400002)(346002)(136003)(396003)(451199021)(40470700004)(36840700001)(46966006)(8936002)(40480700001)(40460700003)(82740400003)(478600001)(54906003)(70206006)(36860700001)(70586007)(8676002)(4326008)(7636003)(316002)(110136005)(41300700001)(7416002)(5660300002)(356005)(47076005)(83380400001)(186003)(426003)(7696005)(336012)(26005)(6666004)(86362001)(36756003)(82310400005)(2906002)(2616005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2023 06:26:28.0605 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 23d3829a-a1b7-46a2-ce89-08db3667daaf X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT012.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB9031 X-Spam-Status: No, score=0.8 required=5.0 tests=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 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?1762407414117048780?= X-GMAIL-MSGID: =?utf-8?q?1762407414117048780?= Add a pair of new ops to allow user space to set virtual RID of a device. This can be converted to Stream ID for SMMUv3, so as to create the link between a physical Stream ID and a virtual Stream ID. Signed-off-by: Nicolin Chen --- include/linux/iommu.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 080278c8154d..f85ce6f01408 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -248,6 +248,7 @@ struct iommu_iotlb_gather { * driver init to device driver init (default no) * @dev_enable/disable_feat: per device entries to enable/disable * iommu specific features. + * @set/unset_rid_user: per device entries to set/unset user space Request ID * @page_response: handle page request response * @def_domain_type: device default domain type, return value: * - IOMMU_DOMAIN_IDENTITY: must use an identity domain @@ -291,6 +292,9 @@ struct iommu_ops { int (*dev_enable_feat)(struct device *dev, enum iommu_dev_features f); int (*dev_disable_feat)(struct device *dev, enum iommu_dev_features f); + int (*set_rid_user)(struct device *dev, u32 rid, u32 rid_base); + int (*unset_rid_user)(struct device *dev); + int (*page_response)(struct device *dev, struct iommu_fault_event *evt, struct iommu_page_response *msg); From patchwork Thu Apr 6 06:25:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 80078 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp821641vqo; Wed, 5 Apr 2023 23:54:51 -0700 (PDT) X-Google-Smtp-Source: AKy350a/qJoJ4w0u+3arWcw5RsemqfPBldY65Znj+7ud7e8FF3lpihaOCJpOzaVwSNZZvaRuePV9 X-Received: by 2002:a62:3893:0:b0:594:26a7:cbd2 with SMTP id f141-20020a623893000000b0059426a7cbd2mr5170396pfa.8.1680764090844; Wed, 05 Apr 2023 23:54:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1680764090; cv=pass; d=google.com; s=arc-20160816; b=E26zMDMeixyHIufRrQWWizRXmx8yPDsgUCQh6VYum4Sn038iNEcMVksqiG4pjXTsDx qIyIAWWkTW4Cifpp4DeNn2aHQ99AGgGzCkAY6rbREeimkAROF5CaZXpe1BZj53bZXnS8 pT7ggXbQ3b+M6uFHUNpJ+4zi2B1SWoGeGWFIl3YMuMutK/35b4Y8BV2tXSBWUCIf9DL9 lqZQdIo0KO+AifIkguV1GEdSsjzuWSU54Gv2Y1IT3LCc4y5HqBXk2RzdGSZz06qD7Swx UxRz/YnfPpCQl8ljpU+kFEm4eV2CX8+A0kV3tHC3L3sAxhbzv8UARXz37JVEnRF21rpl YU0A== 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=3FWAzBExbmyJdVTG4OGhaVnzVTBB+BljON2XqecxAZ8=; b=y3/8bQYMPjKRgv5mA2BLjaMitzn6/Qm5sZkwn0Ap8+TOPzQqf4t1Gp4XqIFofeR1HU CU6oeKc8do4DYs1VRoaA6cYQACN/Nb53hcUFHuhQi9T4CJ4hW8DmgYZ0mPMEKrkfMB14 ec9u2MbtQDd17KeCouWdWQkYR8ADktnHTSRMcrKb/uiDjxLudBoXqg/BYAaeD72tzcWa Z3Lr1a6Npcu5UDVa9JR9WULNJdbfSpY3EP85wWHyVlOxJuwFmn9sNDGpUxEhamSAQHIZ acUHOmjKp74COLqBtVc/rAYvvZSTzPKg2UIQqVl/dYm2E+dVa4nbbebpqFqpT0iyYo+m 1/lQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=Byisae3G; 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-20020a632785000000b005139191c0absi560156pgn.635.2023.04.05.23.54.38; Wed, 05 Apr 2023 23:54:50 -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=Byisae3G; 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 S235325AbjDFG07 (ORCPT + 99 others); Thu, 6 Apr 2023 02:26:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235237AbjDFG0s (ORCPT ); Thu, 6 Apr 2023 02:26:48 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2072.outbound.protection.outlook.com [40.107.101.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C59B93C8 for ; Wed, 5 Apr 2023 23:26:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jlLK5PkHzHqiZLqw7Cmjv6HqYKR6V2mnYTaK/nN4KLsteL84rCvVGsuzLpxSrxjjHy/yuWdis044azdZ75wY8F/igwp7D2CyOcK1LTj0Ab45vRIBpEffZ/bZB02uGk3omqT6tbnyCJqgqgB+BwjmfW/B0DO0ax4ERn7HuqGVfHpkfWFXRqXgHC/hqMmtZk1ezv03nk4nbBdNRzLnPssAWcRZh3bkTfOx4VdN2gBPVdB0168x5+ov+d3QfheD+sP4PnjnsEHcL/xbCBaSVEHl722Axs3s+9pC8BIJ4zwWFu4crAQDp0Wp35Hu20xFu2zo97606G4Vq3M6L7zEmIPhNg== 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=3FWAzBExbmyJdVTG4OGhaVnzVTBB+BljON2XqecxAZ8=; b=BC5a9m958tmbeutruOyi6RS29TufcqZaO8Ni9oJF/OyT5TmwQTiRZ5ucZ+W1MpN+Wyn8uzb3QgitO65o4/RA88S3BLx0QMYNJmL4ST/npLjfZoi+9fQhm0SscKQBY6q2hY+pOz8OzqDjN6vP9c9X+hE7OetxZWV3AX8TvHZGdpxr+tHKG8OroaNcXldsYdAe48v/Pe74aBJ3OmbLfkbsHlz2eR9o7ZyPru3rdwSYu6lt9iazu05vG/rbPCdIl+d6SD8si4YbLdeUadY+Ne63pq5BgKea1oUDBnn/7Jub4Yr6glLKthUdj77RLpwgLZ13h1RAsk//w/QUyqr2HK51Zg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=arm.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=3FWAzBExbmyJdVTG4OGhaVnzVTBB+BljON2XqecxAZ8=; b=Byisae3GL65OG4OxiIKBIpojDCHm88nveOcQ30CyhB+2MpT8vZgk/OcI2R5jpChEj1AO1KQdTEce40tXzedTT03IbIIsTEj/tRsTlOv1Jn2QmKNoNbiOEi1hcNcwROuMGW+z8pRSgB4YtPRBsff+QD2QKgwPdjVIFEvurHElDomD+sgBSYWTLQ/0ZaUmR0ifi1ge3ffM8c9VrZMcWWgi7vfNcXK5ZzKXZPLTzeRaG6HomRow5r+863be/n9C4x4NeIPGYDoC1oXJjaH5E2IKsq6A5Vm5rI8j5XH8vQTO4zHZBShVlQrnJbz3scFL932jSsvyDY+Gj6LsIGAnVD11EA== Received: from BN8PR03CA0031.namprd03.prod.outlook.com (2603:10b6:408:94::44) by DM4PR12MB6037.namprd12.prod.outlook.com (2603:10b6:8:b0::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.33; Thu, 6 Apr 2023 06:26:36 +0000 Received: from BN8NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:408:94:cafe::9e) by BN8PR03CA0031.outlook.office365.com (2603:10b6:408:94::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.30 via Frontend Transport; Thu, 6 Apr 2023 06:26:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by BN8NAM11FT039.mail.protection.outlook.com (10.13.177.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.31 via Frontend Transport; Thu, 6 Apr 2023 06:26:35 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Wed, 5 Apr 2023 23:26:21 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Wed, 5 Apr 2023 23:26:21 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.13) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Wed, 5 Apr 2023 23:26:21 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH RFC v1 2/3] iommufd: Add IOMMUFD_CMD_DEVICE_SET_RID and IOMMUFD_CMD_DEVICE_UNSET_RID Date: Wed, 5 Apr 2023 23:25:35 -0700 Message-ID: <70520cb453d3a2521fb982776080adf4b2e40047.1680762112.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT039:EE_|DM4PR12MB6037:EE_ X-MS-Office365-Filtering-Correlation-Id: 2ea39927-e66c-48a0-622e-08db3667df72 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lBO7xULMwUjelzH78DGRvfOi9fGlWCHmeFvcrV8OXV7UEqcOxwQycmrW3xsFvTMXjDGkXlToOCoFa5Rs8EGBf1usKYFZ8BiFr83JqxukdIwDWFgy2w6kniVGR8LkMPk8QwqKoRvJdAjQCtRAbdNpY5mKKk1gGMxs0IMD35cY4W8MUqOygFpSYN2mCdXno+1CGNcwqW2LbJdvzMJVbiOeknRyX61YO1EXgQ67TTE8lemE5JD0DHaLftTw0mz6El9VsjZNfrx/3s4yqtFos10M4tJLUcCkAHx5I3S4lJveS1bJR+MaV2bRkIhqZ6n25W8PauXE04MTj99TVBrR08VS/GU1H6S9HJEgWdWygvWBdo45+mEwgjakg9gOG9CmiR6qs+QP2acSZLcxSH+6GUZkSX3HWYq4LoW/3jXwILGr5qatx8FVA1xbVnix3xw0IGHHihpkZBvzNho46Jmkhr9dl+NdMQvSYrGKim7zxSJ7w7/NTCsQMZsO8Q0iwm3ctl1DnHkubu2XGzlekWc8KXIuinD0lhSrq8UQHbvauOHevoDJ/sKYWdfg3FA6al/3nkwE3CtCt5APHcjd2U7qRp99KL9XAb+smY7EWI4wM47KoQVoMmmEo2nHXL3IVGL5//SBnMuACMQw32rwuYDD+mpcU6A/dXAfVzrgLX4NLGwGP2UsfoXpsibMMWOKqNxSGocN993+Av/wOahdl6nNWfcI3LnUIDJneanISaGVPdEWcxD7iKesvFubXldZ8LAeNyUv X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(346002)(376002)(396003)(136003)(451199021)(40470700004)(46966006)(36840700001)(36860700001)(7636003)(8676002)(82740400003)(356005)(70206006)(70586007)(336012)(426003)(7416002)(41300700001)(8936002)(5660300002)(82310400005)(316002)(4326008)(110136005)(47076005)(478600001)(2906002)(40460700003)(54906003)(6666004)(86362001)(83380400001)(186003)(40480700001)(36756003)(7696005)(2616005)(26005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2023 06:26:35.9216 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2ea39927-e66c-48a0-622e-08db3667df72 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6037 X-Spam-Status: No, score=0.8 required=5.0 tests=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 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?1762408886946239134?= X-GMAIL-MSGID: =?utf-8?q?1762408886946239134?= Add a new pair of ioctls to allow user space to set user space Request ID for a passthrough PCI device. This is to create a link between a physical RID and a virtual RID in the IOMMU driver that cares. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/device.c | 39 +++++++++++++++++++++++++ drivers/iommu/iommufd/iommufd_private.h | 2 ++ drivers/iommu/iommufd/main.c | 4 +++ include/uapi/linux/iommufd.h | 31 ++++++++++++++++++++ 4 files changed, 76 insertions(+) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 207b0e3fd9c8..db756e5cd77b 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -735,6 +735,45 @@ void iommufd_device_detach(struct iommufd_device *idev) } EXPORT_SYMBOL_NS_GPL(iommufd_device_detach, IOMMUFD); +int iommufd_device_set_rid(struct iommufd_ucmd *ucmd) +{ + struct iommufd_device_set_rid *cmd = ucmd->cmd; + struct iommufd_device *idev; + const struct iommu_ops *ops; + int rc = 0; + + if (!cmd->rid) + return -EINVAL; + + idev = iommufd_get_device(ucmd, cmd->dev_id); + if (IS_ERR(idev)) + return PTR_ERR(idev); + + ops = dev_iommu_ops(idev->dev); + if (ops && ops->set_rid_user) + rc = ops->set_rid_user(idev->dev, cmd->rid, cmd->rid_base); + iommufd_put_object(&idev->obj); + return rc; +} + +int iommufd_device_unset_rid(struct iommufd_ucmd *ucmd) +{ + struct iommufd_device_unset_rid *cmd = ucmd->cmd; + struct iommufd_device *idev; + const struct iommu_ops *ops; + int rc = 0; + + idev = iommufd_get_device(ucmd, cmd->dev_id); + if (IS_ERR(idev)) + return PTR_ERR(idev); + + ops = dev_iommu_ops(idev->dev); + if (ops && ops->unset_rid_user) + rc = ops->unset_rid_user(idev->dev); + 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 e52fd9d8c160..d65617727c0c 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -320,6 +320,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_rid(struct iommufd_ucmd *ucmd); +int iommufd_device_unset_rid(struct iommufd_ucmd *ucmd); extern const u64 iommufd_hwpt_type_bitmaps[]; diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c index 7ec3ceac01b3..113fac4d4de0 100644 --- a/drivers/iommu/iommufd/main.c +++ b/drivers/iommu/iommufd/main.c @@ -317,6 +317,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_RID, iommufd_device_set_rid, + struct iommufd_device_set_rid, rid_base), + IOCTL_OP(IOMMU_DEVICE_UNSET_RID, iommufd_device_unset_rid, + struct iommufd_device_unset_rid, 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 59a44ceff27d..5188a4318e22 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_RID, + IOMMUFD_CMD_DEVICE_UNSET_RID, }; /** @@ -482,4 +484,33 @@ struct iommu_hwpt_invalidate { __aligned_u64 data_uptr; }; #define IOMMU_HWPT_INVALIDATE _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_INVALIDATE) + +/** + * struct iommufd_device_set_rid - ioctl(IOMMU_DEVICE_SET_RID) + * @size: sizeof(struct iommufd_device_set_rid) + * @dev_id: The device to set a Request ID + * @rid: PCI Request ID + * Bits [15:8] are the Bus number. + * Bits [7:3] are the Device number. + * Bits [2:0] are the Function number. + * @rid_base: Base ID to map PCI Request ID + */ +struct iommufd_device_set_rid { + __u32 size; + __u32 dev_id; + __u32 rid; + __u32 rid_base; +}; +#define IOMMU_DEVICE_SET_RID _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DEVICE_SET_RID) + +/** + * struct iommufd_device_unset_rid - ioctl(IOMMU_DEVICE_UNSET_RID) + * @size: sizeof(struct iommufd_device_unset_rid) + * @dev_id: The device to unset a Request ID + */ +struct iommufd_device_unset_rid { + __u32 size; + __u32 dev_id; +}; +#define IOMMU_DEVICE_UNSET_RID _IO(IOMMUFD_TYPE, IOMMUFD_CMD_DEVICE_UNSET_RID) #endif From patchwork Thu Apr 6 06:25:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 80073 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp813966vqo; Wed, 5 Apr 2023 23:33:12 -0700 (PDT) X-Google-Smtp-Source: AKy350agapKDwrQDXv3tZNrC2+WgIKWejMNpq0bFUH8VvhtY04luEa+vmfYqEGqCHnfiasCXxBwO X-Received: by 2002:a17:90b:1e03:b0:234:d3a:2a38 with SMTP id pg3-20020a17090b1e0300b002340d3a2a38mr10129130pjb.43.1680762792587; Wed, 05 Apr 2023 23:33:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1680762792; cv=pass; d=google.com; s=arc-20160816; b=SBZ9OOfPuf5beZE3WUofPYaxPRy8hjJ+QH9PcWSlo2PCo1AmYp9zxos4z8tagOAXcR GFeoN1qtBkyC2trmCHeLuYSwblkZ6bkQQVoY9NeSwj4zLcWU9A3nx5XifYKszf9b27PO yhjhRjEal5UIzs5PeIM6ZjOofZMFU97HnNXZAwNmtkDgA9eqCfG3u/1PQwZ/5HAS459B RRvY+O/kNuS+QhmVrVo5EUBDVCeD8IOF4NlOassENieaIrzroUuiCAyCU/goHAoQEEDL bVdbiecyuNPxhectXnfOxUpGtIiotU2SNa3vIFYhIJRkTXU7LBUwmOo40F1/NEt7kZWu 9SqA== 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=fQ1ZD3yQu0tlpaYnsC5KDJ0bq7VJM6KFLaBFEEW8p0k=; b=j8l3tHaWl7xUAawtZJY6PwF4byOeHVM1KDE13f9bIJ/SA07diONQfv+w0OMqH8PniV mNRdKTj/S1Yr4XDerLrdj2uFHUQk2HAsgY24JDCyk4bAW75dj9TJ14W4AX2XeBHrc2YT E6WFrmWfqNkh85eWSNKEaRTkqrO0DZPVfaHoiM2J9CRnB+ZoJLE0dDWIUW+gVMD/wePC PPymC2a9f5955b/5O5PdaYlI0cnDpT985dJuKJIhRbUL7uKq4myTIC0U/+wE7oFJwnsr BxzXfsSjQqPJnTkS8N3hAxS8lkmO5TOY2n7vyiIvGVZt61ZjSvFMVHcRFVKDwdonk2U9 xmQQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="q/09NP+8"; 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 ls9-20020a17090b350900b0023e066d4e2dsi608211pjb.184.2023.04.05.23.33.00; Wed, 05 Apr 2023 23:33:12 -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="q/09NP+8"; 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 S235334AbjDFG0y (ORCPT + 99 others); Thu, 6 Apr 2023 02:26:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235323AbjDFG0r (ORCPT ); Thu, 6 Apr 2023 02:26:47 -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 DC4439011 for ; Wed, 5 Apr 2023 23:26:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ngv/2j97fH1q1u+HPZNw+myQJYneziGA/lnYoMA8F4GOyvcTRoSaSB8sNe4aNJxHqBq5H5lpSB650G2C46iGKbUpR8F+Oyim5qrdVCC48iYvXOOBPzPzsJbGZYvbUfBeAUuPjfTIbKPKPZXa6tW1AFL9FkEQllpJIjd67MvP1F1GLqND4T7c7n7vc+G9lAYYh6ECXCHXifM65T6aSVxC9BcPI1XQchvcscH9tKChyqGp/s8KlQrCsp+PADDpfrhLAYD11zIF1t1FcRIBOoyhV9x6eNqLp4tczOxKKAnIuWirjEZ8FTZyV6TlnDYCu2A/W2k0BCYS42iLpUipVg5U6w== 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=fQ1ZD3yQu0tlpaYnsC5KDJ0bq7VJM6KFLaBFEEW8p0k=; b=eLJfhzdGl906hxGEjNT5Majm0qduDnFp0xW/Lgdu8x/QZlFt2YLjp02dstLPGktMViDaoep3wPypoDxq3PkRW389Go1S3osQ/zhgziLAPVuzMLd2Tfv6RS47vIRvCxJe9T015tcDe+D2y/aBaPPq8LMatYj/e+lYTaWdEeLrqc7F22mmB7sGICEBPM2C4eZrSoF04RngZtSOGHJ5yqmy+MKXnCT2Df2Z1ZM0Z7JuaFRGOh8LxXQqoMiY/631YyhhW23TSip8L73SngMNP2GDWaSuHewDPk+Mbqut2j9B5WYjNxkkzJDC7vI66uDruBWTVG9kulcZ7Ji2fmjXd6nIsg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=arm.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=fQ1ZD3yQu0tlpaYnsC5KDJ0bq7VJM6KFLaBFEEW8p0k=; b=q/09NP+8cEVWyGD6I/xTOZV5KQ4WGuiNhv7gKnlf8UvuntW3qNxMR9JQcO7arE0ta0G71PzuRnUOF+r42Fkg4leQPDLvPlHTZUuuXfYFLDsDeBtxa+jQq2cAYtx4wIXTjKHDEl1+uyEnhnjxPJ6UdcTV4Na9d6ITK7ItD0FQx+iMECB/KeCwRnvBfPyRYXZwC+HG5AsYnABAs2rhxl9X7xpjsfRKLzf07/qzKZYpsdSaC6GHCc9+v5edREbbAF3rVjdx9wMlUsM7n2wOBehgJyXwcDF4L7eoVplGUPC2e7u/Ia8/2/TSuhGoI5795IPKN1MbBd0OCcKZqDDlwndycQ== Received: from BN8PR03CA0034.namprd03.prod.outlook.com (2603:10b6:408:94::47) by MN0PR12MB6056.namprd12.prod.outlook.com (2603:10b6:208:3cc::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.35; Thu, 6 Apr 2023 06:26:37 +0000 Received: from BN8NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:408:94:cafe::85) by BN8PR03CA0034.outlook.office365.com (2603:10b6:408:94::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.30 via Frontend Transport; Thu, 6 Apr 2023 06:26:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by BN8NAM11FT039.mail.protection.outlook.com (10.13.177.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.31 via Frontend Transport; Thu, 6 Apr 2023 06:26:36 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Wed, 5 Apr 2023 23:26:22 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Wed, 5 Apr 2023 23:26:22 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.13) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Wed, 5 Apr 2023 23:26:21 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH RFC v1 3/3] iommu/arm-smmu-v3: Implement set_rid_user and unset_rid_user Date: Wed, 5 Apr 2023 23:25:36 -0700 Message-ID: <2f00c7faa5c8ddfb4b94e85d3c5af7a0fa8df35d.1680762112.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT039:EE_|MN0PR12MB6056:EE_ X-MS-Office365-Filtering-Correlation-Id: b7f1a9c2-1c8d-410f-e396-08db3667dff7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8XqCRCi2antXc8Tnl/pm7D6EtEgtrmjiS1pqhz6r6h8IP2hwdzs4yXVZ2IL1D3klqPTBE2JwCQGUaXjBwhZjm/tIU9GuMDyiOin/gJRto2fhy5TTRMi13Q/ZseQBgBGrJmq929bsjlbLQk4pK22mmBZocEBcCxFALYJpj1t7EhPpdDViaZHxMuVq41/fQsrlMWwToA1RskAOiLmSwtFJjYxTKfl36SkDHmL+9D7c12gP9lmnVUBX+vVRDChtTeYEL2Ge9OBoIHqJoNKQJZrf8Bly1l77n/Wo5OaprYWj64T2Al4RNNmHNQl1qMqFkmspbt8ZDQYBDjZmJEpcyKjylf4eMpfPlROmWIChmG0rzTFp+6wjqUTEtf/RssP/wkPigH5r3AakdeUQ3luhYM7niYQTVFtcIIlaH6AJUZE9Ej3J1ngze9nz8AI6X3UmP9d1F4/5RmBZuSMhnWZqWcmsvVDG8FUtHv1r7wK7lckVjKMgvp928j60LfAiSLcdrHBK7+orZ6mnfaEmGZtkjS9xIg+oVEfLmw4W/JH70cUVEieR3SvEPOQ5o87MWWHVy/EBJKE/MJVEZF7aeAQXRgh9QSl7jj6+S0OcC7212vz8ogz1d92keomOQdxRmVxmuEwSdTXTUuNtkJwyjbHB+um2dc+YqKRwf/K+/B1dssQvGBJEZc1rPNOWPCxXge9l3jbQjSiGVWAwmaf4bzxB8ZprZmK3iYuZVfpJO0jL8qL3Zp1HT6Qgau75NI7UZfsBn48r X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(376002)(396003)(346002)(39860400002)(136003)(451199021)(40470700004)(46966006)(36840700001)(478600001)(8676002)(70206006)(110136005)(316002)(70586007)(54906003)(6666004)(4326008)(7636003)(2906002)(82310400005)(40460700003)(5660300002)(356005)(7416002)(41300700001)(8936002)(40480700001)(82740400003)(36860700001)(86362001)(7696005)(2616005)(26005)(426003)(336012)(47076005)(36756003)(186003)(83380400001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2023 06:26:36.8278 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b7f1a9c2-1c8d-410f-e396-08db3667dff7 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6056 X-Spam-Status: No, score=0.8 required=5.0 tests=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 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?1762407526320856937?= X-GMAIL-MSGID: =?utf-8?q?1762407526320856937?= Implement the new set_rid_user and unset_rid_user ops, by using an xarray to store the stream pointer indexed by a given user space Stream ID. This will be used by user cache invalidation hypercall, to check the SID field of an ATC_INV command and replace it with the corresponding physical SID. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 45 +++++++++++++++++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 + 2 files changed, 47 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index f2425b0f0cd6..17bb90e78547 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2843,6 +2843,48 @@ static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid) arm_smmu_sva_remove_dev_pasid(domain, dev, pasid); } +static int arm_smmu_set_rid_user(struct device *dev, u32 rid, u32 rid_base) +{ + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_stream *stream = &master->streams[0]; + struct arm_smmu_device *smmu = master->smmu; + u32 sid_user = rid_base | rid; + int ret = 0; + + if (!sid_user) + return -EINVAL; + + ret = xa_alloc(&smmu->streams_user, &sid_user, stream, + XA_LIMIT(sid_user, sid_user), GFP_KERNEL_ACCOUNT); + if (ret) + return ret; + stream->id_user = sid_user; + return 0; +} + +static int arm_smmu_unset_rid_user(struct device *dev) +{ + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_stream *stream = &master->streams[0]; + struct arm_smmu_device *smmu = master->smmu; + u32 sid_user = stream->id_user; + + if (!sid_user) + return -ENODEV; + + xa_lock(&smmu->streams_user); + stream = __xa_erase(&smmu->streams_user, sid_user); + if (stream != master->streams) { + WARN_ON(__xa_alloc(&smmu->streams_user, &sid_user, stream, + XA_LIMIT(sid_user, sid_user), + GFP_KERNEL_ACCOUNT)); + xa_unlock(&smmu->streams_user); + return -EINVAL; + } + xa_unlock(&smmu->streams_user); + return 0; +} + static struct iommu_ops arm_smmu_ops = { .capable = arm_smmu_capable, .domain_alloc = arm_smmu_domain_alloc, @@ -2854,6 +2896,8 @@ static struct iommu_ops arm_smmu_ops = { .remove_dev_pasid = arm_smmu_remove_dev_pasid, .dev_enable_feat = arm_smmu_dev_enable_feature, .dev_disable_feat = arm_smmu_dev_disable_feature, + .set_rid_user = arm_smmu_set_rid_user, + .unset_rid_user = arm_smmu_unset_rid_user, .page_response = arm_smmu_page_response, .def_domain_type = arm_smmu_def_domain_type, .pgsize_bitmap = -1UL, /* Restricted during device attach */ @@ -3082,6 +3126,7 @@ static int arm_smmu_init_structures(struct arm_smmu_device *smmu) mutex_init(&smmu->streams_mutex); smmu->streams = RB_ROOT; + xa_init_flags(&smmu->streams_user, XA_FLAGS_ALLOC1 | XA_FLAGS_ACCOUNT); ret = arm_smmu_init_queues(smmu); if (ret) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 8d772ea8a583..8ccea2e84bbb 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -674,10 +674,12 @@ struct arm_smmu_device { struct rb_root streams; struct mutex streams_mutex; + struct xarray streams_user; }; struct arm_smmu_stream { u32 id; + u32 id_user; struct arm_smmu_master *master; struct rb_node node; };