From patchwork Fri Jun 16 19:02:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283117 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5A11BEB64D8 for ; Fri, 16 Jun 2023 19:03:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Wi3NYIBe7GuK1Aq3vuu8T7n5/BL09k53YSWUcgOYusU=; b=4Wiyz22e6xb5qn DBmDkfGLPcNGgK1zhiAroIUVkeQjbMuWhKLccxP4H/mjzaoO7tVD+tg0a5Ala/WPf+s0bwJHFp8QL PR7kG1KIskZCmYPsm98tjv1E/LqD1UtEfHEQoUpOy3qteeqEqRy4YusLD0qKbUimDaSmPzrtVPh35 U5UPEqQ+mpQXd2iP58yXSBrtQk2dJJfvlwGCnJ1wVtdhmlvjgpzYt6MW9lwq/0GmMfTaVPyc3no/Y Ed0F22PbmOAYJBJuKVtRDK6+9hvnIGiDpLIajZGvZ7IpQMp7dTfB720o9kWF20wX0dZLVxkXiWFnr hWelGYV3HZ8TrbvdkuKw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAEjR-001XaV-0t; Fri, 16 Jun 2023 19:03:37 +0000 Received: from mail-bn7nam10on2062f.outbound.protection.outlook.com ([2a01:111:f400:7e8a::62f] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEiu-001X1S-09; Fri, 16 Jun 2023 19:03:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=io+Z9i3M9k+6nRYLrZGtMydKugdFleUuP3jylGyJxP9jSKrR2Hvplr3OXoKMijhop30lHWtSDlxwlvWkQV3Pea+3gZHzFuGD8AVbJu3GL4xJucfUUYEf2GEgFRykuWoOiUi88Xl3b72ii3uHaW26zTiF0Ai0hS5WpND4u4iR/mWY5OIgxkf4hUZ8GVtPLlXRoOloJpS+icPTRVDOL0kKCPtgDGWSUjifp1MYTdCA4ZY2gzezyVaO1cSOT26zO6JAW5fBAlhEDft5bM5I/snxdCPg06DFl8vCu8QqwOL0lxzWcUH+ALohS76JPUYNfdrcDJvUwc33VTeSZVv8coeU6Q== 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=bTIWsmIcZycPI7iiZZ7fmyAJtWycD0v37toHHV2MnwU=; b=ZJCwA2w9oS5hvnFvrhJIrBeXDq7olKHlbisJmfHQLVWu8t0Kz0GJu1dp3pTVHdHrcKsdn5ZEq841l7s32bU3bbDBV1GQ0EuNG/p/rdEY3cap7e1Q5UPwIahfq358gL4d6+XoRBiPgwHvqYcy+fpxx55CoHCEAqNs9cuVbLRyzN6P8otzzFFX+rJA08BKfdPkw+rB3/zGMZi6lKbQrubiDqquqnubbxbCyAtr7fcMeaI8FAwcolWingMsrHXwwonI+jK7SO5A7q4RYUcgzUmRCHhORUcIXVsQrrJCjFBwMdwuMBmBFF9McZ9YJscLA17zlgbS+JiCSiLKiyqInMAFNg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=bTIWsmIcZycPI7iiZZ7fmyAJtWycD0v37toHHV2MnwU=; b=qEDO+Tbw3nFDPdBAGe/mfPbIqe8JWodwd9pS1E11z5C9CZ+HaOkkF5pwq9EIx604Azayy90gpYxZ9AF9PFaLDaRRx2ZenN5TfuVoq7Id0UjEE2Gbm43xFFqM8PJJ+Z9GdSjL7bIbx40oPaVQTo6+muWQ47T46lQqCQ2vlNxT2BG54tvC1dd6WTX4B/jN9L2SernWVtM5Yum7/vhyXmpDMUddEweqrzw4FWWSQwpcER9ENER2MkzahcDX9jjCueLHlp4pXAjbF+5Zys+IK5jFNZftfUwInqSlsDBDDvtFnyyPAHvs0yklYfhyBoDnoiZ5YHsIJLpw37WwueBR+DHHmQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:02:58 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:02:58 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 01/25] iommu: Add iommu_ops->identity_domain Date: Fri, 16 Jun 2023 16:02:30 -0300 Message-Id: <1-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR03CA0072.namprd03.prod.outlook.com (2603:10b6:208:329::17) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: 6917df59-42d3-4f3e-c84e-08db6e9c4af8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bkQ7XiiRdK85gqd4cOiWbiQ9WtLU3aKtpgC3aYz/A7ysY1PI4HVO7JiZCuNfZ54mh494zpRjscpTG48X6jGMD5kmYki+0r21Sv9zqkNpybXT/bi0o3+yTiWuG+L82JeF39nPzkJ5Xp9utDXzVves5gC7CKcVYkr6f00S3oqXhSBwYbQxZ+1u2lG/67nK8y4DBEFAE7JbmIYgrzZMC4cbYYl7DJs1WlwTssBLeMcTNkU9aptq3YOYghxXEoUDapKC+1lDZqbIOXbQ0TGgJmYcu1GDUsLETCsocqZVafPLIksKa77C7AWqWpkNhwBeYAmNmq4QEDOPM2YyZA4JWtnPZgpIVVwiVRqXDmUDwiCRY8eYJsFN5DsjZTy7ZmHZgG261ne7FPCdRHrhz0KtM9NknDE54EeboH/1cuKvTR1X2y88jaAtv7uEcq9Pnpy6kG6mNotXDJ4dkoFAgmJDMyrzFLIhzLFYJCPPGs3rDHP1o6I5e5OLaTvCg2TamRPvzUQLtZTEYssYbaAKMPZpkFsCiFjZUas4zmI0x4SL7RVH5ocJfQGmfhtwfQcZt2d61vp1TLbm3HpS1WVcceNm6rB9SDPAvPLs3q+VoSGDv/4MxIJoHYpoufpe/HSOB5mXlF8q X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: v5IiqN8W0Ywfnv5KUtkkC7/XUd+FCw7KFSjcWsPjyKEc8NQHCgcWtzPB9tLZK1/JCzVpiaMpDa7rHHS2PcKHnWurDoUvjM5hnsCuNVQcy9DEwzuxfIbFHadnVABivjUZHAfWQY6tdXxwlWJhhmIRXH1XML7wOo2vaZjzFWAcMJMiTaivg3qL9NSZj2oBw/GK4kZaVkKRdrsLX+d1s42ABX0maOHo9XGl6HxmHt1TRezZ1DuAHDnKj7w9jNqlvJCMKxnxw9p0WHirct1s17Etf7M5mCk4oKuUpdtQMOZGq0uMnLoXAT7q485vR414P3YJhhfVnrvLcuxclGK26ZRYfXaBe1yMrMhdtWOGqcMloFQKbV5+7aFdA0MzhmV1xoua7CuUIkmwrxS4pyrhfRXIiTn0RBzNI9NWU10k3SMo/V6cP6lIdoDo7G6aXxqI/xv3spe/uBOVE2H81iCK6HJT6Jh41HvitckH1q2X9dWNGf073C9vlZmjSeJq5f1xdemuAHsANWD2+d82uqPMQHihe9wsPW0ASErZv/U76BSQp7TPYFY5B1m6U80jrv3Sh83dbA3qe4nPLjESgHYDG+Q7cERN6TfPVwtSenS92fa63bVrF5z1iL5BMt0gkrFTTdESC39sSaRZSavhZzCqvsgFXBV2o7N4d65RlCxQHqB6h3xk0pDwJ80uSEF/qIt13WNcIsEOtProRi0WJ/KgKbtuwsBpAYMMeCGepCQqUepCRozBekO6e9fr4dI6IpYaK1yvyfG6Pi2NYPOxalkujzT1YNW/S0rwPsO+/iLYEVTIdqTA1y5AIQ7Z9pSrsfEiIoqxXwiNKjpJzEDkK1jTU4DuZYhPXeoIzTYhOz5ZVlfktaY/+jX5f+HxLXYcK57WwXv7XT8qPGw4q2b5u6Bbgt7itsuNIB/+HXCJaMmxC24pwJBG/Gma658frcUa44ME8kd2G9leYZG4RdYRRsVDkUI+M5e3dMfRmBTt5/32kdSnHX9+u82BNlzvZv+Cptj6Zble7wBJyjFmFCwZgGJHvp1S99vF5d6IKXnqSNFeMGULCPnIcXMmqwiPf/Wp83k5PNTgxSJ2E44iWLFMj066bGYrjOCgP260NJp7qB0hW0hO6WxEpW+S3qxgyezdjL/JIAd1xj0pjy3M3pnirYsvH0HJbHhOOhiShkukPci4nt4OIWg2LGhK84D1aon+gFOvPpKLgXqImAQJ+pbSCJWEzbA1T3SG3Drtx13JXEHEmpoii7GvQAFhv8+wce7LdpNJA1qK1U4xN6Ht9yXpwsyOEzMXN4ff+kSf+y+7+xIE50Gn/ItOh+IB41cZhkho8RviHsM21sRPSwzB1msjVbNwXXqwWWQrMND3zJcg1WVpQ+NEJWNAco4j2OiGid3D8ebT09lchyg7j8teSEjU3eaNJOM2wY4A0NCsPN6g5JCPy8ob9ymE/J3AG1LD/2AxYtRXuezTg2KUXHcHln0u+k5noTJiKo2RyvYEIs5tyFQW7/jpGSykPNnCGuFouMTelbW1UOq+Q7Y5SfVUOjoZLOiJYecAXgH0iQN+Ckba3Ar+2YMSajLPHnLHKN7GF8O5PjPJj/lN X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6917df59-42d3-4f3e-c84e-08db6e9c4af8 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:55.6661 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: CWdmM1ww9hBGLBvwNZyT5nYkB3c20lfc/rXP8Fv3SmYuD3IpXrmU8oEEgGevVheG X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120304_130821_3FC49CBF X-CRM114-Status: GOOD ( 17.19 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org This allows a driver to set a global static to an IDENTITY domain and the core code will automatically use it whenever an IDENTITY domain is requested. By making it always available it means the IDENTITY can be used in error handling paths to force the iommu driver into a known state. Devices implementing global static identity domains should avoid failing their attach_dev ops. Convert rockchip to use the new mechanism. Tested-by: Steven Price Tested-by: Marek Szyprowski Tested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 3 +++ drivers/iommu/rockchip-iommu.c | 9 +-------- include/linux/iommu.h | 3 +++ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 9e0228ef612b85..bb840a818525ad 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1917,6 +1917,9 @@ static struct iommu_domain *__iommu_domain_alloc(const struct bus_type *bus, if (bus == NULL || bus->iommu_ops == NULL) return NULL; + if (alloc_type == IOMMU_DOMAIN_IDENTITY && bus->iommu_ops->identity_domain) + return bus->iommu_ops->identity_domain; + domain = bus->iommu_ops->domain_alloc(alloc_type); if (!domain) return NULL; diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index 4054030c323795..4fbede269e6712 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -1017,13 +1017,8 @@ static int rk_iommu_identity_attach(struct iommu_domain *identity_domain, return 0; } -static void rk_iommu_identity_free(struct iommu_domain *domain) -{ -} - static struct iommu_domain_ops rk_identity_ops = { .attach_dev = rk_iommu_identity_attach, - .free = rk_iommu_identity_free, }; static struct iommu_domain rk_identity_domain = { @@ -1087,9 +1082,6 @@ static struct iommu_domain *rk_iommu_domain_alloc(unsigned type) { struct rk_iommu_domain *rk_domain; - if (type == IOMMU_DOMAIN_IDENTITY) - return &rk_identity_domain; - if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA) return NULL; @@ -1214,6 +1206,7 @@ static int rk_iommu_of_xlate(struct device *dev, } static const struct iommu_ops rk_iommu_ops = { + .identity_domain = &rk_identity_domain, .domain_alloc = rk_iommu_domain_alloc, .probe_device = rk_iommu_probe_device, .release_device = rk_iommu_release_device, diff --git a/include/linux/iommu.h b/include/linux/iommu.h index d3164259667599..c3004eac2f88e8 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -254,6 +254,8 @@ struct iommu_iotlb_gather { * will be blocked by the hardware. * @pgsize_bitmap: bitmap of all possible supported page sizes * @owner: Driver module providing these ops + * @identity_domain: An always available, always attachable identity + * translation. */ struct iommu_ops { bool (*capable)(struct device *dev, enum iommu_cap); @@ -287,6 +289,7 @@ struct iommu_ops { const struct iommu_domain_ops *default_domain_ops; unsigned long pgsize_bitmap; struct module *owner; + struct iommu_domain *identity_domain; }; /** From patchwork Fri Jun 16 19:02:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283119 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 90265EB64D7 for ; Fri, 16 Jun 2023 19:04:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mE9GaC77F0LP913jP5b/fM3WFDedlsKQ3vi18yXtSH0=; b=zAm/jB+RSZ3mhT S7oIeS2AXz+ErsYnu4nsW0ue+OnPKLlxq3N7YGQtczKOXVndv661KOMZXMrls10iucOX0I+SadEGI VJ89QhParuH6tOo2QbfC4X7dxb3WabmLnIq4xWwuSz2t2S2UCK2R/FaylR682o0rRjmarCmHr/Quo 9NGhRk7H7E1Z/mzR36lhic9ANUaCEPId7hBQmdH7HMRMPQE36suxD1oSK2RUfbkpuhkiIpsyzuTu9 /VXdBd0h0j3J1/cXFfFWv/Lk6LN86WIEKDk874C8erh/lACli/zQZaSBCJ67+h7St0z0yXg65IZee srtw77KoNZPd5E8PoLpw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAEjg-001Xpk-1V; Fri, 16 Jun 2023 19:03:52 +0000 Received: from mail-bn7nam10on20620.outbound.protection.outlook.com ([2a01:111:f400:7e8a::620] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEiw-001X3y-04; Fri, 16 Jun 2023 19:03:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NGec1QE83DbfAPmsD6Vzy9peqLdH076xI/U7KTPlk9ABFaXJeFNSwjtajjc+3d/3BIlS6/TMw/mLNYOsJ9K+b19qOVw/lDPXpcC+RpvCSzv1k+1jgrFU0t5zRaW3peExNbuNU95uCrxFO2Ba3bee+ozLLIn9iG29V2EdlKOeccbYzv1BuZ56wnpHUp4LNqrdkr3Fw13jl6Ocd1zzcnqg7mjypEDmxJbyZHDDKcKsd1/p/lPPHaJ1cATyXTwoKdwm/4Tv0Z4hU8JLX0t8PxBjAzm3aOcQGn0w0+bXDvBp73omQLykQRZG2V6OQSPMGwsR/jg33dDkoM4cHYn2MRGhpg== 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=vjMNzj9ECgTiH26ByBwRnJAD0IolSUQ+Be7+5FtoCOo=; b=bQvIgef75Klu8OwmqcPEsyGSMPJh0paKDjus7ABq5KA+872azs0UxuC0fxrd/AeiYoaAoH3NWfNHYz6YZbDndVAavvohXhH8wg6w2XR0F//z9SvGyEnZFunMR0e54gF960QnCgm/SsAmTrMA4/I0Q4JTCGP4+wyu25wUYa9vUmx7oPj2o1sqyx/1tzjLfRbwDOxb5gzzmvRztDwrLpeIR16/BQQggh0nPQGcDuDgOQkVwHM1jsTpuH0gwrZQ2nUiTlh48zatJ9IZehBG9ZhEwQ2ec4Bf/oCZzOmMW0C8/9MCoRYnzNkULbn5N/pa8rV09HLjNqdC/JAE1F60hpvHpw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=vjMNzj9ECgTiH26ByBwRnJAD0IolSUQ+Be7+5FtoCOo=; b=GPrExGStfKUnEw/ZEk2LNqlSwAMMmp7LOxWTa09+jYwwC8seNItBvIpnEpHY6THMd0x+Ttx5oWY7cuWD3/rTAccLMQPY/OjtIDGzyoFUvqTqSKxdDpcFIDtQACtfpoPkCA76OIwydw7YaWFVnw7eQ1no6ObMi33/l8OVyY0Y4Cj3IZDg0/x/n3KI1pfBqjtcKSX2G0CC+2D3VMcNvI+a2s5pwHM4tkA8f4qpUE9aCHyvlxOqedxu9CibqkOx3S/aB6kVrmeQw2mK7WM8vdSNEk91tTnktzF3n11gcqRQht7tcbkiTvL82Q9ba6qyt02oyV3Zpfd05yIBNLQm96HYsA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:02:58 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:02:58 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 02/25] iommu: Add IOMMU_DOMAIN_PLATFORM Date: Fri, 16 Jun 2023 16:02:31 -0300 Message-Id: <2-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR03CA0064.namprd03.prod.outlook.com (2603:10b6:208:329::9) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: 7ebf6e83-3cda-46ec-ddac-08db6e9c4aec X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8m7HzXfksY4rZUFW16B+UtnhxIpmV0X0AvejhvDWUdCHpZTy8ug89GyUfs5HA957WYIZzzP01dG4g/2mE37Ua6mY2DQHbGlY8pzt3lryHkDXDEvnnI/wgCh1ScMfF4s3jo25SkVrLwyEpqbjVj1AR+xnk0BFzgvOPVkSG0QQI1rEw1kB/0D5C785DnEzrtUyocjCX2H2KJoNbeD3sH7kBvoMdDn34jtiSHeGvDntdmc2T8v5eX4qYtsRbXEGpN2RHozjNPAvrrDUEXVYdtnOgKjN1e85tjiyJ1SQv6O8/HLylTOsaiilpR3/5tTTYJAKUgyIADG8xp9bQOg1RpvDVx40Gg8So1tWF5G90wQr7i4F8BB1qqrjcOo4EkHWfXo+rojMbTPfJ8+6DFlAytXdyVDpqP+hyhOuOa+gLiEYJ+3Zvm1EIyvwqIAqJZAmpe5J510Y6kDnvjuHH8L1rUct6gwvdC81YfT9VbTq6ZgbibAcXUz10ChPWw7Boy5O97QjdmnsKiRIulwE2qnlUVmRcIPeaSg9V49toIPQpZjUtN+Bredu26YHpGhDZ1eEJOVKuE+TBufrXA6kP+JsxqwEkJIGPxGs5jbdW0mRfeNojZMdW4Tu/XV57aD7t3lZnO9f X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UK/a6fMwYmb913nD1igr94THvMguKmcos2SExBxWZQGMjBMsDjOaETvlVI+eoZ/+BUbAOTWnPgarELYrjwsNRbGooRiNhxvObviAaAlJurTFczc8NQVARB2rGsreqOcEVqLB4vRr83eigdMeetOKPRXFGzC/3rkd1pN2/U3ZTvEnV8bCsC0bPBuRKcXfyDt+nQoO+mQkWqO8sU8Il9BHw1stzlUtTSUip3T4VzMp/ybwIMtK6wknCp7YKWezlXyv97iikKPIc3A++evGIEJmTisx2fptHuAWIxXhjJdYH3hmkkFoYczW/7LYTvh4sDevyvr3yo1zZ8ilIqdtMHtRKUorO4yTI0XTi91P9SDSkOgKiyTNiEJAtPHPvhzAG2OpdEjkWmFycxpPRrlXwjXAmzoE4b3LYp1zQWDN0whJcPWvaMqHw0vy+kk/LYNJvmy5dGwPaO7soD3V6stOJpVG9gh4mQZaxO+KtGp13H3Y7PBmff85OPTdShxuCqnjySHrC1HAcJuSxbq86psgZ0JZsQ319YMEJaRTDepQ0aCPrDUt5EMgUKcU5GWm7gagahyn27U+/F2CcX2aMCgxVq58/V6gyZlmjpcS2PU4XlQTG6nQC0HGOyv7Sd4hVY7eksm90vOTzxxXX06F5D/o8h1PTJbB+HGRraM40/EQ5XT7oQPR00mpRziw666N7fl9Famyozw68RRxaez1rk0m3RT7EfjXzjD6Mj2glfIX1r3u24CDANP0lwiWAeT3vKAw2d4s0s2Kf8xHb2joBnva51Jv31K20wgoziBaMLvQbcL1erOItGnESHFR+A6lzuUVZIYjAzFS5hZWe+qyJ+h5ZcWKqyBqtC0dlmD68f7UdT+cVIlYraQY432L29l032S+e6DWsut+1qf8LovRqre6YpvTcog7UqOtNV6xO09G2ZxHLfuLdUwiq0LWIAtqNgQurS9DZ2Yjm532WZi80wKstPLiKpFutxNSvN9iflQZGLXWu4QBYZvTE6JXlzYf0/wUXBznS8OqKkNGzszShcFZrhxrPjR0vwMBCsRcuIkYjevn+gtZGN7slPBte0pmGukSo+jDxc4/0vT1o+gpCJruseZSvda1Nni11KJVj8tEMPRmEz4WWysGSwiO9OK2pohJKwvnFiXTiWfF1GXoK6L3EK+YMN4HsLpZ8YzDP4WTAcCSTaiQJ9mA8b6CF+6BJ6UVr1QnSDd5KHdBga4a8fXCThwXI0k/uUE2xkUmKT1kHFUmIAhSLPX+fg3ZvAmH0AxXir6s6+3mVailxsX97Hh2O0ZiGFkmV18INB7ip/IvQv1J6tpGlA0fOxCUvNU3XcYRMJXYjZNvmnCMS24KxZqdF1QblQv+nkeyUdPNiQ3c70imLfxUkG1/1M9Gq8qae2/z/ryVYX62fxogRVJDJJxtya6VHrWJbtRXWOt3EB3kDXPQ6By4r9XwzH9k3Sl/GWBM0OhS+m9xa2TaAo9A/is5Jgvm4k9vgaZpU9p+P1FW6sjIt2FsH587BPGxKZc9t5pC8HDUujdyxkJS05Q2d+jbqDZgNL47dfAJehARupNNSjMlrBiG9YLkjotpape+U5pPO2os X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7ebf6e83-3cda-46ec-ddac-08db6e9c4aec X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:55.5605 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: A2Ctpc48InBh1CR88+GYB6ZZCxFIG0VeYri6jzytF8Iosqo7NQYV39vk+l+RxVAK X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120306_116187_0FBDA5B1 X-CRM114-Status: GOOD ( 16.03 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org This is used when the iommu driver is taking control of the dma_ops, currently only on S390 and power spapr. It is designed to preserve the original ops->detach_dev() semantic that these S390 was built around. Provide an opaque domain type and a 'default_domain' ops value that allows the driver to trivially force any single domain as the default domain. Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 14 +++++++++++++- include/linux/iommu.h | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index bb840a818525ad..c8f6664767152d 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1644,6 +1644,17 @@ iommu_group_alloc_default_domain(struct iommu_group *group, int req_type) lockdep_assert_held(&group->mutex); + /* + * Allow legacy drivers to specify the domain that will be the default + * domain. This should always be either an IDENTITY or PLATFORM domain. + * Do not use in new drivers. + */ + if (bus->iommu_ops->default_domain) { + if (req_type) + return ERR_PTR(-EINVAL); + return bus->iommu_ops->default_domain; + } + if (req_type) return __iommu_group_alloc_default_domain(bus, group, req_type); @@ -1953,7 +1964,8 @@ void iommu_domain_free(struct iommu_domain *domain) if (domain->type == IOMMU_DOMAIN_SVA) mmdrop(domain->mm); iommu_put_dma_cookie(domain); - domain->ops->free(domain); + if (domain->ops->free) + domain->ops->free(domain); } EXPORT_SYMBOL_GPL(iommu_domain_free); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index c3004eac2f88e8..ef0a0000f09326 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -64,6 +64,7 @@ struct iommu_domain_geometry { #define __IOMMU_DOMAIN_DMA_FQ (1U << 3) /* DMA-API uses flush queue */ #define __IOMMU_DOMAIN_SVA (1U << 4) /* Shared process address space */ +#define __IOMMU_DOMAIN_PLATFORM (1U << 5) #define IOMMU_DOMAIN_ALLOC_FLAGS ~__IOMMU_DOMAIN_DMA_FQ /* @@ -81,6 +82,8 @@ struct iommu_domain_geometry { * invalidation. * IOMMU_DOMAIN_SVA - DMA addresses are shared process addresses * represented by mm_struct's. + * IOMMU_DOMAIN_PLATFORM - Legacy domain for drivers that do their own + * dma_api stuff. Do not use in new drivers. */ #define IOMMU_DOMAIN_BLOCKED (0U) #define IOMMU_DOMAIN_IDENTITY (__IOMMU_DOMAIN_PT) @@ -91,6 +94,7 @@ struct iommu_domain_geometry { __IOMMU_DOMAIN_DMA_API | \ __IOMMU_DOMAIN_DMA_FQ) #define IOMMU_DOMAIN_SVA (__IOMMU_DOMAIN_SVA) +#define IOMMU_DOMAIN_PLATFORM (__IOMMU_DOMAIN_PLATFORM) struct iommu_domain { unsigned type; @@ -256,6 +260,7 @@ struct iommu_iotlb_gather { * @owner: Driver module providing these ops * @identity_domain: An always available, always attachable identity * translation. + * @default_domain: If not NULL this will always be set as the default domain. */ struct iommu_ops { bool (*capable)(struct device *dev, enum iommu_cap); @@ -290,6 +295,7 @@ struct iommu_ops { unsigned long pgsize_bitmap; struct module *owner; struct iommu_domain *identity_domain; + struct iommu_domain *default_domain; }; /** From patchwork Fri Jun 16 19:02:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283115 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C6102EB64D7 for ; Fri, 16 Jun 2023 19:03:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ioYKvUQinIwOauHqDfkxql8wC7EgIiTT0+2X/ehkQpE=; b=qCAiUf9ZOjNLDh rnzz5JGCL/FnSzOweD8pUM5NbIi+SpUAi0EMx2bVAeVqP0i84E+zpdl3268UbOpfyK2FRXtixo+tO ye1LqoI8ApuKfQUI/rixyy18eBB0vm+/WUnnsT84TJ6S1Cbg02eNUTYswDHb/97WtisrTnjXdxLoo MJxBEyDQnb3K/iuLLXf6w89aCFSB8IqRZrOWoNYukMwv1HKg7UIljIvcBsb5qwJFiulFHKE62iqn5 1eysSM6YiETdqTiknLmBbbWpd3SG3BOkpk9SeblQenkDXzIfMM5xau2Bav4PWPV6gyIIQBD22O84W lh4Ffm2amE9vOmTXKDuQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAEj3-001XCx-2p; Fri, 16 Jun 2023 19:03:13 +0000 Received: from mail-bn7nam10on2062f.outbound.protection.outlook.com ([2a01:111:f400:7e8a::62f] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEis-001X1S-1H; Fri, 16 Jun 2023 19:03:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bwiRq+w97h2KBRcela5ePlCGIANVW46bp4tOF48sPJlqKTnN7swN2cbkBvWF9k47zT9lNzQcndTxfTts4wHmT9S3XVLWpCpxoZcFTaL20hY33HVZw8LEM3yzkG5GrLF4Ez80e9J1h1mkj51jTFdwhawOhLsWYnmkm5l9E9CuorsjCAlJDyQxg6qsrhN5qf/H/zZ4QytlLaB7uSs4JMmEsA2cfzFQSV35tAVSDfMcrVL8vqsuVV+F096LpYA6Idxt9feMLX58PCbA0eaPFL+LiTM7QNi5zjyv94lpuNk2GAD3qhhUC+tkJLpemkC7jqwMprkQtxwecaBd/5XqIhptAQ== 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=w0IYW6GJyVFiPWG2flp9VBNO5eU+viukK8rqNAbYods=; b=emK7MmONgTeT5x00wvZhWeNySTxerVzMUIRmorbgblV29eQAZEWzBQEH8W78fbImcjfJpsF6ZnEcwYkyimtE6BXZRUrUTTiIUvoxmUULWLGcWjc/6Ik/kBd7owYWM/uYT7+rTxipBLfvb8iXZ+/mECYgBnJLVO9E+QVxCgGpMA0sEsEzM8rVo449eLh4W9iXjZ8WknLCQgBkm1wZe8ysdtUThLL1Fh/Dpji4V5tU0m+N7q650jeHnwK3PSrOjtzzxsXdEL/sN1dCLIT05Chx6GzPYKbRY1gl93FPIMk99o96GDoTfKqwr3Op3BioHWKfdn+xXpXhSqK8A5S7QN0a0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=w0IYW6GJyVFiPWG2flp9VBNO5eU+viukK8rqNAbYods=; b=GTPD8ONHaU0LezpP7x5wBd4zqKS3levxHXqsGGaTRPVCzpGf46nWYePhUW6pBMp++3b8KY6UMP6ndWXNTVBpLcR5grBrS72dPLd0YZyRdAt4AbxoLaBmfWUe1sJsvCkLOsdx2bmN/C3SJkBEfVlicKugimkI0omZaQqwryhYAIQFFdmpQiQjJsrNylddVfc5wRTHY9fS7+BAasxJjfk528U57PpTK+xSmhyOgpJL58rwWiJHzgZGjbmUk3UKITGllxSqy3NUNgH3ycO0lMbVNet/V1ZjXplCDPcEtOXEWtlcJngpd87BrUm+VSUK0gfT+gTy7dbIE6bFfTMEjfAOBw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:02:57 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:02:57 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 03/25] powerpc/iommu: Setup a default domain and remove set_platform_dma_ops Date: Fri, 16 Jun 2023 16:02:32 -0300 Message-Id: <3-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: BL1P221CA0005.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::19) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: c4a91485-1b41-428a-b676-08db6e9c4ae5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fBa9VnyFRHphLXKFCM2lZtE19VQhnifvAAXXqlRQotWxQDUtnDX8zhSLrOOwaTBMIo3OwpCuJNA39vmzra1X806qmVFwFLEG4a1H4mEtHLfAYvkcBGRetvDZXXdHQ5vM3BCLITvkckkTQMbEjbt6DCjVbhzdrmqPD02SofMUHbSjHAzTfN87Bpw9c8PIKRrG/+3RuhxIs/VgTRljfrDyYUI5Usmtzp7+gcA8oKYU5Z1xmQgsiT8UdAzdxQHQmbsRHGplQJYelcBw7A8OQ1jUI2kp9rm7ThKWYuI6RB70EWYYpgEgslISAWu2otDoTzaNimBo+Sz4cs252p4EX64c5K7lKdrXoGw5/7hFTG4M/tAOZD4hAt62BZrjx2e5NjVPtn3Dv6usbES4E8BkSqzZ7Vk/mCt+HluJLjc5fHRBpIZWHt1yNIfAx33Kdxa1qy9vpwq/7npGZNcC6uDnYwYlBBSoeMvSZ6J5aEvJEXrki06D8HJ436S+4KJaIPMC/uGpjivhVqRY/hG5vHjWJytUftNd99bmkIrPoNpmu8cu46lvPRw4trWa+U4cdzXaXomY7zUZMZiCc/czpGbjc7prCbVVsy66pNs631z38bpuFClbIZGOj8fuuBgwj3qnBGnC X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zKwQdTkaioHxvkDk3Sl6nnslP2ixZRT8kZDLZ4flJAT7Q5CJPiC2J1/Kaf5YYhsmaLPUy9FiXCCpfpyg/xEDnxBfe3D0BCnbx/LcLWhtrvBj8JNl0nNBSwBAmm4S66pCcxuN8CyhV6zq8651I/1kKMEwHMoWLB9KrlZ06pCcdfe+dSH76lRiafXge0/DIqTsmkk9V+PJhNyoaw5xcd2v6j9hDOu8iEhi2Z3rZ3GDXBJ1WHz9OJYCWxE+IsjUBEjILn8Mm3QRBfK7CAh/hF3WRDS+qlR2v8zo1+/2mkt6OFfi4B1YNJe3og3N2kXbhiwlaSy6GT1Ozxfj5vkm1QGgMOrJNtWcUBGtPw9mSuU2IfR4Y010excDaR9T2Rl2gorICjpwZKs+L6uCP/mJSysMSFQhNLbDAxeVjTw1DwPq4YZSAmSBEASCy9dohCqAb4X9HA/8rtTGGDkhyLJyDtjdnPobXbO7vh5U314T5us9V/zaD1/h34zZPMwxs4/WbmJH+e8rrCERpzt+5WBeFOgVtPydMkwjBipnTFtZMXAjwRfIWFDIpF+5ukWK5pCzxftDv7KzdBXDA+Cw6Yk3ZrglXZi1LNT4SIoFqP2/2THUmS3WyA4Cr3Y9Yhg+4gj1i3jvlg8F9hV0TXHst5Bg+GgDOr0BHCf1Jrs7Q43ItwhA+t9R+MFZwT9omzLQs1MrS4zsJs22RtQB5H0ROYFZi7W52tHTsV2dybUDXfpJ2CsvH3ItSp+t4gXDYZ7f8s+9CP18VghBW6u2ixbFSaTxeK9ZAtLXbC01JJ+UEcidk4A1e80IjHbwPacNmGzxHvP+RY3ZOnrBg12PHm6itfge38Kwt1OtcYbhQqVDIeNubqhhPxUR9S32wslSNKQRftCeIHnveaAo3V9F+DCMOLnm4nB2++/xohNf0YRSW3uKDpGAVkkYUAsFOqpDAxTuO8+bjQWecVCclD3ZczF6/sVYhlT4vbFLv3f7lNsHiXr3V6xAHz90nzhSVSs6wCLeo/Y56jgHQCaoGMXJCF4vzOltdaarjrBawNkgZQJwPCSPCL8BOg1ySYfwdRAHZj/Afte9WMRL9mznmRSSuA6YLNFtSk1pP8xa2KcLj99B4SRvPXEt8OrC675LS4JnQWr+ayOGnN+gDjiiZKGfBdK7Y2R/VceZ5fieNdY1B4R1+QnbhQnebH0pTVCfV5C1niFazrJQj3zhAvIC2nP/nVqWogdsUyN13gSabGZGeoWE1VXrCEDDVCrsVhMva3TzXIRgEcR68MFAxDP7+4klIwiOlHfzjZBfwMVMBb+SR8TTfK0C/+35xmupU0SrHzJDl6S0DZ8nRLSgAMsUHqB0NxHQ04IwpRWaWlS0YN5LgTvok0To03bPcl7Rn0lItewvBNliYogUit7WQAdxSp9jY0L5RT5MeCSqHTiiI/jByjrUZIBf8OttH0+rcOoHuNdmxyETsKTlRVvSkg7cZ2nGv1pU1/GtM2KC+ycfgNKNHZM+Pid8QzhFjdY4yV3zMw1UDpGnaqTUSI5PldA9+BegMICWUIJQMXwMPRBvdlijmrEmRNkbhmj1RiXoTqsYCvGxUFUnninUH7C6 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c4a91485-1b41-428a-b676-08db6e9c4ae5 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:55.4828 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6/gWwCOB/P+no1x2kfJRyUfQVe4iBUHDrj+OTmbxkxzIRNabZtbCnm9IcgbBgnJT X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120302_436896_3140B0CA X-CRM114-Status: GOOD ( 14.66 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org POWER is using the set_platform_dma_ops() callback to hook up its private dma_ops, but this is buired under some indirection and is weirdly happening for a BLOCKED domain as well. For better documentation create a PLATFORM domain to manage the dma_ops, since that is what it is for, and make the BLOCKED domain an alias for it. BLOCKED is required for VFIO. Also removes the leaky allocation of the BLOCKED domain by using a global static. Signed-off-by: Jason Gunthorpe --- arch/powerpc/kernel/iommu.c | 38 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c index 67f0b01e6ff575..0f17cd767e1676 100644 --- a/arch/powerpc/kernel/iommu.c +++ b/arch/powerpc/kernel/iommu.c @@ -1266,7 +1266,7 @@ struct iommu_table_group_ops spapr_tce_table_group_ops = { /* * A simple iommu_ops to allow less cruft in generic VFIO code. */ -static int spapr_tce_blocking_iommu_attach_dev(struct iommu_domain *dom, +static int spapr_tce_platform_iommu_attach_dev(struct iommu_domain *dom, struct device *dev) { struct iommu_group *grp = iommu_group_get(dev); @@ -1283,17 +1283,22 @@ static int spapr_tce_blocking_iommu_attach_dev(struct iommu_domain *dom, return ret; } -static void spapr_tce_blocking_iommu_set_platform_dma(struct device *dev) -{ - struct iommu_group *grp = iommu_group_get(dev); - struct iommu_table_group *table_group; +static const struct iommu_domain_ops spapr_tce_platform_domain_ops = { + .attach_dev = spapr_tce_platform_iommu_attach_dev, +}; - table_group = iommu_group_get_iommudata(grp); - table_group->ops->release_ownership(table_group); -} +static struct iommu_domain spapr_tce_platform_domain = { + .type = IOMMU_DOMAIN_PLATFORM, + .ops = &spapr_tce_platform_domain_ops, +}; -static const struct iommu_domain_ops spapr_tce_blocking_domain_ops = { - .attach_dev = spapr_tce_blocking_iommu_attach_dev, +static struct iommu_domain spapr_tce_blocked_domain = { + .type = IOMMU_DOMAIN_BLOCKED, + /* + * FIXME: SPAPR mixes blocked and platform behaviors, the blocked domain + * also sets the dma_api ops + */ + .ops = &spapr_tce_platform_domain_ops, }; static bool spapr_tce_iommu_capable(struct device *dev, enum iommu_cap cap) @@ -1310,18 +1315,9 @@ static bool spapr_tce_iommu_capable(struct device *dev, enum iommu_cap cap) static struct iommu_domain *spapr_tce_iommu_domain_alloc(unsigned int type) { - struct iommu_domain *dom; - if (type != IOMMU_DOMAIN_BLOCKED) return NULL; - - dom = kzalloc(sizeof(*dom), GFP_KERNEL); - if (!dom) - return NULL; - - dom->ops = &spapr_tce_blocking_domain_ops; - - return dom; + return &spapr_tce_blocked_domain; } static struct iommu_device *spapr_tce_iommu_probe_device(struct device *dev) @@ -1357,12 +1353,12 @@ static struct iommu_group *spapr_tce_iommu_device_group(struct device *dev) } static const struct iommu_ops spapr_tce_iommu_ops = { + .default_domain = &spapr_tce_platform_domain, .capable = spapr_tce_iommu_capable, .domain_alloc = spapr_tce_iommu_domain_alloc, .probe_device = spapr_tce_iommu_probe_device, .release_device = spapr_tce_iommu_release_device, .device_group = spapr_tce_iommu_device_group, - .set_platform_dma_ops = spapr_tce_blocking_iommu_set_platform_dma, }; static struct attribute *spapr_tce_iommu_attrs[] = { From patchwork Fri Jun 16 19:02:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283118 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 80C41EB64DA for ; Fri, 16 Jun 2023 19:03:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=34Ri4OeJ2xctrtMBUos/1j9tTey7CeRaCP4AHFtnykk=; b=JahTRU/VFQ6/td WkO5DPmqVfOrGKQvLA0H8KDIvZtqiw4sUkD2DtA7M8kCQxY92m5S1N9yyJIQBugrZ6X7d5TZfiZLs uJryQBh7H3vVGmYImoH2aWOFc04T4oLDtcIjTUSNBn9kKgkDtSOTOHE6AgTXudpD4tap6+Ue1Ey8y MDEZW4RJEL3UjsJvhTllDM4Ii8flzemIWJjy2ASLNTcjB0ypaLSJafzDOa6YL4RzTXMFYCZYNFFal 8lEc/s63xrTCQUqRFwIbG62Kdcj9sUMSRyI+TXR0A1ZYVCNDkN/t6qR++fugu3Fz09MYHU3El/N5q jl4mpQQIkihJj9IFXbtg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAEjS-001Xbm-1r; Fri, 16 Jun 2023 19:03:38 +0000 Received: from mail-bn8nam12on20618.outbound.protection.outlook.com ([2a01:111:f400:fe5b::618] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEiu-001X0n-1c; Fri, 16 Jun 2023 19:03:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Iz6f1AJdSUntP6dPGhixSdtOnktkj/cK+AO9mhe42+Nwl9JOsQtuep8SoNYvftg+Uk130/7haOYcVykZCwqbMmQYL3HA4ePIo5W/x6WghB7442nKprt/v3aXElj0R34SdMsTmysX+7JJWJGDM/YHX06TY2kiheqabHRzUJ267UyjZpU9Kp9mlf15OvASONLLgdl4azxttC4bdKHayY1qtwoAuSorLSbFKHGVD6ggbFbd4C+7OvCNgP8uoiF/o2lPZ3iNIZUZSBUy0E27ag1a5bVZ09FebfC+JFRjxdQISWCCnuKNhGQDGiqI9QIxbHcyCLMQ/CudUM59MZd6Q1Rdtw== 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=KWXa5iPUsdOK6aga88CkdY8DnvSE5VOlKfKrBPcpAvo=; b=ErRIzEDjNgMElSDntUJ/ix4mIzGphd2ZGdxEGawfJFmavll0k2Xl4Z6/qM2PsjtJ8nb79gUZF51+bVGjczSizSrtQrNeiAzUpnhTSqjUxDUD/7ADOYnHCkp5R7zVb+bkk954EIkel17feNN7har3v+mnIxH4Oa6F5wpewoO4AZy+UFqR97M22vBQ8NyLmqx/cW7V8U8mAjk1ytD1qCoqMxJp0IAS2YictOuHrFHIf/acufHzp2y7raOnShqd7P+gy+4EDbghe31o5bfY7l4Z+DdkrGItBJFH4Uf6JESdWOOuBpnEFZPEVEpcfcaASmJiM4CkDdcYrWGevZPWiRO4KA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=KWXa5iPUsdOK6aga88CkdY8DnvSE5VOlKfKrBPcpAvo=; b=nbeAzcr+PHtBQNjQ8kJCPAba9CKd/LSQeblYLl9icXyAw5W+Jt5opkxxksoLCACmYW8dzmCTrx0zN+DCqKJfC1kIdTHoJgfk1IkFrcbXwSpQ/e1Tj87sCY53d8Zcxt+KyMl8s1PcqQKJME7Ab7FygdubOtd1iQlKbJ/HmkS5vPDjsCC9FAohoEL5LveKcRvkLx1eZDF0TM3OAHlgHQ8T+ExdkgaN53cv2JLuLOCDGQIHuBijUXkmZo8uwkf/1U2B68tf873cxt2v2ywKrlTOTesQ58YnhVaRbKU9x5pb8cp4K4DPephIsg2Z3lNardjfJLlKd22V7eKdmgnnGbKlag== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by DS7PR12MB5912.namprd12.prod.outlook.com (2603:10b6:8:7d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.29; Fri, 16 Jun 2023 19:02:57 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:02:56 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 04/25] iommu: Add IOMMU_DOMAIN_PLATFORM for S390 Date: Fri, 16 Jun 2023 16:02:33 -0300 Message-Id: <4-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR0102CA0058.prod.exchangelabs.com (2603:10b6:208:25::35) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DS7PR12MB5912:EE_ X-MS-Office365-Filtering-Correlation-Id: f9ba866a-6dd2-4ba6-4256-08db6e9c4ad0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dbROQo7QWxy1gUHWkTL11kfLQi80Ynex0gWa8cZoyNwpk5I4XzlDK8LhjxxAW4VYQ8yDbu2mVQg8j2x5iUyqdt/E64hQ+t9tHbylCPF9QwCAc6EYG4tJ09imIRzcHqcUITZeWtam3aUVcbE7abUSkePbWTq+FL2N/nM06GA8T/5ymAZZ93iX4ioEyTSgP4/PyeZ9jB3uOvm+G8NvS3I3Pznq3HZ5DGYD2KwZJ7wo1HY3569fbcTpscKO41mqLCuDRXw7iBLXLUd3+suyuYdPKsc8pSaKgy/KJhU99nb1uZZCdURiHDX2D+uS4VUz6AIoUHYpjty5DgFuFRvlASUMK512FaoaB1rqca4AoKBbvH6wxze2U5/VcTYDcMTi90FbVcfdYDlnrnJPD9Lpv28SmZuepAIq51CnThNOua2TXcs4kmWBrsD/1J+2EMdomoT9esEL0VF/TvAYRoNhMKBF51C6lcjG1inuHddCQi87CjOf96x5i+GDtlijDhg4ZX2xBnYpWODbPJh4CZxPVbjScwOnv0DBr3cwYjviSG0+ay1lR1Oes0szBBPtDD6ZfJLNc5mSS6rq5BKFtaTLaAOV+ooLU4R2Z0UoPzq52mMvO4zH4IMrQVJUGrP3n4f74o7v X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(376002)(366004)(136003)(396003)(346002)(451199021)(36756003)(86362001)(110136005)(66556008)(66476007)(54906003)(4326008)(316002)(66946007)(107886003)(478600001)(6666004)(6486002)(7416002)(41300700001)(5660300002)(8936002)(8676002)(7406005)(2906002)(38100700002)(921005)(2616005)(83380400001)(6512007)(6506007)(186003)(26005)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nmQ/gBSSDTawJlt8poDqgezB7qJC9zBaUui07d5ep/u6y/LkDaRGU51gUM9CmcLFqoQCx8Ttu73rX+1nhIpZ72nHiQP9ppeFEin/K0oiSF8M5AkBfaZqoHBJvD27Uig/Dz7ICEKUy8fs2DPiDZ2niKh4r1ySgCxn/cEkKFR9hAOMkRWPhRIj24qUU5WbQAmQeit0Iu1pthPaGZQqclsOH7tDcZnKW2QxqSNM7HxKNBS4K/Yz0THimUI1PTGnqZPOw9VMCuUu3amMMGj4cppGH7cQZ9Iqg3yyR7TKCkbpZlWnn7MXaMJKEl6fiVQynHhZllGIrFdNAWafalCO2KkgSu2hd3+/RUwlPYKc+qzmlEEPxRhXfGh+/BQDb30fhsKRwy4lsVu+UFCfeql5DEqofCWRpJkzJhIX7T4O0PdVCk9G2SQcSPQjiX2+U8WFcSN5geubcboZhVZkLLWeo6NuZyZVbwd8fQeidd8zoJ8v8kuMtYi1ANZ/Cd4k81SWvGKkYqA18ZhXdaUha38TGUe9E4lKCaH0bSW5qTJdyp8Ytf6OlLuxUXphq4E9aoO2znownWksqiTB4kkkQLsCaGXd2kw6d3RpZi4FPwdXHZ7XlY5A31Ix7BUeC+YdtGV7RqkiTrQpm+a10nZsKBPxNqwFzdsWMQI68T1DrEfidmG8yHGdNExJr83j24IovACnEQ1U60w4fSmy7bhscmweh24oNWcquoqHDcm2ctbRb8U4VtQCKyPU4VsxbNZffVciitGaSKhADbMTnfpg/z+6L/mnQBakv1jOhylhraEKtudBQ8uTwQghxK5DbmCyAq3aZL0eShxo/iPOt2y+JXqcD8nINHKHkB/ZDUaGXTr+OMVvfo1IrhCtXuIz3z3i3PyG3+IrUhDg+7UGPtIDmzwfkGweR9qZH75413moo6uQeZxlYR5SCHYDZVuqvT1L65xkwDsUKTUQq9UGJto4zM01eN9NaYjOLDunse1+lnHHASVrtS+ySOJ7FsCcdwXKKH20R12NB4cY39BoAbI0hKqVP+UHLJdFabgYnpgEhiBdXRWwPU2m36XQU4YNLimuMMYm25yK5cicBS9q12qMxjg8E4cd/Fm0U7gxw9Fre4l0cutxJZunK0x1j9qvZkvJ90NXSemHPmvjByEzUv2PCCw1nXR/m4h644RZGAn0OZCiuf2FCYXDEq29hrVHf3UVpQmabUqfsU7+NIR9HPNiuwVr0xfJznIGIvyOCP1siOE44ebrORPtmK3KziINGPVXqGkmI/RgGsNEr0nuWezHOkUvrWE2B0BUOKKBZm8LB48iGui5LOhoCy71YcZ0TXEtBFaVii0QQtsvboHAxmKfJqn+0/TWNQ6osgkP8XgALXziGMJXivDMyqsscZQPLPjO+DNV/6CwL6u46xZ5Na7ALgv/adw1JfvMapJ2sIkXXpYKYSCsqia7mNMhThfBsl5O2p6Vmlg0sz0YKwlQeP6ZiqukGzbgj4ed0SDRI/Gb8hthG5pw1pARXsv140tp67y3aUP4sNBYuDnEaTWBZJBrMH5Uwi16upEaSMZfsIF20rFrpAWEbw0+g9qgLzJ2HG1AmDB2YGs8 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f9ba866a-6dd2-4ba6-4256-08db6e9c4ad0 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:55.3925 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7XBQA9TpbLHFEzlKKVlC/nnhXhzSbOc/5tbf4xv1KdFFFlB4kBPq68AbjE/SVrU4 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5912 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120304_559612_7E41EFAA X-CRM114-Status: GOOD ( 14.26 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org The PLATFORM domain will be set as the default domain and attached as normal during probe. The driver will ignore the initial attach from a NULL domain to the PLATFORM domain. After this, the PLATFORM domain's attach_dev will be called whenever we detach from an UNMANAGED domain (eg for VFIO). This is the same time the original design would have called op->detach_dev(). This is temporary until the S390 dma-iommu.c conversion is merged. Tested-by: Heiko Stuebner Tested-by: Niklas Schnelle Signed-off-by: Jason Gunthorpe --- drivers/iommu/s390-iommu.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c index fbf59a8db29b11..f0c867c57a5b9b 100644 --- a/drivers/iommu/s390-iommu.c +++ b/drivers/iommu/s390-iommu.c @@ -142,14 +142,31 @@ static int s390_iommu_attach_device(struct iommu_domain *domain, return 0; } -static void s390_iommu_set_platform_dma(struct device *dev) +/* + * Switch control over the IOMMU to S390's internal dma_api ops + */ +static int s390_iommu_platform_attach(struct iommu_domain *platform_domain, + struct device *dev) { struct zpci_dev *zdev = to_zpci_dev(dev); + if (!zdev->s390_domain) + return 0; + __s390_iommu_detach_device(zdev); zpci_dma_init_device(zdev); + return 0; } +static struct iommu_domain_ops s390_iommu_platform_ops = { + .attach_dev = s390_iommu_platform_attach, +}; + +static struct iommu_domain s390_iommu_platform_domain = { + .type = IOMMU_DOMAIN_PLATFORM, + .ops = &s390_iommu_platform_ops, +}; + static void s390_iommu_get_resv_regions(struct device *dev, struct list_head *list) { @@ -428,12 +445,12 @@ void zpci_destroy_iommu(struct zpci_dev *zdev) } static const struct iommu_ops s390_iommu_ops = { + .default_domain = &s390_iommu_platform_domain, .capable = s390_iommu_capable, .domain_alloc = s390_domain_alloc, .probe_device = s390_iommu_probe_device, .release_device = s390_iommu_release_device, .device_group = generic_device_group, - .set_platform_dma_ops = s390_iommu_set_platform_dma, .pgsize_bitmap = SZ_4K, .get_resv_regions = s390_iommu_get_resv_regions, .default_domain_ops = &(const struct iommu_domain_ops) { From patchwork Fri Jun 16 19:02:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283128 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5D189EB64D8 for ; Fri, 16 Jun 2023 19:05:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yGCG/YtThgNr/bxmHa5Tk3zj9TrJR0xp/IhsivxIjSI=; b=pWdBgMsDO0cUYB eBbfw98ieM7ZBaslSh72FLYpJOzoOqHTXH9dFJm4GKhSud6fk7zxXyl3FiDFGOaBGkl3BzvKtQKX2 +7HLGFU8+IjrCiNaaaNyZ8BOtSKEh18TWsw1aioL9N/7eUNQZfnnu8qwTLE7tDNMxKocVi8TLLm2I QQbUnD7HZYLmaINCupLY6YITzVX6lv3L/Yjw5aRlDmu41xX6fpwk6lQVe4oCFvc+q5WmWtbVyHW5Z S2aauN/qhVqYq4+YR/C0Jo6jUUPePKwdUb0aQcUGt/n024K5QbxspUo1+Ue3+uE3TKJHKm3GwbV4c OSv79UL22rwu5IIKRldA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAElH-001ZEa-0K; Fri, 16 Jun 2023 19:05:31 +0000 Received: from mail-bn8nam12on20626.outbound.protection.outlook.com ([2a01:111:f400:fe5b::626] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEj3-001XAt-0Z; Fri, 16 Jun 2023 19:03:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KXvxli7oRWdCXB0NnwQp1HUPL4mkI1S3o5KdPGs/sbOFTx46rLvdUEyABvmkKbdqmKkgPThiVrHQKfDosLaEKdxztK5M0V5NW3BbT4Yy8iRIWiZFQgJJtp8J8uP3bTtluB7Ig5EknZzJy9eInI3OKLohTfYuMyWv9aAxP2ZcHE4fnS2k2MfvQ0gEIPytTcy850KvxfTZpJ1Wy9W0vP1S2INFPMuWoSs4CtK/+pOcKFoBqN67o0UZrTvHdvab3MKW1nGCidj43hAaExfqvkopV5utxtYLrYs0q8nslTplykxuN611+exnm9WZcn4amnRi/f4jsiS9MuQC9sHBRA0Vzg== 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=JNyTRyxbNWq/jd5aCXqxAkKB4mcTO+zABe+4bu/mqLE=; b=bPs5fPnpRfpQqerTkFIdifRVOmQr6BHcRllx86RRuRJjUbjiI3gzYlrCFU8iAOgAswPpjERNWS3M+DU94EC7b6Efx9lo4e9ZYjoUW26ZnXQCgjH38HHFFHAEvzWANQqlFSmshsg6I1XAXfSZl+bUegwgSMrS416ChDjnngcicbMttt2kSIU+UTNE/q1uwqd+9dGZSkgtHtT2Mz0nmA7sBXetkn2Gc37mURXLpu+wcOUnRx56WuHM1RgiXsB+3sZofkwAZWwgFrZQWfLxLZepVVt6pza/z3JHCPWKGXEL/XEqTeODinqfjqta8u1EiIIeeDvNF8qX5ErTaDtjWrQw0Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=JNyTRyxbNWq/jd5aCXqxAkKB4mcTO+zABe+4bu/mqLE=; b=tDjy0iNUjvUBMUuhIOGWeV8PQAQjK5jrV5xlVvZTa//F0h7j12CFOQBk9VcakkDLlwxNRHUyO2TC9K7Rdwo39SXZUXwoGST4gN0UMyDIiHF01XEMuzgNm7hrSP+8+nzqQbK7H/HenPsJAxFI9DFaRNUADNW3U958kLB34Ky4vvFPUsw/K8mzx4oRDQ8TX6Getj6Y8LkKZtmT/41hSPHN55yTCX8ZgbEjNYpJesHCiEbgs8WrPCLee0OOLqUioYII1WIF758JOzsUxrYvqYABhDx41ivdMEAGXCcUXTWzHuXeo5peFtTWP+bI5MLDu0zBraV6g/cSLW5m7snUH5mdxg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by DS7PR12MB5912.namprd12.prod.outlook.com (2603:10b6:8:7d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.29; Fri, 16 Jun 2023 19:03:08 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:03:08 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 05/25] iommu/fsl_pamu: Implement a PLATFORM domain Date: Fri, 16 Jun 2023 16:02:34 -0300 Message-Id: <5-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR03CA0062.namprd03.prod.outlook.com (2603:10b6:208:329::7) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DS7PR12MB5912:EE_ X-MS-Office365-Filtering-Correlation-Id: 479e6ddb-cead-42ef-fb74-08db6e9c4c1d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZvxooqNgZBmNAiyhlaxD4LFn3llK6tJV9lmNiwmjq/AdbR1Bx2c6HvFgcqsHICT7Jv9J6mLUC47oy+IYGTxkj9AKKJR4U2lPaN6bKc9ygkIts3tACNv97QoJyULS4MaQLh9wa/xkTv2CvUwnG8xJyBvmVGVtDNiyLVftv+ye2ga4tyekA3KHBtLyszZf2rcAjp03s4Csv1Bu43YjIk5RwQJcvYiarnTBEbWgqdXefifyDfYFC/hPls3zL+3nOw/rW/OABGZFqsiqCBmeRQUzcjYqMjM2/ZSiEJp0NCBb0pmhSKFcsxoeTD+YBY8jip19/fzLvQoFlm3rZIX7eG4zIWiSVo93+OGNylHqTTMwr9bE4B9qsSpYoAs3A0DrbecPVh2IdowHRbq1FBCy680gLElRMI01CBCvTD9MS1xESwr6k5W3I/FwkWTc8U3Sv4Iag+I3ANPi8dvT/ed8uco46aT0n9oouwwMaC2qlI19g8dCdEnO4VhyqULaQzKeowWouFA795HEBRGXZEFueEu1zGkp3zGJQDuVRftOB5oi/CIdVK/mWIU+3MXKoXA92f1amu0uIIiTysBsZJI++ClxdAXG9aPb3bdFpMc+c3OE1bR0yuaBqC3O6JF7hFmU6iaV X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(376002)(366004)(136003)(396003)(346002)(451199021)(36756003)(86362001)(110136005)(66556008)(66476007)(54906003)(4326008)(316002)(66946007)(107886003)(478600001)(6666004)(6486002)(7416002)(41300700001)(5660300002)(8936002)(8676002)(7406005)(2906002)(38100700002)(921005)(2616005)(83380400001)(6512007)(6506007)(186003)(26005)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 94nVWn5UkbfkQ4bJYwxU5cBNY5dSaAaKIwj3h1GbR8MDjfJdN+X47/hek7fVcLgmskWLkz/xMDETGSYRAC8i5nANEVCPGudYaBA3qG5KItWU5jy3+ZBzzn1vGU8PFWUKeoHsH0LAFx3GNo80+6CPO6ddkyIn6wMpD1KMQlXbOUmmZu0s7n1D8E0QXNUSTG12GOfka1mBDh7vxBCsYKT/+C7cWo4adMpm3OjRAzO1E5sjHXzfwcJQpsDgqfa3hTlTT+QiykM56IbSOh8Sy0PpFgGx6SD89btbtq745vPgpKen4I8cMQAeJ+ijks/xTBXEO2Q4JS8TUpkY34M5QY/meQBCMLkYAIMKZ73/Oy8gQUhXEqtPcpFYbH+QHXOrdx9NhjVb9QTlhcfcPKfAa2D0L41aJLFwkLktJknQzfHeWTOmWIk1bkKl/iuNZssAyt4PZYkyvVcgwine9VysJWCVEboyNZP1nBJ3KZ16ZJNNH5fJj+2TQUmzRZMv4MV45HMNiDbbAjsFQF3Q6dvIep/jtA4em4WGJAhqBNDuhRdvNbqFm1xXahTwzylybq99G7pDUILTsu8AV7FW7fLx8urcp9FZqvEfFYlqV3/33RvPHfum5nr4eFjoU/Dgx+kY31AlYPOLskBD0vf+gnMFQmPU3fsALqsPwKcKgNWVDusHrYAQhdzju/EEQa48igXfA2vUJY5kb6tLzSHOsmxwkMOe94chi5pfsjeRPnDrT0IbvssVvNXlj/GUp59iKqxmRfsU6HxP9BkIgCGehcuV4oKHfNdDG7vyuInR5a7MrH0SSPtEbboTdPE5F0yLKAgEa3OHvh0rea/Kmt+2MsY140QvGa3w4rK6xvvcviZLeIM3Oz0FOfzzpx6trtu21nsE4twAdsdw/S2RyrJrIPaxd7YJrUaBGt+0N5zJsUtgpVZybmJp1gAVG4QwWxFQ6xY2S+Dhe8gMd3cxim7T9aXdTsm3js8LeMINubZ5xgu/xT0dwkxUSQ5/Pr2bHUITzVwQwq0IzozrAlYnH5+cJ5eUS3EsJiSwZ2iMOGv+H2iAXkJT3pSsJMRG4OWKxcB6FS+eksCuYyyEffkv2zTzjSIMbZeooNCKJJiesMYIk8BA5eFDWXHTDp2XiQkUrV+e5oRfW0FIoeTcTEaEGFRjSK2aS0VNmRTtB6ZwDOuP5V9Nx1oe30Noxe5onbzug6qP8If/03wgOAqhTJfbZqxqpPGeqT/+CBiNmmg3a1QV56dDnbjHRf8JevPCxOSQojpCwenZiDTWzlN0Lnk4ssmFQsB8zGvvv62ZwkuyekysJPOSFsnWkGHu590yq6Iu/HC17FuKNN/ve/W79IIsajnFOPpSWfqtmUjC9ok0Lke7MxZ8EoiYymXH2/3+mnebvTeR8VCjx9AZDipg2mYj6vOZ5NhANm5FiCcetaH2qXfIxI2KygS4avs9F1VjLSqiplgWG2kNUHxVD2kD4mLh6P9WDqJyCtM02WSYlik6w5bOgmEvoOCpkwc7wM5SLCN09o5pOpT6tHe2aE1tOYyqpIeP07lEBx++2v1RazEMtg1mrZo9CJ4xLMi7U3MXDBMPi1kxgFPwPN+D X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 479e6ddb-cead-42ef-fb74-08db6e9c4c1d X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:57.5346 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: MU+Db9/kHQACuFcM4TZR0NZcLPNHdV3YhLrUcni3OjMrQX2lcmCkPhnVobXz8VMo X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5912 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120313_245699_F66EF490 X-CRM114-Status: GOOD ( 18.63 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org This driver is nonsensical. To not block migrating the core API away from NULL default_domains give it a hacky of a PLATFORM domain that keeps it working exactly as it always did. Leave some comments around to warn away any future people looking at this. Signed-off-by: Jason Gunthorpe --- drivers/iommu/fsl_pamu_domain.c | 41 ++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c index 4ac0e247ec2b51..e9d2bff4659b7c 100644 --- a/drivers/iommu/fsl_pamu_domain.c +++ b/drivers/iommu/fsl_pamu_domain.c @@ -196,6 +196,13 @@ static struct iommu_domain *fsl_pamu_domain_alloc(unsigned type) { struct fsl_dma_domain *dma_domain; + /* + * FIXME: This isn't creating an unmanaged domain since the + * default_domain_ops do not have any map/unmap function it doesn't meet + * the requirements for __IOMMU_DOMAIN_PAGING. The only purpose seems to + * allow drivers/soc/fsl/qbman/qman_portal.c to do + * fsl_pamu_configure_l1_stash() + */ if (type != IOMMU_DOMAIN_UNMANAGED) return NULL; @@ -283,15 +290,33 @@ static int fsl_pamu_attach_device(struct iommu_domain *domain, return ret; } -static void fsl_pamu_set_platform_dma(struct device *dev) +/* + * FIXME: fsl/pamu is completely broken in terms of how it works with the iommu + * API. Immediately after probe the HW is left in an IDENTITY translation and + * the driver provides a non-working UNMANAGED domain that it can switch over + * to. However it cannot switch back to an IDENTITY translation, instead it + * switches to what looks like BLOCKING. + */ +static int fsl_pamu_platform_attach(struct iommu_domain *platform_domain, + struct device *dev) { struct iommu_domain *domain = iommu_get_domain_for_dev(dev); - struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain); + struct fsl_dma_domain *dma_domain; const u32 *prop; int len; struct pci_dev *pdev = NULL; struct pci_controller *pci_ctl; + /* + * Hack to keep things working as they always have, only leaving an + * UNMANAGED domain makes it BLOCKING. + */ + if (domain == platform_domain || !domain || + domain->type != IOMMU_DOMAIN_UNMANAGED) + return 0; + + dma_domain = to_fsl_dma_domain(domain); + /* * Use LIODN of the PCI controller while detaching a * PCI device. @@ -312,8 +337,18 @@ static void fsl_pamu_set_platform_dma(struct device *dev) detach_device(dev, dma_domain); else pr_debug("missing fsl,liodn property at %pOF\n", dev->of_node); + return 0; } +static struct iommu_domain_ops fsl_pamu_platform_ops = { + .attach_dev = fsl_pamu_platform_attach, +}; + +static struct iommu_domain fsl_pamu_platform_domain = { + .type = IOMMU_DOMAIN_PLATFORM, + .ops = &fsl_pamu_platform_ops, +}; + /* Set the domain stash attribute */ int fsl_pamu_configure_l1_stash(struct iommu_domain *domain, u32 cpu) { @@ -395,11 +430,11 @@ static struct iommu_device *fsl_pamu_probe_device(struct device *dev) } static const struct iommu_ops fsl_pamu_ops = { + .default_domain = &fsl_pamu_platform_domain, .capable = fsl_pamu_capable, .domain_alloc = fsl_pamu_domain_alloc, .probe_device = fsl_pamu_probe_device, .device_group = fsl_pamu_device_group, - .set_platform_dma_ops = fsl_pamu_set_platform_dma, .default_domain_ops = &(const struct iommu_domain_ops) { .attach_dev = fsl_pamu_attach_device, .iova_to_phys = fsl_pamu_iova_to_phys, From patchwork Fri Jun 16 19:02:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283212 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E0540EB64D8 for ; Fri, 16 Jun 2023 19:06:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=d+A/mXE3FGZfObO4WhzUV+nzsXeSaf3DrHcijfs9ZtY=; b=iA7eKkjkYJFnBX YZTHFpu3PWHP217nLJ+zAU0h2oxmNwzt+6FVcNJW+FlPp1JE/QtdG/+SjVvofhzsCxidoDzkfINGQ /TLTuLFgvjwYiH8NtM2MLNDX0GwCk4Cnp9kaGrdjJse3X5TmcBQv5VijPrmuYNcGxi8CgWplQFoMO h5nxxE8kPZpVFG4HVzcCZ1hOIy3OFeNO6tVttGfTXzjf1aNOjehGzP5tD4+VX8IY68H7r0g3soZqv PJcDrRXGRsWntokZCAjC9Im9Fj8B1aCtVSyh5lJiSrP+2bypJZoF1NgCkiXcSW0lc0ZVvlstFIcY/ BVB0VazMO8vwQs7BEAbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAElz-001Zwn-2i; Fri, 16 Jun 2023 19:06:15 +0000 Received: from mail-bn7nam10on20600.outbound.protection.outlook.com ([2a01:111:f400:7e8a::600] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEj6-001X8M-2x; Fri, 16 Jun 2023 19:03:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=covZcSEax4lzUXPspRC9RN3G5I03Plc8R5NgsqnVM3BwvR0SzV/K2RCsRJjU2PmkmjVLr9DalqBT5tDVeWapTzbvXej4ZiTE7GWJ/MGEzO+LtFZuPDVJkURTQBrCPWLRTxY+52NF+GUieM7vGkE69BDpdVO9hznP+e3utmkdwg23uzmlwQtgkh+8GbpKmzmW2ZB/7J3F8b3JR/EkcmxCpswaXphVaArHdoS2bEdesS825CQt2KpbIRR/mLHdLWGDGGu8GXRzU1JMeaC3G9BeZ4URYGuqyqpLAOBcEyrph5kLZEGp8WDFAw77hv0onwM+ohEgEzv2seNeHCQhW4h2PQ== 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=AoBL9w7UcixSu9FZgSzhi/C9ixDLEn6X1nz74NS4UbM=; b=MJlCr8vxKwVyxzM+l9EJ7J/r+M5NMMBS8Z/iFf3pPuFYxF7vGofIc5xv26veTjUt/v0wFwbwj2CFtDFVdXsAj11p46tKCpoF4iw+bQPl7lBUveIfdTmuwsI6qbD9GVG5xCdnJqV8VgBvUeWEE9Rp+mJ1V33CBdexNrOVIlwhRyAzk/6OHny0LpPl46NEBcdnrdSldyVjyAWeepSjDZy/H5+xnsMEjsxdllztLXlzLcySrK1sAk+AwQcbV3jMJ8XQs0y4N77ZwVkSu1W6p5q+DOBWhoiib974cG2ocDMfeqYoodwPUZBEROfdwhdkGTxIjlw0V6/Dn8hHmmKkU3xNcA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=AoBL9w7UcixSu9FZgSzhi/C9ixDLEn6X1nz74NS4UbM=; b=LvogzMCuQHboWtyxpk1+uXI/DWMEzduFfj0m6SEr9MlRj54GeBIggjnrLRlheMeyUjmLZ05pMVYvpRPUdQJ+tpfDraJfJ7p/enCbBPe5AyLVlCB6saAZuH/J4d0v1FckHYLAtAKVF8dhIklw1v4CRyD7DEnY3fRE+WRp8Hl0qekrE6LcgyB9Brmau8khLfrsKpskfZoWIF4B11UZbVhva5WG4zovW+i9BuascMrR1Lzk93xJj/0pHbKuOt/m5uSPTnB+t8np7Re/ZnoLoU5empHSK2rkz8CRMX4g4F54YRjittziLaWVgEKhEpC3/KVpgGsrSI68F6ez8xrWeO/r/w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:03:05 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:03:05 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 06/25] iommu/tegra-gart: Remove tegra-gart Date: Fri, 16 Jun 2023 16:02:35 -0300 Message-Id: <6-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR03CA0087.namprd03.prod.outlook.com (2603:10b6:208:329::32) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: afb2fc59-471c-4781-696f-08db6e9c4ba4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZbD52n/N8jca00G6ZOC4V7wVFmjGjyTojgm5+b+5fo+CXUwUEEHP2cmeCBWL+5+gUtg46upw4Fjww6eL9X1Onak/pyO82mBexdg4xJqfkgEu/HHqzFDFXKdTaqIUHiIagml327+vitEMd9CzESQydBh9t0YCpDfPc2tVVVGtsDv/tJCF6CJhqd7I3Pt6FTAg9Ai8X/5rWf9n5rOaYnfo8pIdlkiziDgNSHfpG80HhqTEf7Pjq1o5tXL6GpA0SbaJ/6c37JbiQ9uddInmqRpMTXVIx4CL29I5F78+0vSEOssUYxn2aaDC4szfLeMD0BzjwPYt3ezCDGUG8cfRMLwqbVpxbZ1oSJbhMOlSShPSFnq50SvuAo3p6t/KA0cnfBggIxxLKASqGSwthrolY9mZyRdxr8nCJqToyWP+8+fHTYmziGN/buAUZXT4Fkm7AX3K1+wI02+m5AW5fm6z/zMyX8sbWTYhKXr9BQBx51j282V89cjPDkgaaGUWVTEvWXQH0+LtBdliLmZWu9XJeMltr0DyU46i9S9CfDSg668jVty+fxd4eDNENiW9rcG1UQM6k9zOoHVOcWWAU0/y3Vfo1qK+kac31TTtPHD+8VcQD7RbBozaHM7o1vKL4y0O3zxU X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(30864003)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Qmh2xIyahDn1fPQA5Adb+zusI3yqXG2pO9LSvHPM0WVv+z9bUeQpTKlhuVXLz22MrjHt+VMMaD5S0CikFm3b3nU9TESvqG9/IRGxeDJyypzNLHi6Okaoe/YUNFXcDOcdezDG1/IYOOGL49c+jFABCBnqSQeYIeY54GHmzw7ejaCUlLiVGdFAYYBmxpSvWbFZG+yfaq0439k8EFeqgYUib7rhXYEqQ0q3TW0Vw8zZmV1va+9PcYtUABptv7vgYaXNd3PCoxi0M9zmV5gXRXtz0R4RR60pefD2BV1DAnu6BDxyXhq1+XXRcU6C1lJcgm0VbRqpW2wme/MtHPBF5dkMiW8ZHnCYwemeyX3rXp0wvhTyj7cJWb+xtFFUZYSsDyd3ddz049vgFGUW6znSTLsL9y9YV84L72MUNVLT2iBXR/PvVQmFghFn0BPL5vPRx6NKm3qi1gzaCaJnNW2s+i3fHZFKf6jVg1Istcw47JF9VdYbOFrlfcqp9GyHt2yzRYmqBv8on4grvzyIVpmjM5AfoaMsYn1IblYQ8eTRXW0qn+c1pWfWTi24+1/iM1530vEnYusRzs56jFQS+9OO3yjq1CxD80EAnb4qAQXVy2hJPbpJaC2GCnOFocTYrwm8CQ3WhJum+fCiGRPsQRjmIJc3jCCi81r/rAQxFuZRiMyO3WgkbJM8W7iHbeGrmuSNlcg+isZ/k27ohA2fHRSdjTuc5dlcM//niG1aPoYRg25SLWCvWYlMpu3jd9QeU6aKY5PqTbhwAlX84KtkSsLQLyekZsTos/oVC+eVO1s2psL89KPfAK4Rc9MtqRhRodZamHw9KE5f+i+/UGFopmyLu6SjgEtA4qkgmnfDiWx/Mx5rH2VuNZGrV7XWlKdfJ7desDXr0iQlIA8wNTLoGEuNRPKvTYndrOz36s4YXn+DcirGRvncgvL2cSi6grRxraSpsM8csOOvvVQu8+7e9a3e1au9kmBpqm/LLj1fJDTnbqkC11f1FzGkdl01DPpLbJZcHKASKqec13lw9xu9ZNvj0GlhXwp/gu4a5mMAPkWWQoIClZh9kjLNnPV//1xUjQlJdpipAzZ5n+/8LzmGkyavX2bgKzkL3nvkpzz0y5kDQm9EzwBI6MD7qaKuhVF64od8nPalIay/hOk1s2lOEWN/ZhlojgJCxp0bb9s5+fIXkfDi4DXwbUZ8UV0sN7wgiuM4j9DCfv3xtQe1wlMduSXuUxS7RNMyZJFG6V++Kd52RPAMxqTrIr3MGLaRCAtBsB2yakPlCgHfjcwDINfbz9gkC6R3JOvdyJIHGee7okx4rgZ45NRCDk3+ryDS1q2QWnK8Fhs3uowwacskm7GEThRwBxCg5fzd0h2/J3PorD4mt0Xvd+BuLeApOhnAViBRZAJzelr6VpfTN4biWBUSM06hyKTZVVNcV5DQl4L0k+Qw2VHB/0SZG/RLuS1mdjd1iRPewVyMI/WGcDWTZNy3gLYuR0AqDtv9GeCzVVjE1KxlMtuJnCWo66FY/6OYdD+vL5N4PBNJBPi/GsWJYB1aHhF/Okn8mhrWd+wmwBrLP5USG9K9Nwnp90YOS6MY+tn564EJ3R/G X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: afb2fc59-471c-4781-696f-08db6e9c4ba4 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:56.8911 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rjvFI6hvIHaQzCsEk4OlS2AWk/aq2OfEu56E+sEtnnxvqV2nK5MAkzoQ19cvS868 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120317_022495_7B7BBC76 X-CRM114-Status: GOOD ( 23.53 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org Thierry says this is not used anymore, and doesn't think it makes sense as an iommu driver. The HW it supports is about 10 years old now and newer HW uses different IOMMU drivers. As this is the only driver with a GART approach, and it doesn't really meet the driver expectations from the IOMMU core, let's just remove it so we don't have to think about how to make it fit in. It has a number of identified problems: - The assignment of iommu_groups doesn't match the HW behavior - It claims to have an UNMANAGED domain but it is really an IDENTITY domain with a translation aperture. This is inconsistent with the core expectation for security sensitive operations - It doesn't implement a SW page table under struct iommu_domain so * It can't accept a map until the domain is attached * It forgets about all maps after the domain is detached * It doesn't clear the HW of maps once the domain is detached (made worse by having the wrong groups) Cc: Thierry Reding Cc: Dmitry Osipenko Acked-by: Thierry Reding Signed-off-by: Jason Gunthorpe --- arch/arm/configs/multi_v7_defconfig | 1 - arch/arm/configs/tegra_defconfig | 1 - drivers/iommu/Kconfig | 11 - drivers/iommu/Makefile | 1 - drivers/iommu/tegra-gart.c | 371 ---------------------------- drivers/memory/tegra/mc.c | 34 --- drivers/memory/tegra/tegra20.c | 28 --- include/soc/tegra/mc.h | 26 -- 8 files changed, 473 deletions(-) delete mode 100644 drivers/iommu/tegra-gart.c diff --git a/arch/arm/configs/multi_v7_defconfig b/arch/arm/configs/multi_v7_defconfig index 871fffe92187bf..daba1afdbd1100 100644 --- a/arch/arm/configs/multi_v7_defconfig +++ b/arch/arm/configs/multi_v7_defconfig @@ -1063,7 +1063,6 @@ CONFIG_BCM2835_MBOX=y CONFIG_QCOM_APCS_IPC=y CONFIG_QCOM_IPCC=y CONFIG_ROCKCHIP_IOMMU=y -CONFIG_TEGRA_IOMMU_GART=y CONFIG_TEGRA_IOMMU_SMMU=y CONFIG_EXYNOS_IOMMU=y CONFIG_QCOM_IOMMU=y diff --git a/arch/arm/configs/tegra_defconfig b/arch/arm/configs/tegra_defconfig index f32047e24b633e..ad31b9322911ce 100644 --- a/arch/arm/configs/tegra_defconfig +++ b/arch/arm/configs/tegra_defconfig @@ -293,7 +293,6 @@ CONFIG_CHROME_PLATFORMS=y CONFIG_CROS_EC=y CONFIG_CROS_EC_I2C=m CONFIG_CROS_EC_SPI=m -CONFIG_TEGRA_IOMMU_GART=y CONFIG_TEGRA_IOMMU_SMMU=y CONFIG_ARCH_TEGRA_2x_SOC=y CONFIG_ARCH_TEGRA_3x_SOC=y diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 4d800601e8ecd6..3309f297bbd822 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -235,17 +235,6 @@ config SUN50I_IOMMU help Support for the IOMMU introduced in the Allwinner H6 SoCs. -config TEGRA_IOMMU_GART - bool "Tegra GART IOMMU Support" - depends on ARCH_TEGRA_2x_SOC - depends on TEGRA_MC - select IOMMU_API - help - Enables support for remapping discontiguous physical memory - shared with the operating system into contiguous I/O virtual - space through the GART (Graphics Address Relocation Table) - hardware included on Tegra SoCs. - config TEGRA_IOMMU_SMMU bool "NVIDIA Tegra SMMU Support" depends on ARCH_TEGRA diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile index 769e43d780ce89..95ad9dbfbda022 100644 --- a/drivers/iommu/Makefile +++ b/drivers/iommu/Makefile @@ -20,7 +20,6 @@ obj-$(CONFIG_OMAP_IOMMU) += omap-iommu.o obj-$(CONFIG_OMAP_IOMMU_DEBUG) += omap-iommu-debug.o obj-$(CONFIG_ROCKCHIP_IOMMU) += rockchip-iommu.o obj-$(CONFIG_SUN50I_IOMMU) += sun50i-iommu.o -obj-$(CONFIG_TEGRA_IOMMU_GART) += tegra-gart.o obj-$(CONFIG_TEGRA_IOMMU_SMMU) += tegra-smmu.o obj-$(CONFIG_EXYNOS_IOMMU) += exynos-iommu.o obj-$(CONFIG_FSL_PAMU) += fsl_pamu.o fsl_pamu_domain.o diff --git a/drivers/iommu/tegra-gart.c b/drivers/iommu/tegra-gart.c deleted file mode 100644 index a482ff838b5331..00000000000000 --- a/drivers/iommu/tegra-gart.c +++ /dev/null @@ -1,371 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * IOMMU API for Graphics Address Relocation Table on Tegra20 - * - * Copyright (c) 2010-2012, NVIDIA CORPORATION. All rights reserved. - * - * Author: Hiroshi DOYU - */ - -#define dev_fmt(fmt) "gart: " fmt - -#include -#include -#include -#include -#include -#include -#include - -#include - -#define GART_REG_BASE 0x24 -#define GART_CONFIG (0x24 - GART_REG_BASE) -#define GART_ENTRY_ADDR (0x28 - GART_REG_BASE) -#define GART_ENTRY_DATA (0x2c - GART_REG_BASE) - -#define GART_ENTRY_PHYS_ADDR_VALID BIT(31) - -#define GART_PAGE_SHIFT 12 -#define GART_PAGE_SIZE (1 << GART_PAGE_SHIFT) -#define GART_PAGE_MASK GENMASK(30, GART_PAGE_SHIFT) - -/* bitmap of the page sizes currently supported */ -#define GART_IOMMU_PGSIZES (GART_PAGE_SIZE) - -struct gart_device { - void __iomem *regs; - u32 *savedata; - unsigned long iovmm_base; /* offset to vmm_area start */ - unsigned long iovmm_end; /* offset to vmm_area end */ - spinlock_t pte_lock; /* for pagetable */ - spinlock_t dom_lock; /* for active domain */ - unsigned int active_devices; /* number of active devices */ - struct iommu_domain *active_domain; /* current active domain */ - struct iommu_device iommu; /* IOMMU Core handle */ - struct device *dev; -}; - -static struct gart_device *gart_handle; /* unique for a system */ - -static bool gart_debug; - -/* - * Any interaction between any block on PPSB and a block on APB or AHB - * must have these read-back to ensure the APB/AHB bus transaction is - * complete before initiating activity on the PPSB block. - */ -#define FLUSH_GART_REGS(gart) readl_relaxed((gart)->regs + GART_CONFIG) - -#define for_each_gart_pte(gart, iova) \ - for (iova = gart->iovmm_base; \ - iova < gart->iovmm_end; \ - iova += GART_PAGE_SIZE) - -static inline void gart_set_pte(struct gart_device *gart, - unsigned long iova, unsigned long pte) -{ - writel_relaxed(iova, gart->regs + GART_ENTRY_ADDR); - writel_relaxed(pte, gart->regs + GART_ENTRY_DATA); -} - -static inline unsigned long gart_read_pte(struct gart_device *gart, - unsigned long iova) -{ - unsigned long pte; - - writel_relaxed(iova, gart->regs + GART_ENTRY_ADDR); - pte = readl_relaxed(gart->regs + GART_ENTRY_DATA); - - return pte; -} - -static void do_gart_setup(struct gart_device *gart, const u32 *data) -{ - unsigned long iova; - - for_each_gart_pte(gart, iova) - gart_set_pte(gart, iova, data ? *(data++) : 0); - - writel_relaxed(1, gart->regs + GART_CONFIG); - FLUSH_GART_REGS(gart); -} - -static inline bool gart_iova_range_invalid(struct gart_device *gart, - unsigned long iova, size_t bytes) -{ - return unlikely(iova < gart->iovmm_base || bytes != GART_PAGE_SIZE || - iova + bytes > gart->iovmm_end); -} - -static inline bool gart_pte_valid(struct gart_device *gart, unsigned long iova) -{ - return !!(gart_read_pte(gart, iova) & GART_ENTRY_PHYS_ADDR_VALID); -} - -static int gart_iommu_attach_dev(struct iommu_domain *domain, - struct device *dev) -{ - struct gart_device *gart = gart_handle; - int ret = 0; - - spin_lock(&gart->dom_lock); - - if (gart->active_domain && gart->active_domain != domain) { - ret = -EINVAL; - } else if (dev_iommu_priv_get(dev) != domain) { - dev_iommu_priv_set(dev, domain); - gart->active_domain = domain; - gart->active_devices++; - } - - spin_unlock(&gart->dom_lock); - - return ret; -} - -static void gart_iommu_set_platform_dma(struct device *dev) -{ - struct iommu_domain *domain = iommu_get_domain_for_dev(dev); - struct gart_device *gart = gart_handle; - - spin_lock(&gart->dom_lock); - - if (dev_iommu_priv_get(dev) == domain) { - dev_iommu_priv_set(dev, NULL); - - if (--gart->active_devices == 0) - gart->active_domain = NULL; - } - - spin_unlock(&gart->dom_lock); -} - -static struct iommu_domain *gart_iommu_domain_alloc(unsigned type) -{ - struct iommu_domain *domain; - - if (type != IOMMU_DOMAIN_UNMANAGED) - return NULL; - - domain = kzalloc(sizeof(*domain), GFP_KERNEL); - if (domain) { - domain->geometry.aperture_start = gart_handle->iovmm_base; - domain->geometry.aperture_end = gart_handle->iovmm_end - 1; - domain->geometry.force_aperture = true; - } - - return domain; -} - -static void gart_iommu_domain_free(struct iommu_domain *domain) -{ - WARN_ON(gart_handle->active_domain == domain); - kfree(domain); -} - -static inline int __gart_iommu_map(struct gart_device *gart, unsigned long iova, - unsigned long pa) -{ - if (unlikely(gart_debug && gart_pte_valid(gart, iova))) { - dev_err(gart->dev, "Page entry is in-use\n"); - return -EINVAL; - } - - gart_set_pte(gart, iova, GART_ENTRY_PHYS_ADDR_VALID | pa); - - return 0; -} - -static int gart_iommu_map(struct iommu_domain *domain, unsigned long iova, - phys_addr_t pa, size_t bytes, int prot, gfp_t gfp) -{ - struct gart_device *gart = gart_handle; - int ret; - - if (gart_iova_range_invalid(gart, iova, bytes)) - return -EINVAL; - - spin_lock(&gart->pte_lock); - ret = __gart_iommu_map(gart, iova, (unsigned long)pa); - spin_unlock(&gart->pte_lock); - - return ret; -} - -static inline int __gart_iommu_unmap(struct gart_device *gart, - unsigned long iova) -{ - if (unlikely(gart_debug && !gart_pte_valid(gart, iova))) { - dev_err(gart->dev, "Page entry is invalid\n"); - return -EINVAL; - } - - gart_set_pte(gart, iova, 0); - - return 0; -} - -static size_t gart_iommu_unmap(struct iommu_domain *domain, unsigned long iova, - size_t bytes, struct iommu_iotlb_gather *gather) -{ - struct gart_device *gart = gart_handle; - int err; - - if (gart_iova_range_invalid(gart, iova, bytes)) - return 0; - - spin_lock(&gart->pte_lock); - err = __gart_iommu_unmap(gart, iova); - spin_unlock(&gart->pte_lock); - - return err ? 0 : bytes; -} - -static phys_addr_t gart_iommu_iova_to_phys(struct iommu_domain *domain, - dma_addr_t iova) -{ - struct gart_device *gart = gart_handle; - unsigned long pte; - - if (gart_iova_range_invalid(gart, iova, GART_PAGE_SIZE)) - return -EINVAL; - - spin_lock(&gart->pte_lock); - pte = gart_read_pte(gart, iova); - spin_unlock(&gart->pte_lock); - - return pte & GART_PAGE_MASK; -} - -static struct iommu_device *gart_iommu_probe_device(struct device *dev) -{ - if (!dev_iommu_fwspec_get(dev)) - return ERR_PTR(-ENODEV); - - return &gart_handle->iommu; -} - -static int gart_iommu_of_xlate(struct device *dev, - struct of_phandle_args *args) -{ - return 0; -} - -static void gart_iommu_sync_map(struct iommu_domain *domain, unsigned long iova, - size_t size) -{ - FLUSH_GART_REGS(gart_handle); -} - -static void gart_iommu_sync(struct iommu_domain *domain, - struct iommu_iotlb_gather *gather) -{ - size_t length = gather->end - gather->start + 1; - - gart_iommu_sync_map(domain, gather->start, length); -} - -static const struct iommu_ops gart_iommu_ops = { - .domain_alloc = gart_iommu_domain_alloc, - .probe_device = gart_iommu_probe_device, - .device_group = generic_device_group, - .set_platform_dma_ops = gart_iommu_set_platform_dma, - .pgsize_bitmap = GART_IOMMU_PGSIZES, - .of_xlate = gart_iommu_of_xlate, - .default_domain_ops = &(const struct iommu_domain_ops) { - .attach_dev = gart_iommu_attach_dev, - .map = gart_iommu_map, - .unmap = gart_iommu_unmap, - .iova_to_phys = gart_iommu_iova_to_phys, - .iotlb_sync_map = gart_iommu_sync_map, - .iotlb_sync = gart_iommu_sync, - .free = gart_iommu_domain_free, - } -}; - -int tegra_gart_suspend(struct gart_device *gart) -{ - u32 *data = gart->savedata; - unsigned long iova; - - /* - * All GART users shall be suspended at this point. Disable - * address translation to trap all GART accesses as invalid - * memory accesses. - */ - writel_relaxed(0, gart->regs + GART_CONFIG); - FLUSH_GART_REGS(gart); - - for_each_gart_pte(gart, iova) - *(data++) = gart_read_pte(gart, iova); - - return 0; -} - -int tegra_gart_resume(struct gart_device *gart) -{ - do_gart_setup(gart, gart->savedata); - - return 0; -} - -struct gart_device *tegra_gart_probe(struct device *dev, struct tegra_mc *mc) -{ - struct gart_device *gart; - struct resource *res; - int err; - - BUILD_BUG_ON(PAGE_SHIFT != GART_PAGE_SHIFT); - - /* the GART memory aperture is required */ - res = platform_get_resource(to_platform_device(dev), IORESOURCE_MEM, 1); - if (!res) { - dev_err(dev, "Memory aperture resource unavailable\n"); - return ERR_PTR(-ENXIO); - } - - gart = kzalloc(sizeof(*gart), GFP_KERNEL); - if (!gart) - return ERR_PTR(-ENOMEM); - - gart_handle = gart; - - gart->dev = dev; - gart->regs = mc->regs + GART_REG_BASE; - gart->iovmm_base = res->start; - gart->iovmm_end = res->end + 1; - spin_lock_init(&gart->pte_lock); - spin_lock_init(&gart->dom_lock); - - do_gart_setup(gart, NULL); - - err = iommu_device_sysfs_add(&gart->iommu, dev, NULL, "gart"); - if (err) - goto free_gart; - - err = iommu_device_register(&gart->iommu, &gart_iommu_ops, dev); - if (err) - goto remove_sysfs; - - gart->savedata = vmalloc(resource_size(res) / GART_PAGE_SIZE * - sizeof(u32)); - if (!gart->savedata) { - err = -ENOMEM; - goto unregister_iommu; - } - - return gart; - -unregister_iommu: - iommu_device_unregister(&gart->iommu); -remove_sysfs: - iommu_device_sysfs_remove(&gart->iommu); -free_gart: - kfree(gart); - - return ERR_PTR(err); -} - -module_param(gart_debug, bool, 0644); -MODULE_PARM_DESC(gart_debug, "Enable GART debugging"); diff --git a/drivers/memory/tegra/mc.c b/drivers/memory/tegra/mc.c index 9082b6c3763dcc..e4d75c96bacec8 100644 --- a/drivers/memory/tegra/mc.c +++ b/drivers/memory/tegra/mc.c @@ -918,35 +918,6 @@ static int tegra_mc_probe(struct platform_device *pdev) } } - if (IS_ENABLED(CONFIG_TEGRA_IOMMU_GART) && !mc->soc->smmu) { - mc->gart = tegra_gart_probe(&pdev->dev, mc); - if (IS_ERR(mc->gart)) { - dev_err(&pdev->dev, "failed to probe GART: %ld\n", - PTR_ERR(mc->gart)); - mc->gart = NULL; - } - } - - return 0; -} - -static int __maybe_unused tegra_mc_suspend(struct device *dev) -{ - struct tegra_mc *mc = dev_get_drvdata(dev); - - if (mc->soc->ops && mc->soc->ops->suspend) - return mc->soc->ops->suspend(mc); - - return 0; -} - -static int __maybe_unused tegra_mc_resume(struct device *dev) -{ - struct tegra_mc *mc = dev_get_drvdata(dev); - - if (mc->soc->ops && mc->soc->ops->resume) - return mc->soc->ops->resume(mc); - return 0; } @@ -959,15 +930,10 @@ static void tegra_mc_sync_state(struct device *dev) icc_sync_state(dev); } -static const struct dev_pm_ops tegra_mc_pm_ops = { - SET_SYSTEM_SLEEP_PM_OPS(tegra_mc_suspend, tegra_mc_resume) -}; - static struct platform_driver tegra_mc_driver = { .driver = { .name = "tegra-mc", .of_match_table = tegra_mc_of_match, - .pm = &tegra_mc_pm_ops, .suppress_bind_attrs = true, .sync_state = tegra_mc_sync_state, }, diff --git a/drivers/memory/tegra/tegra20.c b/drivers/memory/tegra/tegra20.c index fcd7738fcb536c..6f367f743587db 100644 --- a/drivers/memory/tegra/tegra20.c +++ b/drivers/memory/tegra/tegra20.c @@ -687,32 +687,6 @@ static int tegra20_mc_probe(struct tegra_mc *mc) return 0; } -static int tegra20_mc_suspend(struct tegra_mc *mc) -{ - int err; - - if (IS_ENABLED(CONFIG_TEGRA_IOMMU_GART) && mc->gart) { - err = tegra_gart_suspend(mc->gart); - if (err < 0) - return err; - } - - return 0; -} - -static int tegra20_mc_resume(struct tegra_mc *mc) -{ - int err; - - if (IS_ENABLED(CONFIG_TEGRA_IOMMU_GART) && mc->gart) { - err = tegra_gart_resume(mc->gart); - if (err < 0) - return err; - } - - return 0; -} - static irqreturn_t tegra20_mc_handle_irq(int irq, void *data) { struct tegra_mc *mc = data; @@ -788,8 +762,6 @@ static irqreturn_t tegra20_mc_handle_irq(int irq, void *data) static const struct tegra_mc_ops tegra20_mc_ops = { .probe = tegra20_mc_probe, - .suspend = tegra20_mc_suspend, - .resume = tegra20_mc_resume, .handle_irq = tegra20_mc_handle_irq, }; diff --git a/include/soc/tegra/mc.h b/include/soc/tegra/mc.h index 51a2263e1bc59d..a46f9d290682f1 100644 --- a/include/soc/tegra/mc.h +++ b/include/soc/tegra/mc.h @@ -93,7 +93,6 @@ struct tegra_smmu_soc { struct tegra_mc; struct tegra_smmu; -struct gart_device; #ifdef CONFIG_TEGRA_IOMMU_SMMU struct tegra_smmu *tegra_smmu_probe(struct device *dev, @@ -113,28 +112,6 @@ static inline void tegra_smmu_remove(struct tegra_smmu *smmu) } #endif -#ifdef CONFIG_TEGRA_IOMMU_GART -struct gart_device *tegra_gart_probe(struct device *dev, struct tegra_mc *mc); -int tegra_gart_suspend(struct gart_device *gart); -int tegra_gart_resume(struct gart_device *gart); -#else -static inline struct gart_device * -tegra_gart_probe(struct device *dev, struct tegra_mc *mc) -{ - return ERR_PTR(-ENODEV); -} - -static inline int tegra_gart_suspend(struct gart_device *gart) -{ - return -ENODEV; -} - -static inline int tegra_gart_resume(struct gart_device *gart) -{ - return -ENODEV; -} -#endif - struct tegra_mc_reset { const char *name; unsigned long id; @@ -177,8 +154,6 @@ struct tegra_mc_ops { */ int (*probe)(struct tegra_mc *mc); void (*remove)(struct tegra_mc *mc); - int (*suspend)(struct tegra_mc *mc); - int (*resume)(struct tegra_mc *mc); irqreturn_t (*handle_irq)(int irq, void *data); int (*probe_device)(struct tegra_mc *mc, struct device *dev); }; @@ -216,7 +191,6 @@ struct tegra_mc_soc { struct tegra_mc { struct device *dev; struct tegra_smmu *smmu; - struct gart_device *gart; void __iomem *regs; void __iomem *bcast_ch_regs; void __iomem **ch_regs; From patchwork Fri Jun 16 19:02:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283114 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0DE78EB64DC for ; Fri, 16 Jun 2023 19:03:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gUdWtsGqaX2+h74zrMT+5m4X/yKsmUkYxIKlaZBGo4o=; b=icxSjKsD71Rp+3 uPfNu5a/ZnRuaWFvwNBkEdQUIeeWroPL1ImXQiTpY+NAkbax6+gEVEQYSR0Hba7Ec/Lf5VbP3hyol ux7ooA1rlkBBkMRWOeBFxK5amar81LzfaTCYEikPZaksChnx4hKsvWWfhrhmdEp1Sj0j6HrsJxVuG gxWLC5GwG3iOLLm1XI6LURultp8wgKV+XjTyapDjfXPif073czAwRI7BdrGt0xBvJNP4jdDB2Opjv RINLp81SO1aLtopSQfJkyDixboH1WnD+HD2YtljyUEruW5TZOpHI9vf3V2O5kPfv7Dhfypsk5e+Li o3y8w5TZGUgsmWlOVhYQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAEiv-001X4M-0v; Fri, 16 Jun 2023 19:03:05 +0000 Received: from mail-bn8nam12on20618.outbound.protection.outlook.com ([2a01:111:f400:fe5b::618] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEir-001X0n-0f; Fri, 16 Jun 2023 19:03:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JN/v3l4XbnD/HBcSlxckL3cYHxC4uVQKegCxjBiTQNrgSSdXQ2TMkPiMfm5MRi5PQa6k7VAwE2GLsoqvD3ZXnY4OpBsVtFDgAW4WwUuo7mQMrqp5Cl3sVgobGnEBvCVkfbIkm8UZdRe96ujqDdRMBBe5Wsa6ejP5kIay6sZkMYRvOCfrxzvLzVeF91hnDwVpueAMlZEAl5DSMab8byyXWbmbzrMxawsi7oxcubwi3Pe8xXMvmDg1ixFVLZ5lgLx1G2565Ls2aXW3wdr8ilv04WOKKi+S/fI9BAhlGm54rpNw+TPCg21QCqCukztlSeTcf9LqHkeFbLW/Jw95jLWEAQ== 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=oc9+cmsyQ7ClyqBWCUJKmesYXwKbwskFnJn3iebEKMo=; b=ckU45o6hE555WtzAMiaUZgbl9SKagy4MjW6GYJaUCcrC4tPPW88NIOrn4g5ujuSebkQ+nTdnF1MDcKvbmnHcK8okE7cgo55xGxhGit1I/VhYRIDK8I+n34DXdXQEuSglwWumH0YojslByADiJ8/xIXKeLoMoQ9K/syJTuzc5Sn2HEEfcV1gZt/ZKlFsCNHQVhg1WBxq3HeUnZs42+Zfu69B2ne7JSahvQDcs1AOaNR/GJy0SpfjcunZYoDw8dB1dYGVxROsGEZDTcaoH2lEOUimpLl/T20u8Sk94uLn3h3P0Mb6QwGiXCmtQyGbL1JnjD3PlXthQ+L/VGSvd0n6orQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=oc9+cmsyQ7ClyqBWCUJKmesYXwKbwskFnJn3iebEKMo=; b=FaffOsvV8xbHPY5E+gB/87OzK6CWY5NyETL1eT8n/+3R/yt8IRv1bnhESjAAV6fc6/YzHK5TuZDULkAcE3oSbdSXjfbonuxcfH962DyVB30nT80z/RIJBaJyCteqPwL1nnHNhBjDnT/KjN+eWBxkxOAoi/Ljgv+iRV3sKY29lvknaFKLa1C0Z0qc7CbW4XV6GfnoD+2zPkCB6W32AU+tOPA2cKTx/sEIWBTB/nJhWlXyAP82xHgi7/ewkqaybg9XuKEvDTGsaQcZkZiNT064qQuyPyfue8E/RLVz3MdR77svSFLkjMLLqKVHm/8k5vciF8OXsL9/bxuxSxnihIpveQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by DS7PR12MB5912.namprd12.prod.outlook.com (2603:10b6:8:7d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.29; Fri, 16 Jun 2023 19:02:55 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:02:55 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 07/25] iommu/mtk_iommu_v1: Implement an IDENTITY domain Date: Fri, 16 Jun 2023 16:02:36 -0300 Message-Id: <7-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: BL1P221CA0028.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::18) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DS7PR12MB5912:EE_ X-MS-Office365-Filtering-Correlation-Id: ba5fb741-ff9b-4aca-6bdf-08db6e9c4ab8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nDZX7Z0IMW7AIx81V45HVuwU/qcLbPpP6tYFrasRli8wZD8rSu39siksaXbtKytY4UZTlgcfGTJNoPWdLLKMaZRcvJzg1yH5M182hfvQ2mrgXn0eUWgqrqJ5jUXALS+Cs5fpEXFrjgScfYErNxJKp0/v4VciLZoTEVKME+7hmIzfDuedbs2Kth4WvkvQRtjZjaEJJ2QtK9VBJfZtzRkX4bPEukDiYBhsXuLBTdDUtESliiBZCEtlTfPXZ5ZihFGJVnP5+7KfHJzIC5+jQdbIXT42Bwr4thz9sml3fqg5NfKaOMQBThZ5q/E7d1+PuJtGmZT/UYsSFf3Siy12NKjFXAkxV7V9fcCCILOLLjmlKOlMeUT95FLrmfzEXZqJ/nYubOnKCFqKv1ydr6z7lUdDhTjNxAhMF3c5nmDBoyvOiCSCYEjzmC5cjQ1Jli99lzigk/MNBpyEEI0JTynWzxs3kDPKQSY/5iFZIMNZdVOkk/sj/o++Mxy2Vs7Q54Fs+X1Zn/nDczbir/veAu0NdoKRG28X93bof0st7WenQ+7xh8EyCI0jgNJzN7XNE0rQ/XZHziz1A8Ed2pfWsKfdg8fpMrK/ZE6RO8oPdxtt9MtLcgzeKs7Z+weiQbclqOk1TFcW X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(376002)(366004)(136003)(396003)(346002)(451199021)(36756003)(86362001)(110136005)(66556008)(66476007)(54906003)(4326008)(316002)(66946007)(107886003)(478600001)(6666004)(6486002)(7416002)(41300700001)(5660300002)(8936002)(8676002)(7406005)(2906002)(38100700002)(921005)(2616005)(83380400001)(6512007)(6506007)(186003)(26005)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AS4myCmkuekrawsO3bY9j1M1g53dgMnIP0UQvpuXizhCMlEpp6lk1UF6OfKM9zrVrnT9WNISSqsISEjJIujeMmNCi+9ptbkZC1J994axUQ66koVkt9rXZiP06EUVMK3ppZ/P74xuChGgkHk9+WDAH03kSd5C6YfJVecyMJFU4wO0DbNzCgzFP1NPUjg9fZe0gYcogFfrrFCtZr7Hp0b/4Yl2tASTByB6Z/il5aTLRzh73IT7AY+iT2NVfVBbzpoWMCl7phohE/jr7DXYvhjGoDsDM+1BCaBv6Yj5Mdxqrp0QGfk8Snoxi3jPAWpHzRO6zz+OHfS9jQMZo+hbe4Tm7JVmoKF420D3lNUswv5vPBHTkLjun4DgY5Cv8nfnTD8ccuZ7kh3V7yoUfKSFdPpOrElxl2QgqxAlZ/0W3adrQB1656CAiM5xoJzAsXQYTpAbgkwN24uUPlfmFca3LZEFv9sk/hCNS5M8n/VAfh1hBXfvdYPDAj1IazqUTvP7f7Wj/01mpRIfUfZJnw8rwwLb4OHOivMgXC4ZNFZt6HTynkIEbPekExQKAAUp+pA5jFD/7EE++lsmSOcaj99ouKQY00vGjEk9xjTBEpytDjzvqF/7t1P+2v9ZDN7x/yLjgBZJ8eQb6YqI6vMGOnPziYCpAOyfEGx4mRX6gJjlb+ukSu4hNuRarHf2cVJpc8TbE/QWgw025CIOPL2HHLUik/Yt1IAdNP733f7wN1UYzVwlENjc1Wkfgh6qzpROHcJ02lBbDEA9sYtZSClt6678rpjTCfI4R6jAAUOnUOmBvq3JJ9eJdNgqYkIRu2Rxi+tagZYPT5EJu/KeZJ8qPh2+kGObI1TgjzZqHybccUsxHdeGqeFHbQP8nO3rO59p0NBGQOZVAx31cUZS3ars2597cRBaVvulHjdAk4i6y09vSLwosSpD2CazLP88WmHj3DUEQxlN7MTL26fKU/2jnSl29b/fhb9vnc7Jz2ZaC7ZXGFrhyutUMIO6H/wRn2XtcrvGpl09uG2kQbIigmvMAb4R5gtAt1avSEpU+kg5AyHWW0ZYlAuBZJ7y8OWMzoLPxa+C4x724FWljg7fva1yo6NAnGPREQcoI0AjeB06ymnVfM9+Prs9NRd+x5N8dN3dgyTZ8MZaBt0gsC6vt/lFm9ckmJHTPmSEHp31O0aT2xQD77SGYOnWyELZaW5+15gSoHwizq2glnkpwvDf1R89xltrgJ1xjxyHq1loyKwF1PFrY8PHeUvo7FU14D7erLMuvnxJzrVEm1TYJbS1tV+yA3kI5C09U8mJP0R2wEELXIrB/w0MLJI/u3d+uZLcs+QHF0T6hGIEygwR3FI7tVwdVdjKpyZCur00cww/napcY3ewInIweydrkXiMJeoqdLaQ9Csx+cb7kIjaqdvlnFcp8aBdIRnH5mrfKRYjHoutxSlTtNkTaAO/gtgBeLCccvtO9V8KOlnC05TAmLAw6cHZ17+CN00dAFcezzCZDtEK+4I+LC1OjBAFGwvlqOVkoqs9C8799POjlTAc7IwqE4cq+OE5X9JlOZZjdhcDdAhPB5ayiBeWSe95PWZkgBDaM16A/tdUvvh6 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ba5fb741-ff9b-4aca-6bdf-08db6e9c4ab8 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:55.2072 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UwZo/lNoIHKTt80v3ZaHUrj1Py/BIiENoJXEqIjPRtgbjThprjcO/YGyaa6WOCDo X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5912 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120301_249342_EB1FC4CB X-CRM114-Status: GOOD ( 13.56 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org What mtk does during mtk_iommu_v1_set_platform_dma() is actually putting the iommu into identity mode. Make this available as a proper IDENTITY domain. The mtk_iommu_v1_def_domain_type() from commit 8bbe13f52cb7 ("iommu/mediatek-v1: Add def_domain_type") explains this was needed to allow probe_finalize() to be called, but now the IDENTITY domain will do the same job so change the returned def_domain_type. mkt_v1 is the only driver that returns IOMMU_DOMAIN_UNMANAGED from def_domain_type(). This allows the next patch to enforce an IDENTITY domain policy for this driver. Signed-off-by: Jason Gunthorpe --- drivers/iommu/mtk_iommu_v1.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c index 8a0a5e5d049f4a..cc3e7d53d33ad9 100644 --- a/drivers/iommu/mtk_iommu_v1.c +++ b/drivers/iommu/mtk_iommu_v1.c @@ -319,11 +319,27 @@ static int mtk_iommu_v1_attach_device(struct iommu_domain *domain, struct device return 0; } -static void mtk_iommu_v1_set_platform_dma(struct device *dev) +static int mtk_iommu_v1_identity_attach(struct iommu_domain *identity_domain, + struct device *dev) { struct mtk_iommu_v1_data *data = dev_iommu_priv_get(dev); mtk_iommu_v1_config(data, dev, false); + return 0; +} + +static struct iommu_domain_ops mtk_iommu_v1_identity_ops = { + .attach_dev = mtk_iommu_v1_identity_attach, +}; + +static struct iommu_domain mtk_iommu_v1_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &mtk_iommu_v1_identity_ops, +}; + +static void mtk_iommu_v1_set_platform_dma(struct device *dev) +{ + mtk_iommu_v1_identity_attach(&mtk_iommu_v1_identity_domain, dev); } static int mtk_iommu_v1_map(struct iommu_domain *domain, unsigned long iova, @@ -443,7 +459,7 @@ static int mtk_iommu_v1_create_mapping(struct device *dev, struct of_phandle_arg static int mtk_iommu_v1_def_domain_type(struct device *dev) { - return IOMMU_DOMAIN_UNMANAGED; + return IOMMU_DOMAIN_IDENTITY; } static struct iommu_device *mtk_iommu_v1_probe_device(struct device *dev) @@ -578,6 +594,7 @@ static int mtk_iommu_v1_hw_init(const struct mtk_iommu_v1_data *data) } static const struct iommu_ops mtk_iommu_v1_ops = { + .identity_domain = &mtk_iommu_v1_identity_domain, .domain_alloc = mtk_iommu_v1_domain_alloc, .probe_device = mtk_iommu_v1_probe_device, .probe_finalize = mtk_iommu_v1_probe_finalize, From patchwork Fri Jun 16 19:02:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283127 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 11520EB64DA for ; Fri, 16 Jun 2023 19:05:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=PGOUGt38qqS+YD9cgXhG1CSW73euLmea4mAgvqIJpCc=; b=Ao0PyPXxLbgRVW FsNB2mFs+1D+X1NQLtzxFtI4rYLakZyxoU6jv5nTl40D39YJYpuyWMoR11IbE6sIeYD/roMGk7jOI EA/mleoRNYz24SB4kVXm+HmkkyMDSOvtIaWL9fbo6npbGojEMwSbCMyMETmv39sNwo9rjwUZWYhZr 6Md7YdrxHYREJtOjtAlw2Z3O86NEdSwNTyjnc0viu3Zoc6ivHXkgXCl0SGYiEz8+2sR3kiitKKPJt V/8+pka+Kmqtheo7LWjfSS9YHVfxeDh38Rvmrw7GtWAUHoDQjEP4foQpubo/XCa9MYFouTeBh8sD1 5wNy0r/XlJ2wJENZSUZg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAEko-001Yok-1T; Fri, 16 Jun 2023 19:05:02 +0000 Received: from mail-bn7nam10on20620.outbound.protection.outlook.com ([2a01:111:f400:7e8a::620] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEj2-001X3y-26; Fri, 16 Jun 2023 19:03:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X/U7zB8Lkz9Ze+QkQENbB7wSoK9bJV8PF2i+ONjqq2yrWjpWEsNqAjkYSGCv4HmpFounCHQr0bAWSakCYqUzG/lUNnG4iJUu7ZLF8CbpqU0HaTdQ6c+uUQGX5FZzTR8nRpptzRklcmSjSYverOnUAkUyCHjXIb4dAav7FshonHPRHfMhEQANZ/SeiZAqu69vJUnWgQNkbHqZBsZM230A95NVJNXVniY8iEvDeby03yzXxGPxvnfOam5lkcoNBA4MQ+JnYZG1rq5d4RA1TU02bVyVil35NgY1Bb60My+7qZjWo+se9WT+k5hmOI8XxEVMELi0hPrVFnh2qWIaLsJ0xA== 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=cE3gP3IT7L/AsvWvDwFn9+Dm0y7PEvGc1+Rm0rxcwBk=; b=MWjsF2qWwI1bozBsJB/syuSkxeikSiNal16HhAiATdtWGeRzmv4rhGU7cR8dF/Woaa5FhXnf5inMSQzMZ5WN7NiipUGzMvhgy+Rr7QBONVLe5zWJo5M77XrTRy/0uEvMImJrfCcNvDdGGHhiHESYJxbYCQZ1y8albDUrr1ClM904ky/k6gxIJzcUoZaiM9UsW0Az+cVpBGm/NMF7INVnfh+6hSUITk0qdKhLi9N1D4LETCEPRiWAxfq+8q2YD9T40umB7nh1ZS3g7LjGB2rkrdDarmKnLXmL6pqzhjQybnMg7btbiJhWaW7tckXdIBlucA6qjjcD7WR1xlATrFVoEQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=cE3gP3IT7L/AsvWvDwFn9+Dm0y7PEvGc1+Rm0rxcwBk=; b=KpNYjQTyzaLJdgiC2LTxLZwWb6CmlePMaTvxMslvEH8THLBLvPdUsGodIjdBRLUPrDqTa/6mr9qER2N2CfvrSutwoAOUIu1nbLYn9gRpNQNlNO+JommC8tUY5+gNv4r3qQM9KoGJMDvaLrqrkY3aumNUmy5fnmEMFK6cNsFln9VyPST3/LvFH5YPY+c1taIHg91DZZuexlFQXo1UWUaPWSKRgfwK7Im/vHL0zgIAMzeusgCMfjqLflb+tr+8ErI0ObxjCbassvQprinD4lrHBiazY13UDSbzvua4TcSY/tDOdYjHUipKNSvVhwQ2J3EyOStWfB1+uljvhYTm/vjADg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:03:03 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:03:03 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 08/25] iommu: Reorganize iommu_get_default_domain_type() to respect def_domain_type() Date: Fri, 16 Jun 2023 16:02:37 -0300 Message-Id: <8-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR20CA0041.namprd20.prod.outlook.com (2603:10b6:208:235::10) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: 3375e37d-f41d-45c9-d189-08db6e9c4b68 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ctwbR8Z+SjBCAK1QHZXGia1glNscT+9fLfcT7BQNWKooOYiWu0zyJQFmKSOuzxA8RczT7B92bIskbyhINPfIN5QKI7U+Pt33tfgzAP4QB2JO93bXRlwIeGTX3Xbm1tGOOubsXMAI6ikNkv388WdF1tx7TBFcZcuHkZfl6rnqdKchZxvthWrSpkAC4Ob5TCxg0UKOayTee8LEhKH3pqTifMbcvl3WJ+EMXYPxoNsbv0iuSSrD1bVL+oBTDiO4OYU1pIRhsTq8w4C1VhL6YWI/+JY1PN6UyisWSfbzPdKU3HYpB7Z4WwOF5BK1qy7HJn/o5zD9SI0+tFtPurl5D9wuZkStvURKFMZHVqrjTCo5dQgHdrFxYxkkYurJLBVY2Ym7LyCNTTLni8/st318zc3ErPIydb86FNsiau/PMjoMWBvcboGav9cxp7BGRLoN5JE7a9xeAsnJADVOXAnJSeC9YnwbKzoIbfWhfj+JYgqCZC9DXiyAwQ46Kh6ETUIFBMzHFSVrGyl0BA2CND7P1I3N3erCi+37rJD8hHbiE+MJIwUjf4qfCz6GFqemBQMNtuGKdNwaoFx+eRbq6Ss6dkBloz31ibRAwomyYum79KsDIdXopJxqu9RCsLBge8vm1i+I X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MSOfTVl5XbX1DiejjeY39xPb15HrhqE9webgHXmWrGyRO1VjS+KTv3GmV8y79vZxbV40aAsKdChEivAYWljtbXMF6tAtw3wCkTFOXud4GRAZPUTvFpYG5bXysoNqHyj2XDtcRJ7m3aCFYGCV80lylwFp3yH8tgwOZTGBELjS0LCQpNFJJeBZefiUYsgKvlnuMn3FN/xMEikBTjWzPbRrpB7ksfwzueoVZ8P3XTYWNjveNKi9cQeoeiaO2PXZHZv5nMyTI9IfJGQSOeGvHxHEA43SdtaByIHPakK1UtY3xOXxs+3DwivKoEKEno5/ylAFnmyYsE4GU/z/uUPhzTkK9uEc7tobnSknj8Sym3yGq5mr6jUDqVjkVsHhMwAdG1GVOQFe99EH0po2H8suRKoR8gQ5w5lg4MDv22CgSbK26Pel9IsmQv/kcgsOW/IowHCrAKHJBBlC7cfC+tKE60E5ENVYTooixkyKpD4x8ZaR+GuPEHdW0mFZ5uhtiIdCsC/RT8MieEUvFvmwXGVwKNSKFIcGeyP/By7Iid3nAZUal7Y8/sVJMjH6sk4MtmRu2PEn+Z35jtL0uHzMtA+iaFo8dWbmQdLvkOgfIatj7I0oR6RBlr0t3z4MrBj3LkkGmeHcgQzaVDl81LuOcE/ivr1JQFrxuZt7dkwLQBRk3K7XMh6aF+NTJW5L7aGEDA+0RyfmhBRcejStXx2lAYiaplaVxG1yITMpm/gwHC6OIgdhDY1253d0+QWpMGWa32RBGL5B6URHsWhYgqrwHiLRp0ItaO7ZXEhnYi9pD05XOT1mEhZAo0OHcjuVnF7rTGzoDnNkT0LK2Cjq00rNM4dt6L6V0hl8nlTEqNB2gDSV51eKMe1CrASLbkhBNFhL471smnEIt1sSFu7rUzigPXtM6WsewLOu/t/awp43NmG6ujj4hazJUObr5yWianzASosgBFYbqpnOmcCwm/QUH9YGTUiDmgBAZXP0gcaD1SohTlqIFRJx5W7nTgDTbWlqZBaFad1Mx99MNFNNy6AYY5w/HaJhAup322QjgoyfsYC5yaNOfr6FJespdN/KHlLP9DUsIvYJ6eHK4Cqi2aSBVaknpB2P1OzQ0N1YPKVBZehZWM17pppAP14ALodzq3QyP37la+PA7G25duC69PAzs/rRS+4sihc9LPzr4LWSyiVZC03Qqm1bzqcTk2mJ6nL9yNb4iDGmAXhw4cNGkDlr6OJpIebQnxq12iCDsr6yzTw24Ob/JSwJE5xF1LV5lMKT/VZmjiJdAEinqc1iTWVI2BylPqvlxgP13nh+F0nO80TFxTym1iztzSGmHM3aQevC3YZ2nkmXm1tcp4oFPKdyQIDCEb1IYdbAQnZTW0ry0rwis/mXwYr+QThIHBaXF1C5UqXllJsFrX4q7eBgBVATrL3bJXDob38/vROc4GnefLn3dP6Nt2rxfoUSDrIO+zPqhivQFbqHhW0jx7k+DJybxoCW9xsqfXxjUDhxaMJBZ0SoLWk0x1d6SCTWrj+Rsr4Exo0cQMOrr+6w/ImSmwQWMHU+SFMV7PohVOSVCopU0Op5lEhxX3CbkJWUN8ZJ5FEdeI28qRf1 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3375e37d-f41d-45c9-d189-08db6e9c4b68 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:56.4299 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1+h/Y+b2tZSZ73W6kQV/hIBurxQgBKcz8cy0L8AG3BWWK9N5S5KbM5Lsr0Ah3QnF X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120312_725417_A81A748B X-CRM114-Status: GOOD ( 16.23 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org Except for dart every driver returns 0 or IDENTITY from def_domain_type(). The drivers that return IDENTITY have some kind of good reason, typically that quirky hardware really can't support anything other than IDENTITY. Arrange things so that if the driver says it needs IDENTITY then iommu_get_default_domain_type() either fails or returns IDENTITY. It will never reject the driver's override to IDENTITY. The only real functional difference is that the PCI untrusted flag is now ignored for quirky HW instead of overriding the IOMMU driver. This makes the next patch cleaner that wants to force IDENTITY always for ARM_IOMMU because there is no support for DMA. Tested-by: Steven Price Tested-by: Marek Szyprowski Tested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 66 +++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index c8f6664767152d..0c4fc46c210366 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1608,19 +1608,6 @@ struct iommu_group *fsl_mc_device_group(struct device *dev) } EXPORT_SYMBOL_GPL(fsl_mc_device_group); -static int iommu_get_def_domain_type(struct device *dev) -{ - const struct iommu_ops *ops = dev_iommu_ops(dev); - - if (dev_is_pci(dev) && to_pci_dev(dev)->untrusted) - return IOMMU_DOMAIN_DMA; - - if (ops->def_domain_type) - return ops->def_domain_type(dev); - - return 0; -} - static struct iommu_domain * __iommu_group_alloc_default_domain(const struct bus_type *bus, struct iommu_group *group, int req_type) @@ -1761,36 +1748,49 @@ static int iommu_bus_notifier(struct notifier_block *nb, static int iommu_get_default_domain_type(struct iommu_group *group, int target_type) { + const struct iommu_ops *ops = dev_iommu_ops( + list_first_entry(&group->devices, struct group_device, list) + ->dev); int best_type = target_type; struct group_device *gdev; struct device *last_dev; + int type; lockdep_assert_held(&group->mutex); - for_each_group_device(group, gdev) { - unsigned int type = iommu_get_def_domain_type(gdev->dev); - - if (best_type && type && best_type != type) { - if (target_type) { - dev_err_ratelimited( - gdev->dev, - "Device cannot be in %s domain\n", - iommu_domain_type_str(target_type)); - return -1; - } - - dev_warn( - gdev->dev, - "Device needs domain type %s, but device %s in the same iommu group requires type %s - using default\n", - iommu_domain_type_str(type), dev_name(last_dev), - iommu_domain_type_str(best_type)); - return 0; + type = best_type; + if (ops->def_domain_type) { + type = ops->def_domain_type(gdev->dev); + if (best_type && type && best_type != type) + goto err; } - if (!best_type) - best_type = type; + + if (dev_is_pci(gdev->dev) && to_pci_dev(gdev->dev)->untrusted) { + type = IOMMU_DOMAIN_DMA; + if (best_type && type && best_type != type) + goto err; + } + best_type = type; last_dev = gdev->dev; } return best_type; + +err: + if (target_type) { + dev_err_ratelimited( + gdev->dev, + "Device cannot be in %s domain - it is forcing %s\n", + iommu_domain_type_str(target_type), + iommu_domain_type_str(type)); + return -1; + } + + dev_warn( + gdev->dev, + "Device needs domain type %s, but device %s in the same iommu group requires type %s - using default\n", + iommu_domain_type_str(type), dev_name(last_dev), + iommu_domain_type_str(best_type)); + return 0; } static void iommu_group_do_probe_finalize(struct device *dev) From patchwork Fri Jun 16 19:02:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4B4AEEB64D7 for ; Fri, 16 Jun 2023 19:06:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1Xdb4GAuE1pTxMyXV13awRzt/6s6nn0gjvZMplmxWMM=; b=zM+v2+6plpXp/o yM7kZCWvzxm4H42tu5X6XM9MTf+cfJx+vHDPn7uWN9VEHDnhWe53zxaWQ93Gj97/lPovHpGFYNpJ4 n0cOsi3XypXyfsD2PHz+ja04tJFT75OUpMCNmyEXjwWw0pZ8zIVQAevlUKvpE9SfuX8RvWGhOHEGA 4bZNAUsEb2qDDAXD4E+scS2nBVtoSqEr1dT+8Hsi1Bt9tFKTNHQvHnEQ7ogSuoLuoFzUiRMqzW3ae +zfoWN3MpY0I1/zQSZg548EYlLNagzw3g2eBcTVVkqZuFHz/Pzy5f4gWuQ4aRi46134JcKi2yyNKU O2/jcxESKUVxdcgFRiyQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAEly-001ZvH-2n; Fri, 16 Jun 2023 19:06:14 +0000 Received: from mail-bn7nam10on20620.outbound.protection.outlook.com ([2a01:111:f400:7e8a::620] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEj7-001X3y-2r; Fri, 16 Jun 2023 19:03:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PvPBg0okGv7e88S0wagiuQLMXfoOfRiwhMh4B8U6I/NkrqPOtY/6ievuRB4ZKAEgGzYc66zGLUBROjuVaSQDb+Np9rRkpskyaGBIaWQvoUZn4s60El2Z3s3jRqDG6sCz3a6nESvgXY+IXdlWYCjnM/9yW6UYqYq0J6tAmanC17Z5ZmUvLNBNrOwamkIHS3xfF3h7yzF+0vgpa3uB/R5d3vKGEIX+7oyPefS1cdIyoU1NoyZFfogyqUQvwC/twlAWTCOHLHhwTeUZPyHZZeU0hUrnbXLxaR7aYbLqPpFdiSrIQokWlihwQ2a8qXpiYJVwsXbLLHYRbujcMWl5sWfO+A== 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=KcLi5FVNpllgaVjruqTdAdysLAYv9WirjaaTtSVFkqs=; b=NfUmRSQofGgnU8oDP0Rc82wNjpRE0WNVU1gu3ANJz+mB8qroxmHByp/845yFVhy4kPl28wuoJFKdJUsgS0yjISJvM9dBV6E4Ml1HXTgEpwXwFSZ57pNiwn7EfLXCA/dEPu1rwZN43kkTNmQcSUcJzm42Ye9nF3bni918AR25TE6zandDtmh5Bct8gE5P4Cb6+eVCECiy7dr/WX5WZ+LszB10oVyX/EPh7hQ84zjIxLwILGKerVpmTX6/WtqXayJXShehWIKR5TI1HDowrGf+T40td1RlQGS/1TJ2ZHmtlxV5lEzKCgU4H4/y4ytV/0fSJ81IKDc/FFxvrjZMNfUMHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=KcLi5FVNpllgaVjruqTdAdysLAYv9WirjaaTtSVFkqs=; b=tK9+26A6Fo524RSgnXRy2wc1HP34lX3UiG6m6Thpc8wx/5xPuUJ49D4qE71XtPr/F2mxS8PO/9mB5WfX38apK2VXVIBHtE9E3PqEcyN9bjD24S4KQ7R/8zMrVrakUNt+Ns/bDZUCFOlwa3l/uXNGKiX5VM19waut4fXalAq0s3u5kfRSxiXdrSfmDd/DPQ5masHEek8Ny9tT1z+By4pRYV8n08eDO0U3r0C9Q3s4AieuijbhQjwOMsUZNwwsC2N5GF6cszI0Zp17Om4EFPHO2abi6aRhKi3aORir9LGRTdkekW8HqWmUx883INtn4yyfMaLf4uayL3X9JXbJxUNqig== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:03:06 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:03:06 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 09/25] iommu: Allow an IDENTITY domain as the default_domain in ARM32 Date: Fri, 16 Jun 2023 16:02:38 -0300 Message-Id: <9-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR20CA0048.namprd20.prod.outlook.com (2603:10b6:208:235::17) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: 8432ac28-e91a-48f8-c5da-08db6e9c4be4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ml3wuo8Gi/eMZ4klvg3qxkQIC8YPxCGDIpCThH9GhRQgnujhBg8rHHl4XbybZDIJeF5p0Lzkm7ctlvvnekwyDVRON/lwIGAEeCN7vF5z5fPeBHRZjm9G2vtZtGeBWflTIaHj9/cJM0u0eYXT/jwhFwovO+cgoKDnJHk/E3DKixfI1Lc3BOzu/7Y+LbtKgWrtdDXqiLr96sLKRT93r9FTCJPq5SafTscbGRs18GuIhn/bHHIdBLAgEigk4vhwp1VyJJ847cP73hkzlejAIHtCk9Y9anXoqR2lZVrrJMB6nwXjtTSlch8ObKczbwyfvaYdvo5ChAuPQiHAuknTbY15YoV30K9ZC2rN+zWMY4wMgez8rWFkeSMoH+NAl8am0X8RptoGXH5BKmv5JMATPzytAWsY+r7k+bqPQZo/FFVeNAN63xNA8xqs6VNWf+6CaSl9UdkPhdYdEEyCGxyjoFvmOqua0OTqbXJKbyVWuux4zLbqJPctiV4oCf+EnycdZUnUYzWEDaiSSmW2T3wQ6Dm7sbVzcKi+052QqR5R7g4qOszomRMcZKa4WWqS38C2DtJKF4/lonI2jEZ0+8077nO4hEgUECyftF9P3NYsFZx4ZXh5lVRBLKneoBmXpyNJlb0g X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7ULIWZ+t2azjASU61aUexNH4NKJ00MAJlSXnXC3GIsKkoXBnkcXUZwY55Fdfc65Rcnb3saK9nehNTyH0+rOdWkUaF8VFwlvXsQYK6l8kL52DGgOmD2dtMZ3Iit6zS89AhG9pKcfD3R+hVvXrCQPxpEDdGBQ4ip5wvU2Xe/qdeUgyOJvM0WofPQmgU2/HLM3UBkv+mC78n28Ad2sHfhUZwVyDC/f6wID9v4y+3aYOJv3pAeoz01TRrJwo5eCcu0L4vpnSIo8QmqtEWTqQU6m4fZVR4zFBgEt0MBFxTyyJMdPsWJujZPu1AZ+eggzugrAGOcuobR95GIwF5KZCOQk9kRZ/KwJYgNON9G+63PBP4uGU1Q5Vgl7JFeDflUlMWhxk/59WiUqS+0CgNZFZm7iPO4mTL/HaarKxS60vR1/REvWnaUyvbnK19RivJ+I2jfFT/UDKFsK/C8H7oD1KFiZvWyIUQW7NhtuXOK/j9B2pqoaRBQ41mLCKsalBmuJyAMa6WOvSJeoU74dBse5t/MuYbmrz31sWwa/c3W+wgSi1lP3PeKh2BRWLwKl3idOSh1Z7HrhoTEwS7Rc0mcUw742KEl+Vfu1pSilJa4Q4ME4kNX57W0SZjq5x+LOADsWOYQwCIfaf9ojDULn0ti/uWP6eKn6jwhZgIykstkwlVgKJ5DqmYrRp6wDsje6id5hlk5CcWLr9LUsT9ApLly2vVxH38HeuvmQZZJLvELLq3Gv44QLxRhVGgKJ6oW0IqfT1QNquz5kOpC9SsHz6hPXDmZfowh2rx8p74SrzSEiv/HTvq+dHTndJTZb4RtxSoIaDZB1SCll1N8DDWLjVtLXtqyz+KouAogz1gYGCLboTJixyKDXQR2n88+X84uNYMlYj36K1UKKYRrN0i3supGsqN7F9XylSptK+3xqTtgVNza0CWsuNn9UfLvrLccfjFEifK7k2FbNrm190p5ePx0/7njLZBuYomxFmElwKw6BRXoXUGdXcE3c5cIpMd4hFKBdCmcSO1AhUE1CsNyiVPjRr/zkZA2yuzAf6V+yH+inofVUXFUKJLn5Y4pW8gFgRydN3+zskXpa8m3JkCsQo2XJnR8X/sOjJmX2irzoCrr9Ff5IyMfs2xHNVuTK3eIYgtpZSFN5KocMhNGpR5ojdp62w3gccLBbsbEr1aKi/WwHSGujomkI+hKmV+q0dI52FKSHPi8hjbL6z1KRsVQHbjcnw7dUCREXM294IonMCzGBK5+yQ1mUJCgCQTYFdoreGtDyrjfema0z1ex5/BddO5dUeIQ/tqVxEdePhVqmcGcTXQMJV4LG/ukVqe9fAuq26y+IrXOKG/M3qvQZqs3HBoUIGlDVRHP8lMlSal/qAdohGANuoEnHg5GUuzrYa/1exetRwZXlEVI5R+Nrq+L7tLh9Kic1hJLKcygyD77cIw8GmmV68Fg1Ysj1dA3OlM3ZWNO1SgKHbukIne6jyYKL9YZeZ7bYlTbXnOlFo7DXydDpxh79hep/VSDA5qkHysQkqurkeiXyvpGLFPsWOSpPLfOS+JYW9E1bFGaaAphx7so0U7KCp14NYgLIb4ryTqLalHL5BiQb+ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8432ac28-e91a-48f8-c5da-08db6e9c4be4 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:57.2096 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xo3hQky/RWgqvR/tBzImuNwyuKAg9b3MbkHx4ofQ0363QPc6bJLEHCTyog6D1xXh X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120317_961470_68EE4A67 X-CRM114-Status: GOOD ( 23.07 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org Even though dma-iommu.c and CONFIG_ARM_DMA_USE_IOMMU do approximately the same stuff, the way they relate to the IOMMU core is quiet different. dma-iommu.c expects the core code to setup an UNMANAGED domain (of type IOMMU_DOMAIN_DMA) and then configures itself to use that domain. This becomes the default_domain for the group. ARM_DMA_USE_IOMMU does not use the default_domain, instead it directly allocates an UNMANAGED domain and operates it just like an external driver. In this case group->default_domain is NULL. If the driver provides a global static identity_domain then automatically use it as the default_domain when in ARM_DMA_USE_IOMMU mode. This allows drivers that implemented default_domain == NULL as an IDENTITY translation to trivially get a properly labeled non-NULL default_domain on ARM32 configs. With this arrangment when ARM_DMA_USE_IOMMU wants to disconnect from the device the normal detach_domain flow will restore the IDENTITY domain as the default domain. Overall this makes attach_dev() of the IDENTITY domain called in the same places as detach_dev(). This effectively migrates these drivers to default_domain mode. For drivers that support ARM64 they will gain support for the IDENTITY translation mode for the dma_api and behave in a uniform way. Drivers use this by setting ops->identity_domain to a static singleton iommu_domain that implements the identity attach. If the core detects ARM_DMA_USE_IOMMU mode then it automatically attaches the IDENTITY domain during probe. Drivers can continue to prevent the use of DMA translation by returning IOMMU_DOMAIN_IDENTITY from def_domain_type, this will completely prevent IOMMU_DMA from running but will not impact ARM_DMA_USE_IOMMU. This allows removing the set_platform_dma_ops() from every remaining driver. Remove the set_platform_dma_ops from rockchip and mkt_v1 as all it does is set an existing global static identity domain. mkt_v1 does not support IOMMU_DOMAIN_DMA and it does not compile on ARM64 so this transformation is safe. Tested-by: Steven Price Tested-by: Marek Szyprowski Tested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 26 +++++++++++++++++++++++--- drivers/iommu/mtk_iommu_v1.c | 12 ------------ drivers/iommu/rockchip-iommu.c | 10 ---------- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 0c4fc46c210366..7ca70e2a3f51e9 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1757,15 +1757,35 @@ static int iommu_get_default_domain_type(struct iommu_group *group, int type; lockdep_assert_held(&group->mutex); + + /* + * ARM32 drivers supporting CONFIG_ARM_DMA_USE_IOMMU can declare an + * identity_domain and it will automatically become their default + * domain. Later on ARM_DMA_USE_IOMMU will install its UNMANAGED domain. + * Override the selection to IDENTITY if we are sure the driver supports + * it. + */ + if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) && ops->identity_domain) { + type = IOMMU_DOMAIN_IDENTITY; + if (best_type && type && best_type != type) + goto err; + best_type = target_type = IOMMU_DOMAIN_IDENTITY; + } + for_each_group_device(group, gdev) { type = best_type; if (ops->def_domain_type) { type = ops->def_domain_type(gdev->dev); - if (best_type && type && best_type != type) + if (best_type && type && best_type != type) { + /* Stick with the last driver override we saw */ + best_type = type; goto err; + } } - if (dev_is_pci(gdev->dev) && to_pci_dev(gdev->dev)->untrusted) { + /* No ARM32 using systems will set untrusted, it cannot work. */ + if (dev_is_pci(gdev->dev) && to_pci_dev(gdev->dev)->untrusted && + !WARN_ON(IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU))) { type = IOMMU_DOMAIN_DMA; if (best_type && type && best_type != type) goto err; @@ -1790,7 +1810,7 @@ static int iommu_get_default_domain_type(struct iommu_group *group, "Device needs domain type %s, but device %s in the same iommu group requires type %s - using default\n", iommu_domain_type_str(type), dev_name(last_dev), iommu_domain_type_str(best_type)); - return 0; + return best_type; } static void iommu_group_do_probe_finalize(struct device *dev) diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c index cc3e7d53d33ad9..7c0c1d50df5f75 100644 --- a/drivers/iommu/mtk_iommu_v1.c +++ b/drivers/iommu/mtk_iommu_v1.c @@ -337,11 +337,6 @@ static struct iommu_domain mtk_iommu_v1_identity_domain = { .ops = &mtk_iommu_v1_identity_ops, }; -static void mtk_iommu_v1_set_platform_dma(struct device *dev) -{ - mtk_iommu_v1_identity_attach(&mtk_iommu_v1_identity_domain, dev); -} - static int mtk_iommu_v1_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t pgsize, size_t pgcount, int prot, gfp_t gfp, size_t *mapped) @@ -457,11 +452,6 @@ static int mtk_iommu_v1_create_mapping(struct device *dev, struct of_phandle_arg return 0; } -static int mtk_iommu_v1_def_domain_type(struct device *dev) -{ - return IOMMU_DOMAIN_IDENTITY; -} - static struct iommu_device *mtk_iommu_v1_probe_device(struct device *dev) { struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); @@ -599,10 +589,8 @@ static const struct iommu_ops mtk_iommu_v1_ops = { .probe_device = mtk_iommu_v1_probe_device, .probe_finalize = mtk_iommu_v1_probe_finalize, .release_device = mtk_iommu_v1_release_device, - .def_domain_type = mtk_iommu_v1_def_domain_type, .device_group = generic_device_group, .pgsize_bitmap = MT2701_IOMMU_PAGE_SIZE, - .set_platform_dma_ops = mtk_iommu_v1_set_platform_dma, .owner = THIS_MODULE, .default_domain_ops = &(const struct iommu_domain_ops) { .attach_dev = mtk_iommu_v1_attach_device, diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index 4fbede269e6712..818748a76e2469 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -1026,13 +1026,6 @@ static struct iommu_domain rk_identity_domain = { .ops = &rk_identity_ops, }; -#ifdef CONFIG_ARM -static void rk_iommu_set_platform_dma(struct device *dev) -{ - WARN_ON(rk_iommu_identity_attach(&rk_identity_domain, dev)); -} -#endif - static int rk_iommu_attach_device(struct iommu_domain *domain, struct device *dev) { @@ -1211,9 +1204,6 @@ static const struct iommu_ops rk_iommu_ops = { .probe_device = rk_iommu_probe_device, .release_device = rk_iommu_release_device, .device_group = rk_iommu_device_group, -#ifdef CONFIG_ARM - .set_platform_dma_ops = rk_iommu_set_platform_dma, -#endif .pgsize_bitmap = RK_IOMMU_PGSIZE_BITMAP, .of_xlate = rk_iommu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops) { From patchwork Fri Jun 16 19:02:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283116 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 97C74EB64D7 for ; Fri, 16 Jun 2023 19:03:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=byt8ZHhawlBk788LBoIZtet9P+BNy7UWKp4glOYqFJQ=; b=pW0ReVseAFR6Uz oUGasE7eOO8CbtGaniLZ9MZY/E/j7D3JdMb36CwJosdOJSx6XP7ZXmsraHruUVhC2byrxc/PzXnSr WdzaiwyGlBgaiesg6dhjl0V6kgF181Pw1Dp+ns/rxV4RMO2fPivZ+YFC6p1tZHUWFf1e2rIi6rpEN SiaN9uKmejovJBt+pq3ybC7i2JKy3ogQJ0Dyng8YArws7hbMBDap7JFYknStOVRGA0dnDj4ZkHs40 06kYwj4jltZwyWAHRkhqqhf5cC5geSKMcPMxsygNugO7kAHNM8Nvx202mpjCmPHSE6+Yev6Fs5VXJ MCfRKwURw/sGGA+SS5Pw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAEjE-001XOB-1h; Fri, 16 Jun 2023 19:03:24 +0000 Received: from mail-bn8nam12on20618.outbound.protection.outlook.com ([2a01:111:f400:fe5b::618] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEis-001X0n-2J; Fri, 16 Jun 2023 19:03:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nTFXpbijChNrhAL5mJb8maaMLgoADa2H/WpGWqp4cHf7RLvqkBjtVleTK4qhkc3v11ZCQj9g+J745LO8MgV3l+9qbhMSXl2QBjSmk/kxYNaqJrSs0s2/OCLFqxeIHU7OV38g9Gx3hnHwXkyOje0ED86VmdM7OgdJ2UgtE9ypzKlS/COT4bxeh5mB+CEI1HoqqP1C9k4t6MZfCqsLfaEh5+kgj5XyNWk28ynAPWBmiku10ZmvckM4ceJi5oSSk9aOlKHUDZUD2b+CLVceTx8mPWqSSz8aiPIcNCu62NoOTZY6LzjgMrAV5YMVICgJwZ0QzUQKujDc60e1G6F4IReO/A== 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=W1C264BQBMTFlLs4E/xf3D1AOn2brjnRUGsr5ogwL0Y=; b=JQvjnXQ2Mj2xU6qxs4zJ3Q8T6nCJb9Xl6DoXnw320Eo16xENoIVZn+x+5tIB9Wpo6OYt1/pVbZ11UH5YbK7qia8BKEsfIQgHpNTLAuf2OSO/7URms1O78O8O/y9Ps1RwLskdvBJmPcOQdbS1+eJLNKRcC/5ijeCUNJgP8P1DiDYIyFAJe+4g+RcZoVY0dIWa0ZyOkjDWLv0ojkP27kOx6WSL0q9LnRunarAf1eyotdnAc9dIE23iW600upMe07WF5gupAyPk2VR94t4kbkuqHM9JjzEM2Qh/KxQc+721kHaAw3ZuIUhDDV4VhwhPaeZOWcTKUpKl7/qMpq+EToBweg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=W1C264BQBMTFlLs4E/xf3D1AOn2brjnRUGsr5ogwL0Y=; b=fNtfiAaK1S9QhntGBPiTw4EvBYI5/ce2U0c4zOl6mywaIoDNdIEdkBm32fz3ePqGsHMDOGBljqtB1XHaPplhzO+bkdvClJ3FakO05311oISiYQWEaeZN2pHfB1qzsmybLXRPNQn0wugyJasmrt2erqIEis2fpd4MOlnsQbbjviKiL2GxHeNxZI6K70JX4emYLJXKNFP6xNnvVMnrLgZJml/78AwfornzXyTjS0wsACHpS6ijzgikQ8hDQKIiqWLUbHE9O7oFzU+xrxrD0omzPLPB6JOreBiltgUaRfyipI6WTPml9pXBEOsAHGGTd9RtZsmj52lQNoqSV//P3mcslw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by DS7PR12MB5912.namprd12.prod.outlook.com (2603:10b6:8:7d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.29; Fri, 16 Jun 2023 19:02:56 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:02:56 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 10/25] iommu/exynos: Implement an IDENTITY domain Date: Fri, 16 Jun 2023 16:02:39 -0300 Message-Id: <10-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR20CA0065.namprd20.prod.outlook.com (2603:10b6:208:235::34) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DS7PR12MB5912:EE_ X-MS-Office365-Filtering-Correlation-Id: e049e19d-6e84-4967-571f-08db6e9c4ac4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nRi21VTenDWK+mttTSVoEydIPy44vWge2snRez+d9sFc2TWCeyQNs2aD5xbMGlKUg9XtKCPH7CJA6D2gcF0bhaWU7wwu4Aox29fAWRDQmuZqeb3wOzWLaGL6wwBx6IFX1shHr9E/qQDVn/z/yPGPW4ZBWVDNPGCnov6nsYDIQxWXixBYB7aHXsxeNGM5ij9RmAtChDV09Aqp7G+uUzMYoWqFvLhixl0jlX4N76UtC7Lw2ZEYhp0wAigPdE9KQoAklPQcQEGcJQz7f5bbSIXbTkt1Hk2hLSJ00Ijw8DeZEM/Q49m/7ZA9+h16A4IUaZkPCdVkC5y+x3rYUeDdu3NiraOFFubf+55SXwoeiLCMq5O9Q5bhIlizMeI7Uyw8ujdLbAOubw88vGL/KmltgK1Y0UQyz8UADNXsyu13vuswDJsdJfzV2q0B6wUheB2thW0yWlv9y0u1qYoR3bP9VqzN6K8iAxgRXsg/JZDnLzqgNAZ2WwC2ZPZOhG5//AJl9EMAQJLe3hmF13q1rBPAAQ36Q2vKGjeKAtoY1auIiqobhNN3OYmv6hHSmRNc4WS3QIwvX09yFL5dWr6dfTBFwsoFv+KmA4MGIUMqDboGHCswzuc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(376002)(366004)(136003)(396003)(346002)(451199021)(36756003)(86362001)(110136005)(66556008)(66476007)(54906003)(4326008)(316002)(66946007)(107886003)(478600001)(6666004)(6486002)(7416002)(41300700001)(5660300002)(8936002)(8676002)(7406005)(2906002)(38100700002)(921005)(2616005)(83380400001)(6512007)(6506007)(186003)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WdCY7A7BDQ1ctE4FThDhVjfEnxJv/FlHtyFY2VKwQSqJklCJtQblDYJVB9fvU3HtLjhfDDEf+/eUPYevn6kvoS24OvpueOr2cODSvWe7gpCguOdmUPAZEZuP4N1hERVq2Gim7dT8fxWOSuHmq0pXvKXR24yCH8jRaaQAbFOLSGWinzRnDHv+4BDy7lb73pOXziYERgk1Qe01NdDO5ta9ALJGlRt3et/5w9zqLgIWRpqkPSLnFr5ZNkjvO5HTdaLcjzpV5F8++W3DxLaO3goDJChhAcVdP//hYch1tx1GAOnUauEai9UdQgDKxItj6JS22BIJO7GHa/ngurAPmGJR9UCOUr5PnQMHpenk0LsMsBg/ePmpNTCV6NEEIirxRWcEayambgfXm0rGj/rF/c14DKQp5797HV+86vMzV1i+NeQ/E4+naPkuq7zehpNq09Y78iSBMO67neJhI10MmfqWT9piQ47TM491iWLUFnIcb08gdLVB679y/p9+oTHGplQ7r/BDcp4ps1jsBZjDbp140hESBBaSxq7Q5ewa9xOvJ8xZzvkxJ1UozbM8x5hTl3WpQBo4jTS10VZKw2hszqWis3lYmk+xL5CvZmoo1DgyQqTq9/yJumwcL6nH4KMwN1ZJvbUrFB8d+BdCAYPEQixr3K50SFcPKdDPCWCcy3EpQIiM61v7nxu37Sx7EKhwEBd5uOusZgN3xyMc002z70mNBjp+czBzLsFBxvofioPXmhUOg6OyjXHQBBUKOO/sbn1vV7EhEqT7jrEyq3qbu/F+bzjxYPNV27C3vQTunAjc/jS0cQcQQ2gJFz+R2ZkFdZ4DuXUkSmv0aUcvGqnwFwdNeFKeLczkqlT0W/vhkYrUr9/D+K+PcJdkgDqp35Y1V5PCEshxcwKYCJaDcQM+v1W/l302RtK3dUEoZeCN2OClKBr0my5lWN0X9tqRKQmJVlJ2wlskIdv3RVLqWaFQ45Lff8kOIXVuQJs6IFHvfftczcOz58MiWb/O9y0P3tvrM1qHXmfj95uyoWa84S227l/AQKaYVHVVJuRvWip8CxyJsz4xzeasj1X+zSSk9JTGRe2mOBGD4vGDZofKT47jj6zrWPpGwtL8GweFEBOvt0kr16mwlfInMxJ5puolHLK3m6GlCUTzZ+0DfJuh8AjxOoCMEnkTWz19fp8trkjXQ5EzXTwoUybBrvVCRYp0ufEEI/WPUh5kZggKWxIrFj1GpvyNRlPBPD3eiefTf2t8ynGpPNCDzjo6zpVRVuwtwAklKj1QNsDb67wiQwwgZKLzzXN7nxEj80y9/v14fklFFgOv7xV7PGCPBXSKqccIxUpFOh8Om1cCN0Idzn5p3FQKhl//gz9vSnV0ENaQVjCTQc6IcWUmmC9k8xOU5Z8VwSUVi3RRLd3q1Glx4JHG5gFqtMGus79bWN6120En/BBalubZrBUe54VwmpdJjhVk0G0s0Ug2Ru5JGm5xZJb8geZJWwxIifK0xPmG3SHVEQ743HzmCJ0m43zd54Ro6I2QGSjfE6fz0jvjxtVZDkmNAfBtMA03z0DdfdGHHat/Yh2i91ia/6zMfjTLliXgJSCstEYun5OM X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e049e19d-6e84-4967-571f-08db6e9c4ac4 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:55.2685 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: HOm1zmd4F1Jvq9cB1F3RTZDjKvXajoqXOYfF0wwN8jZlrgsrtrLGCqeyUfC4emVC X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5912 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120302_764607_6023305C X-CRM114-Status: GOOD ( 15.02 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org What exynos calls exynos_iommu_detach_device is actually putting the iommu into identity mode. Move to the new core support for ARM_DMA_USE_IOMMU by defining ops->identity_domain. Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Signed-off-by: Jason Gunthorpe --- drivers/iommu/exynos-iommu.c | 66 +++++++++++++++++------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index c275fe71c4db32..5e12b85dfe8705 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -24,6 +24,7 @@ typedef u32 sysmmu_iova_t; typedef u32 sysmmu_pte_t; +static struct iommu_domain exynos_identity_domain; /* We do not consider super section mapping (16MB) */ #define SECT_ORDER 20 @@ -829,7 +830,7 @@ static int __maybe_unused exynos_sysmmu_suspend(struct device *dev) struct exynos_iommu_owner *owner = dev_iommu_priv_get(master); mutex_lock(&owner->rpm_lock); - if (data->domain) { + if (&data->domain->domain != &exynos_identity_domain) { dev_dbg(data->sysmmu, "saving state\n"); __sysmmu_disable(data); } @@ -847,7 +848,7 @@ static int __maybe_unused exynos_sysmmu_resume(struct device *dev) struct exynos_iommu_owner *owner = dev_iommu_priv_get(master); mutex_lock(&owner->rpm_lock); - if (data->domain) { + if (&data->domain->domain != &exynos_identity_domain) { dev_dbg(data->sysmmu, "restoring state\n"); __sysmmu_enable(data); } @@ -980,17 +981,20 @@ static void exynos_iommu_domain_free(struct iommu_domain *iommu_domain) kfree(domain); } -static void exynos_iommu_detach_device(struct iommu_domain *iommu_domain, - struct device *dev) +static int exynos_iommu_identity_attach(struct iommu_domain *identity_domain, + struct device *dev) { - struct exynos_iommu_domain *domain = to_exynos_domain(iommu_domain); struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev); - phys_addr_t pagetable = virt_to_phys(domain->pgtable); + struct exynos_iommu_domain *domain; + phys_addr_t pagetable; struct sysmmu_drvdata *data, *next; unsigned long flags; - if (!has_sysmmu(dev) || owner->domain != iommu_domain) - return; + if (owner->domain == identity_domain) + return 0; + + domain = to_exynos_domain(owner->domain); + pagetable = virt_to_phys(domain->pgtable); mutex_lock(&owner->rpm_lock); @@ -1009,15 +1013,25 @@ static void exynos_iommu_detach_device(struct iommu_domain *iommu_domain, list_del_init(&data->domain_node); spin_unlock(&data->lock); } - owner->domain = NULL; + owner->domain = identity_domain; spin_unlock_irqrestore(&domain->lock, flags); mutex_unlock(&owner->rpm_lock); - dev_dbg(dev, "%s: Detached IOMMU with pgtable %pa\n", __func__, - &pagetable); + dev_dbg(dev, "%s: Restored IOMMU to IDENTITY from pgtable %pa\n", + __func__, &pagetable); + return 0; } +static struct iommu_domain_ops exynos_identity_ops = { + .attach_dev = exynos_iommu_identity_attach, +}; + +static struct iommu_domain exynos_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &exynos_identity_ops, +}; + static int exynos_iommu_attach_device(struct iommu_domain *iommu_domain, struct device *dev) { @@ -1026,12 +1040,11 @@ static int exynos_iommu_attach_device(struct iommu_domain *iommu_domain, struct sysmmu_drvdata *data; phys_addr_t pagetable = virt_to_phys(domain->pgtable); unsigned long flags; + int err; - if (!has_sysmmu(dev)) - return -ENODEV; - - if (owner->domain) - exynos_iommu_detach_device(owner->domain, dev); + err = exynos_iommu_identity_attach(&exynos_identity_domain, dev); + if (err) + return err; mutex_lock(&owner->rpm_lock); @@ -1407,26 +1420,12 @@ static struct iommu_device *exynos_iommu_probe_device(struct device *dev) return &data->iommu; } -static void exynos_iommu_set_platform_dma(struct device *dev) -{ - struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev); - - if (owner->domain) { - struct iommu_group *group = iommu_group_get(dev); - - if (group) { - exynos_iommu_detach_device(owner->domain, dev); - iommu_group_put(group); - } - } -} - static void exynos_iommu_release_device(struct device *dev) { struct exynos_iommu_owner *owner = dev_iommu_priv_get(dev); struct sysmmu_drvdata *data; - exynos_iommu_set_platform_dma(dev); + WARN_ON(exynos_iommu_identity_attach(&exynos_identity_domain, dev)); list_for_each_entry(data, &owner->controllers, owner_node) device_link_del(data->link); @@ -1457,6 +1456,7 @@ static int exynos_iommu_of_xlate(struct device *dev, INIT_LIST_HEAD(&owner->controllers); mutex_init(&owner->rpm_lock); + owner->domain = &exynos_identity_domain; dev_iommu_priv_set(dev, owner); } @@ -1471,11 +1471,9 @@ static int exynos_iommu_of_xlate(struct device *dev, } static const struct iommu_ops exynos_iommu_ops = { + .identity_domain = &exynos_identity_domain, .domain_alloc = exynos_iommu_domain_alloc, .device_group = generic_device_group, -#ifdef CONFIG_ARM - .set_platform_dma_ops = exynos_iommu_set_platform_dma, -#endif .probe_device = exynos_iommu_probe_device, .release_device = exynos_iommu_release_device, .pgsize_bitmap = SECT_SIZE | LPAGE_SIZE | SPAGE_SIZE, From patchwork Fri Jun 16 19:02:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283126 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4BE69EB64D7 for ; Fri, 16 Jun 2023 19:05:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SzbB5XUMO5dIwyrrpPVSZptK4WE1Wk1e8qRCflBZjHI=; b=h30eyzAREKEige MN6fGHeHuIK12UFfMDtYCjfWuw4TeG3GVtdDKTCQX4UxID7rsYG/yeThKluDKv9SSlmNJ6m4E3Qwa YibCvO7MLPZdJsUHqJRvtyBg+B1z+rbQUCHGobQdyH2uCFa+WrQ5ElAZhYCxni+Q9cX/sfTIOh/XA V0OOCnwZVHk+IS3+Nky/4KIKW6fo7lSzaBZ4EkylPbM2VMrKamoyU01GRTK8HBlPiVnMDMGtCJHU+ hO7QWOsDwnkxZNO/bvONqkgBcyLfQ5U6cDt06sEKPUaMZ/rGihjUzCHp92LA/WhkoWwD3QAphCORp QyAt8cJ6+d7rBQtvf9wQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAEkf-001Yge-17; Fri, 16 Jun 2023 19:04:53 +0000 Received: from mail-bn7nam10on2062f.outbound.protection.outlook.com ([2a01:111:f400:7e8a::62f] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEj2-001X1S-21; Fri, 16 Jun 2023 19:03:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k+/Iz6LndN0gvIg2Y4PmIx1r9zCl8cUq408vanmp+Hn0t1Z1JfckyWVfSCrRM2wKfzsCnJEbrHfwVHoQoWzPD6Kl7hmbSgI8Rt5pS3ssNRZyhrxaCAYHYxaFyew1U0LVSs2LqrUSoJSR52wiiwm9CvC84kWPpzkLlurrqiqtNLZdwrvxGiXVVUsmuk0iDNar4uc9GDHJL6GJa6KfhnKCEA/Lm8SqR9cBe4jk8o4yz/j3iDRYJV2jqFq5+oSJ++aUc/9XE6U3oVitXflVP3/KwSl+HnkFvywbLLOC372qURUupSBqkDQBqIVW1j/+Hu5GOd/1m9cCi9QlWPWX6jxeTA== 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=fv07ZTI6TWqMM56BZclxgR+qWcyKeH1gSmVtTipkoJE=; b=IkyqRaB3tysGKjrBWhlUe0wrI2aJniW9sPXM4EoW++YdpjpUs58F1cakDgiUbRBCiKoC8jxSDn6pOcYcBKyb9JG156k+dWUnnEqZ2gq4RzKf5qw4APHLoE+AQFDuUtpjLj/Xf5NFL2Lvnw1FlxBDeykI/xvPrlHJvjaUdG7gmJbX86wvWYnbWY4JUqFNoVQ10EfMSACi8cHu65pbA4d9jmdPpyK86mO8E6bSmUaHhAPAuAfKEzigd8wjO0asEsNYztzCEfx39/vMxVXzHm9GY+ltFkoa/C8gJBidQ6TVHUFkVs6Mn7rG3CpD7HQHz8j+UND+M6d5gUy3Q2HBdZVefg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=fv07ZTI6TWqMM56BZclxgR+qWcyKeH1gSmVtTipkoJE=; b=gnXK83YM04q7/ZrspK6xN5mQY66SzPeArxCff7TwIg/dKUyr98JuQ56x10AoHtHu2AS/3kxLqUOd8PtM9GVN3ewGLaG/PgBGKYE5fYvJHs+6c/7l9J7STeKQMHF+OeRqA6DHpkL4gepFkIgsEjgfTU3hBPjlCB7+XV723tg92v76cQW+di4r4lEWwamXFGlxP0Cm7G5N5SdF8H/M6r9dnNb56ONJeYG3EpC7m37DqO7iJlsTWOMIQxsZy2m7X2PsvS+GWwqfZ2lVo15XAd3zdoPwxb/xYt+2khg2T93QEpWoXSbY424OjfqnHwynVf96zxV0aKWKJcZhTE5uJfQD7A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:03:02 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:03:02 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 11/25] iommu/tegra-smmu: Implement an IDENTITY domain Date: Fri, 16 Jun 2023 16:02:40 -0300 Message-Id: <11-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR20CA0062.namprd20.prod.outlook.com (2603:10b6:208:235::31) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: 1b35a496-4181-439b-0d0c-08db6e9c4b64 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: S16JY5H491tGXdLawWVxwYFjukxfuwJLyoovRReN+lgbvg2hFRrNVxTjFlOb8IQKJ92Zoa21PIALDDlZH8MObjvwkjnn2J9nrfbbpJ5TAi//raWGZZtP5dzJ6MPFnCtYIZMJ1tJkJCZ5j4Krc7chWI/apAu6QM/PERHla7799U0NVMf2vn64TBHxMoTlh/6wYwK1OYIVyoItBHEc2Kd/XRDEUtjS89U+/TbRxA9lUbHHULJLU/NO/8V3qQpA57e5ugaEIe4+TxbD2nS6MqQXS1oyQpxu4ZQwRpd6ixyDW2/PqHXmDjHPusB/UpeqnOObgjcBx0LdNGUzd8s0TBH5+rS9FYDTp0Ir9Bi5GS0SrBQZTov+sSwUU7xN4eCT40Dp5EF4z9qa8iOhxKpGCFodlhmIO/9GMykMtGeHLaAstDTe+N2Cv+lXWea8vtyEMAU4yErdXOWeNEkW/U/4oEP/7gsGUASW/YVwd3z/GZlvxMk9Kf+8ssbppkF8w5jNQGfne/rfvKjTnvuubyy8hIsy0EQDB++RodQxCx/JQoJEi1IdbunlLi0JdWki/++qG+UBflzxqdkNLjy5itmKTTImuBWQB3cEUojqZ/wmVl9kj9U= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EtHvvILHIfUte7GgqzfIWALlyjAklnOgP9lIo/dN3PvcrWT4IM9kmgdRUd3qLDPHeUWjl3WVGaOaRg188cwi8jM1pJ7nPKRS+Cx6uzk4xya0ZKOAFUFv4WLLfmpZSxGUm/VnotyEncq3Ua0F4hI3bXQQk9YgFYPiFHuCoJBnt5nqFrzbf9oVP62IQGfgXzCBiYu42WgyFShhdqprglenfDujGDV7oWyQ1nssNN+HCnWrglYCgd9HLV0xYKUBWo0KiSR5Rr/wLksNpJaj2VXQrQ3vLYP+/c3ORq8aQVEezmQ21r2MEQQAOwzU6v/Ts0egiEtsRkD4dI486A3b4O4/wtN+ECovZfAgDasmYWB8i1gGJy6AIPythOM4wd8jS4qK/lpf5Z0n6BMOLTCTf5TBEk4BgzWf/Y7DSc+seK1lunldT4rAD1rAATF5DuaQf+IihEfnEn6gtLwWNPjBZcgISxCi6x+wiKixqB/I0PjXzE5Yir4cuy8kEvrYvE9j11ChCH/Rca92uPDNC4ZBPDnfhiNTQnys4yZTFco3hoIdV4zk65xwoJ1rmg1bah/NuEH9nEMzenSDSnWgW4bACcrMrcIrAZBAPPqbVPcbt9sxQ+axqfwj7vAihoraOiJrVMHrJ1+M+93xEI5l4no5lGfVJEdNUUhGjfUIFlmo5CUrNxMJb6SRDnVYi/DxOfQh0LqxdX10zexhC0JSNGWCvQG8tBVjMfOoH8qAACZfJzjdDb692V4x5Kmzt7c27CLeX/ADnD4YOoxTNWoPX3RpCq7pjKP9RxM57UZDTk3NQhXB6IVViIEhz7ky0fmE3iBcrFxHgOYdIv4UCHfDfu+0oUMbCDy7nHNaVemppEpoCeaSlj/zYqI7R0cy7t7bDrrr33jjuyVAyJKfOQFF6YF3zVaOX6PJV9S7BPqg7cZiO128e5CYOD6G5M90KkUUT0w3cK6eFtxSUEzu98/l6/Q9C2i2EetBzOgFsWiwICn2n2Y6ZhS6vM8erIKxM7hoFWDuP4qAvcjE8ukCxipzFUESBK7g3iTA7qttzsTn3cWD9fEQ94BHsSILqwlgaTT+xGMLf04K1gJBdOXyB7Lt+eYnJkJBcz4VYNYPANB5MCrhkxfWCM8H1U+ORW0dfYIpZ1C6S13Pgqh/5MxQdylJaPIclPX7RUGMA216pVO4/4B+4fYin8Pk4roTNaKAjNPGXZ0DH/T+9+CtcmfPUV8vYqjMr5vlbkqGRKExKTqNJCeLMvi+uaaUq3muSEEW3rR6S9h1Cg9TD1yutfbkZFl2IN3S2EjVQ4Tg3FX/Op8K0e9PKauqO1WcVxUbl+6oeYSVLrrCFbLzOQxzVfoAa80SRNHkH9ud+7BMUTl77sBGAT2eIp3BuMdkeQdf7ydW43tIaaZ79bL0prj7UX5tTUKFt6owe1Q4sP+l2BY1YlG5vxBkD9jVmIqH0O77NL2cVebiLPWwBvzmNJOhjUlFezAE5WTi+TjtAq3S9/iYnUY1iEPmVf1/oG5IUZZLanTbDl36Z+Btj9iHKFIh+kntO/E6GmX2YoXd+S5C0bzLVIEjCy5ACGuafVIsbk3wM7Aw3CshQ6BxSRjY X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b35a496-4181-439b-0d0c-08db6e9c4b64 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:56.3597 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bnrPyhNONpiLvOpeXVchz3YP0B5OZmfteUyOUn5TrqWy64QKzxA2zcKekWiVs6Kn X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120312_698234_8F2C7433 X-CRM114-Status: GOOD ( 14.97 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org What tegra-smmu does during tegra_smmu_set_platform_dma() is actually putting the iommu into identity mode. Move to the new core support for ARM_DMA_USE_IOMMU by defining ops->identity_domain. Signed-off-by: Jason Gunthorpe --- drivers/iommu/tegra-smmu.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index 1cbf063ccf147a..f63f1d4f0bd10f 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -511,23 +511,39 @@ static int tegra_smmu_attach_dev(struct iommu_domain *domain, return err; } -static void tegra_smmu_set_platform_dma(struct device *dev) +static int tegra_smmu_identity_attach(struct iommu_domain *identity_domain, + struct device *dev) { struct iommu_domain *domain = iommu_get_domain_for_dev(dev); struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); - struct tegra_smmu_as *as = to_smmu_as(domain); - struct tegra_smmu *smmu = as->smmu; + struct tegra_smmu_as *as; + struct tegra_smmu *smmu; unsigned int index; if (!fwspec) - return; + return -ENODEV; + if (domain == identity_domain || !domain) + return 0; + + as = to_smmu_as(domain); + smmu = as->smmu; for (index = 0; index < fwspec->num_ids; index++) { tegra_smmu_disable(smmu, fwspec->ids[index], as->id); tegra_smmu_as_unprepare(smmu, as); } + return 0; } +static struct iommu_domain_ops tegra_smmu_identity_ops = { + .attach_dev = tegra_smmu_identity_attach, +}; + +static struct iommu_domain tegra_smmu_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &tegra_smmu_identity_ops, +}; + static void tegra_smmu_set_pde(struct tegra_smmu_as *as, unsigned long iova, u32 value) { @@ -962,11 +978,22 @@ static int tegra_smmu_of_xlate(struct device *dev, return iommu_fwspec_add_ids(dev, &id, 1); } +static int tegra_smmu_def_domain_type(struct device *dev) +{ + /* + * FIXME: For now we want to run all translation in IDENTITY mode, due + * to some device quirks. Better would be to just quirk the troubled + * devices. + */ + return IOMMU_DOMAIN_IDENTITY; +} + static const struct iommu_ops tegra_smmu_ops = { + .identity_domain = &tegra_smmu_identity_domain, + .def_domain_type = &tegra_smmu_def_domain_type, .domain_alloc = tegra_smmu_domain_alloc, .probe_device = tegra_smmu_probe_device, .device_group = tegra_smmu_device_group, - .set_platform_dma_ops = tegra_smmu_set_platform_dma, .of_xlate = tegra_smmu_of_xlate, .pgsize_bitmap = SZ_4K, .default_domain_ops = &(const struct iommu_domain_ops) { From patchwork Fri Jun 16 19:02:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CEF7BEB64D7 for ; Fri, 16 Jun 2023 19:05:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VIM6k9UPr/8FglE9aIDq67YRZsymiEH166Ch1ic5D6A=; b=rTv68uQfc1MuBx M5gVjl2cJnNuRmXma8Jhb7NJhzmkO4uVKe3QcDtC9l8m3BNabkc3i+A6I6A99nobzvUKK9C56NLz6 kBQ7Ih31gAsvP/BJNqjnsksEp0X9IHOKwXRn7+7iqGoCvrMsuyyt3SM61vcmISK+WEomADC8FXAVg vtnH3v/TaRQW9g0F3dJ6wbj5SYqittZQ4u5OoU+4PVUbMXtMBZcEaK3OgqsjfuW8+NWkPmNKKEWWT pRplREIeEKJ/Zj3CuwEZLvQa70ZqbNJOXPP+XrIu+gwDMWglrsonJ5q57/WcLgbqCRROMYBpmxF9V 82QyN8bjhrBYzCMCBNhw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAElE-001ZB8-00; Fri, 16 Jun 2023 19:05:28 +0000 Received: from mail-bn7nam10on20600.outbound.protection.outlook.com ([2a01:111:f400:7e8a::600] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEj4-001X8M-15; Fri, 16 Jun 2023 19:03:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TZCzK9mJ68daY3j9NxhGgi5HHP4ilRLMSTh8Zqr24Xvna+geqoYNptQe/lFK8bvvUFMoQCzs5veonkbaorbn92rhDuIpXlgD6vlPuw7pHmoshCxVh9l1JULrdpeuJN2HC0F6e7TgEAb2kPGT2v8Yb1c/nHWvpz/UCuEDmXbj77I6GwxFUDCx/epk/75lF0uQFkZ0WPyxdIesVd9aR5iv5YstUhIJZC0qjlPM55jtbOp1knGT7Rmcl+rbW1aCKh7rh8+lT0ZzFenHSP1Z76RzMfBmPWbFe2vbwubMVe+1KKn6HqfGkGyZ0/S7miNG22qcL4aokLmJf0Fg1iDAj0YgZw== 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=fUUt/fAI8ph2DHNlhM4gNIsfEv7BScpXS9Tps+iWPLY=; b=CUGUPeZ9M+f/91kypFo2s67Xypymm6M5WxcyTDEO8nyc8qJmbeTGNyAYg7K72f4nzH9hU4/pT3oRff/CDVTLlEMCn3MyketKRbl/KOtLmri7/r2BVFxEEi4LBhfl+Fcn8drXRWk2froa/VztEDvD77a9oRuiLMjUivoLV+YjtIW8zTo14YNx/VlOGFsEbQlyR8VtPDgfWla/vgx7LlMTgHGxOwCDfcxIl8jcEJMpfYLbCJp6oaKVNQA798ZhLq1Ju82Z0p0oIMBtUwfU9+krYkJkDyN3wprYSJqQ6VPNCna3xY97G9EwMpW/ZyVSa3H/YX41naZr98QwskIzSC2wvg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=fUUt/fAI8ph2DHNlhM4gNIsfEv7BScpXS9Tps+iWPLY=; b=ZFzSUWhdmbQsvIhGBrN03mUboymBDRocLFtPTjE7W5N6NGb08zCV+v89o73J5RuwTpnkwgOrrVPi+dropWyszTojOAXIkj5WzcgoHFca6blAejh25r57BsvZu+XNFWHM7fJpmwk/V+4f+jFKSRcWnN6MO4dA37lX/3ht0HpNTmwjwyVmvLmmS4cjF5T1GPu9DRMf6Rx58Jz0r0lXW29K25cfZFAC8oHMvPxuT46UiWXvW7kHdTo63uy1jjl5ZBYorBmnFYK3EW+jdW61cAEn6MhwDMgxHjqqj3ta+MEC40jpqmI3d2pfA7RkB3OpBl0937EPOvQVHAHNQSb5CAgDnA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:03:04 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:03:04 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 12/25] iommu/tegra-smmu: Support DMA domains in tegra Date: Fri, 16 Jun 2023 16:02:41 -0300 Message-Id: <12-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR20CA0060.namprd20.prod.outlook.com (2603:10b6:208:235::29) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: 719f4613-fe12-4385-4593-08db6e9c4b7e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bph0ONWjIbIlYMdA2cwyoThAzYx/yipSrfMRcOAU2mLkSHS5eDZDjWl603gdQrti4gefZjy5D0SoKy6S46cHg/WuWlhB8+Ww63CkUCBG+vzMWyIxaYZcWlZz4N5G8lCc2NSTssGWp3RyznYTGJldbvr5Xpxgm+gxru+EpSv6dNHmID8jSBbB1/snWSUtqS9mj31gFk8uM7a5MR9NiJz2XNsULQkc5/fY5jne7vXVEwp9iw6SHlIzPX7Pd9qnf+i7fcl9J1P3Vj2EuLCpfzBtv+oc8zc78g5x6BM8AoXxlNSjsrzJHDsewb5M7VrIwwO3O3qHR8zwVbL38WNWp3zag+2qxvv9E9HJHmOsNhPRJ8kz5pOMGWFNUyatGRtllBaB5DKkfqbkQQVrHsy8U7Q2/dZR22DZUOezH7GMh0K2ePJwkOfYUkMf8uCdV1MO+w3heSISioyFzf5+OyQ78xznPRj81D6X6mfnaOuVcw2+8jqZlaeojQYnDKMkALK1KgA3Wftz543gpuucPpQQlW4Xd+yuuXBw12xnGcCwnP30hLflhmzd9zOoKdfGq1B5cH8qg2F7Krahd/NTyjIFd7e/PWeNoGA8a8/VB/OZmdx/nb0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BVhCJLw/cV65UtBr6Vi9PKllG5qjOsCgk3SRAU/O+fsEwAnvsDzPhMXQguXoMipvDIATJJVPbkur0ixltovIGXiFFzJ15rBNpz0hF+XcXH+ZM4Z42cwU+NhSeJ1Lyis7xy1eDzR7lj+8DnPLuYh9JIi1tHy9qqwzJds2er4bXgLclm/ow6+O08s+h39B2ySGODgNxvr4LhDjGjvyj8D4yPvfAzXZw4SFalc2ZYbGgJP2OHPSx8T2Xovks5hdmd/p6PUGvTImr4wS2rdq6VFvFqoERc1EpUpbVSLXbgEH/R0SkDQ4muBRHGrgbz3+Y0FeTE8Po8aOOOCqy9mfyVDjZRVZfC1/WvM7mec5oMefy/9C5sSQAnW4uM01me3fzbsIv3EOB4lrM7YPr4u8SJFMTSHhSRunuEasR8MDiHNQGSYNZP5JhQpaZRhYnKjnTWRiEgZelB0e5EY5+Vc7zlgH6PxKy0sE4A5HmLgOFIG+1maAMf3xJplQhXfvvEI0PesfahpyKrOfazLVAkAakeNSIMdrm8hYSFC8oCfbtEkc+cFmT9x0MXcLLyy+whRflfiunAUtNvKwxS8Qq8ED05bd6S7WPLb0LO3BbhXlpKpx6ZbQeDabQdZi5QLsrjJbKpHORs4hLFJ5xtFNA9XqzIYPW8BsyKJ3IWNrV8ZB5UYxHx2ZrfKK1S0+qwfmJN5P08EVf4xOrKlCOomm3DHQxXGkNps8IU3vv8vtSBPdUMtY5LLTgKE7CNBicf253bTnq01BG1bahEGwi1COAL9obFT9dL6XwD/Op55MPtfEgsj64waqGy0HyjK400BR0PwMuDGaPgJvofSPv24byyBiMCMNxdfXeKVekyg6QiuyQz3ibY3x66cC25QzmKdRxXXn5knrUzLl3xZWylE6Ea0lc/9LUj7Mem92VXpRQSOC7qJqx0cdfhu3aD4w5IRB9E6giHth9j3ElJH3YnDe26AiwMYOYD98HLn24PSwC/yvv3/947bEZPG8RvyKOcs02xes3g5Zx7RECyeZEAFcS0D92F1GBVfYLGD2XqwryIlNk5doj0VTyk2mCuWTaQk1PoNiYvUkV4M+3A4pV6Zd8dqsc0fMuUltw1ClFB+HCp0FYPrKVlcsO5jmeopTASRrUAxRUUZOrDMocvxPBLVdw370uALVCmxWw06C3Ocva9Mai9KfUgDktbMRQi3Je7VNJtdYBb+3gNpfaPKo0KKkJTd7m4hgiCNOVVWGiTh+kIvlls+UqhUpTTHFBwpgaY5RWkHjPP77avhJSX9DIFXVVZnXukXofdtD9XXLa9m85XjZOJFLy3rulW1RbP8m3xWCC8oboou0F5IQAsyzr94tV94a7fu9f7gZ/FJtaLwr/5K+KCSafszLT0VO0uSn8MS9bh8UcsSeOpGcBnleM/U8veV2K0BuammAy4fWg2G/3jMyKdssfawRNshb5EdFAt8eFJrEiSqDPRm0Xwm3KHV2oU51BTKF9nNTO5SyREu0dnz2wmCHvqoSvPxXPhCw3wnxPiZjemDMTYrTE+sm/tjb9w1MZGqXdsTHP4qzBr7xSgmIewZ15czR9ICXPAbXNcCtaSTjxr+l X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 719f4613-fe12-4385-4593-08db6e9c4b7e X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:56.5004 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: eCiSm1w9oEWT2k5pY72RjoexHTrcywDz3wTSt3Z7UUf9FAfgXrb2VXtguyudLbzk X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120314_428614_FFC2E773 X-CRM114-Status: GOOD ( 13.01 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org All ARM64 iommu drivers should support IOMMU_DOMAIN_DMA to enable dma-iommu.c. tegra is blocking dma-iommu usage, and also default_domain's, because it wants an identity translation. This is needed for some device quirk. The correct way to do this is to support IDENTITY domains and use ops->def_domain_type() to return IOMMU_DOMAIN_IDENTITY for only the quirky devices. Add support for IOMMU_DOMAIN_DMA and force IOMMU_DOMAIN_IDENTITY mode for everything so no behavior changes. Signed-off-by: Jason Gunthorpe --- drivers/iommu/tegra-smmu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index f63f1d4f0bd10f..6cba034905edbf 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -276,7 +276,7 @@ static struct iommu_domain *tegra_smmu_domain_alloc(unsigned type) { struct tegra_smmu_as *as; - if (type != IOMMU_DOMAIN_UNMANAGED) + if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA) return NULL; as = kzalloc(sizeof(*as), GFP_KERNEL); @@ -989,6 +989,12 @@ static int tegra_smmu_def_domain_type(struct device *dev) } static const struct iommu_ops tegra_smmu_ops = { + /* + * FIXME: For now we want to run all translation in IDENTITY mode, + * better would be to have a def_domain_type op do this for just the + * quirky device. + */ + .default_domain = &tegra_smmu_identity_domain, .identity_domain = &tegra_smmu_identity_domain, .def_domain_type = &tegra_smmu_def_domain_type, .domain_alloc = tegra_smmu_domain_alloc, From patchwork Fri Jun 16 19:02:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283209 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 381FEEB64DA for ; Fri, 16 Jun 2023 19:06:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uHcoLf8UiPc+gPGIjCpnZu9WpaOjQaR4hjk5b/DeS1s=; b=UsXoMtaLyHqAKI p/NHelIQMz9lBNRwxSSoQ/8iKnNdJJyvYiZ/ilNDMI/Rxj2E7kZbrlxktK+UfeRgOTdTKiCOojejF nP7t9bOD79qw0+sRQwR0HB3Z0fzvypo3VVib2o9ZFf5+hzVchL+vDiS4XffCOcdSuxp9e2WY611Q5 N1I4XJ/S5YffWJ5m+6poy2VgiwV9Lc65/Mndp44O6Sxc8TGwktlD9CkArXldqB//HuGOs7R8FhAfd FaWO7BZ3Muw2gMRSmi4NGeluOzQNBuBd3zAT2oMCnUSyAj4LHjEJ72GrVJj8094GCFIHbAKilhiyM evTH8ikGAbVtoKPdB6LQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAEle-001Zcq-0H; Fri, 16 Jun 2023 19:05:54 +0000 Received: from mail-bn8nam12on20626.outbound.protection.outlook.com ([2a01:111:f400:fe5b::626] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEj6-001XAt-2W; Fri, 16 Jun 2023 19:03:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wb7Yn+8+apISWwRD/1GcDAEYLLUSIN1ynPp0VFBKJzgeSzBJ6VqROYPGc/q2tvlPcZNPfY4ZmbYIS6msYVvEUmt9R1k/QbbQEtCBC4fvEmF/NynrdTJ8WEvo0AdD4/k6oRisSbL+z5JfDJk2WdsgNrnKkMLVyEq3R2s/sMnYuiGlhXcv6XpDDVcadMVyPJC2cZdK5k3oZKkZRRcq2soONWZi7OVuBHbeFVUyU6OaVMfWCORENP1csRDjlywgqG29nRqM5gYzro8KJeov3M1mBeqkPHUklIysKDLV/Kf7TJ8jz5IaM/WI2yNhlWp9ZCirrRtZqp+1VlPDzoY0uTWVyQ== 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=rTyavZJIyqr4bzkZ78lJsHJ+7Og9ytKqwQ0syxXa+K4=; b=iQpTVigddQ3W1bvpxs9sZ1ZsGLS41PkyGIqEgROO10uFYEA0ZGMWUx+SNilfdqJd4s863rDQp4GphYMP32Uk7RQkCarPc1QOWFpkKkLJYtfq099aB9vkAqvSRzRlI9pmRsjCO54aoMNr/ICNQkdEbzin/iGwDOXJXY4w0j5SIDYPlszTKx77gMjWlWCgKHjWu6WVomSGDRMLuvsVGGDyxL0/C52AmiJzS4EBmJ8tKseQbzoIfZspEa5hWOO6fP+DgSqA5ScowcVE2CHVYClO9AgwMcvLcPGPBvfZefAntWkC8xD2yaClXsyTdEcgARFZzUCo94C6vVycQNYqRRtutQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=rTyavZJIyqr4bzkZ78lJsHJ+7Og9ytKqwQ0syxXa+K4=; b=V0n/5+R+0FViFScxxs8W05wMBwG7YYInHsPO/52mVT5bE44trSaLk/hWejunwAIHN2Xx0rgXIVdgRLCX40NI+7a1K0o4J65P+gM9vgUjJ2zf1Ccqntf4rI+aVTKtPOTxFHFkJEE2JMOUMpJyVSztSiuhyH/X+USbMjKQBSI83I08ddKISafFw3z4gGeiZKvvQzvo0Ug4FuI3x1Uvf6/9iwecpdLoy+Aj9p5RCXIGVqbFM9C0ZkKrBUKK+R1BJMOrhvCNIk1DrVrR/wMck10uiebIEnR6PJmRQ76B36K+RLFdvJBD25JSDnYEEjZXq1nct0AvRXJ0d0Dcj1cDpFS2kQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by DS7PR12MB5912.namprd12.prod.outlook.com (2603:10b6:8:7d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.29; Fri, 16 Jun 2023 19:03:09 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:03:09 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 13/25] iommu/omap: Implement an IDENTITY domain Date: Fri, 16 Jun 2023 16:02:42 -0300 Message-Id: <13-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR20CA0044.namprd20.prod.outlook.com (2603:10b6:208:235::13) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DS7PR12MB5912:EE_ X-MS-Office365-Filtering-Correlation-Id: e15153d6-da58-4770-3404-08db6e9c4c38 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uu4S2mUnHhscO0uGBY+MQu1YJu5VIIZZa3GiO7Zviq+PBMazSfLDVWbCD68f/DINXMPuDMuXZY/Ge5o0rlYKu8a3ZuiEK2HKkrbvdYr8qh2gQ0VHWf3EnFW6MgTlwIP5fxbGbL8AzQq0DIQoQ/zzUzwMBBAVni7zCR9/BEp2xzkAxB3Nss/AP2VY30Tg9yqWCGGRVNkcDWhO06eN7tHAA45zRhV4vv8pn3EjCgRjfyAhX+NPi+6zA78I6nPDoSzfHsqw8CFbMqDVmu+Bze1lrI4LZjcxabNG4jEJCe0BdHBsjDj3XrPUjx1N9YbYcsO6yS9fJUkpWoDVhw8tS5XFJelNpK2XnoK9i+VFaSXGvnr7XnIhhzWvJAzbyTMO7bDOHFEziS9NEFJrPTVurvErcz6LGufMzHU7mcvkbsqqBgJPe8x6AGwv2NhA8tTNy5p4ARJRrRK+/i+2ALJaIPpp5JgSveKbFpvuhcWytstoQgRe3blEr2riLCWh0N4PWW1kpfxnSyWTFa3asagsRH3XVImXHTEONeg4J8SeynZOlnEmyjU3Ilc+/2GpTg8D3nAcXM8tK3lLQTBpv9czwjtQkOOuLWdEsf5pCgtoOrb3xDw= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(376002)(366004)(136003)(396003)(346002)(451199021)(36756003)(86362001)(110136005)(66556008)(66476007)(54906003)(4326008)(316002)(66946007)(107886003)(478600001)(6666004)(6486002)(7416002)(41300700001)(5660300002)(8936002)(8676002)(7406005)(2906002)(38100700002)(921005)(2616005)(83380400001)(6512007)(6506007)(186003)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: v02JbY16jTCFtltKjqx6yHgbTZKQGxkUbaFt3DZXk6V+5qgIsDje6CD+tmUV4q6YD8C64SGeUEystgChlqJ8v5gTnGc3aNY10Ciroer49arShxPiXpeofrXLLlbFQu69BWSEgcMtiS+Z/FWn/VLBoDHMO7ovMIZAlbr9S8CY8oD+4Z9fCQLPl8aimVYM5OZ2QJRguqKSPz33nnGT1sSldooFJP78+jALi0any3DhaSqyzQ5c71WDfodFdPN77Wpayl4LNsgRI3dWVi0OLQpxIcN6fB5yHkKbeANwNKX429Tb3adSdQQ5DEQhy2rwDwSQD5cJqs4pcUVkRptKETsF/w81PVItW1q5fpmV0//uPEf5psgz/drcde24QctD7/JVM3G3ye7TVCBSFIs0Uwg55qjHBnCz+vp9AqnlyOq5FdkNU0jTY3RH8IJaMmGMe4L45fYxTpE69h9u6ifTi0qYjDH0HzY8RbU8w9J4Zw+QQfk2ytKP5r2b3HWQl0BeQSkeULsemNw2scaPpE8pqI5dc7rqBosMMfMy1DHdiSQxUTOjVCt73qTirQD2yQb9Ea4njSPq+l2uStMsOug49PY64S/WvBGOMMfY9ZixhYwla9h0HbdzJ/Hpdi01hp/gtB8EZX0/A9fJcuCKg2Ld8eCJqjABP78Q/OapnAl9JURLiMuP4uTdJCzN8QJzMwOUO4c23F+xcKj469jjoPEALKQ27ZTNrQRQWzcdYtSJUn3pQe01VeP3Kqq7S5QMijt4oCgivsYix/lR0Dtba/kFwH7o1OT1W2bMTUVd10nU1avORE3XXg8r6XYmO/sKss++pNrQlrQTekaluXT+AACkCwIUugbN5hNCygGlGnXhhgPHCEBN5GstTZongcwrNfJAuTzQ0ZGaTmzVD3SXxEVszQJKv/fl+sNvR1SS3TsTyL+JR2wnl5ln4P8PcLOTOpDjdRKQZA6ERTBJmSBqc5edt0WGAiR67AjN8PU1xGLq5C6UKbYDPETzv/AlWJnRHHifuIHkNdIAqP/1whBk70VD1r75B2rxS77BVIxScnw1QCnS8TaOP77bmQlx5r8JTnbxs2ph3z9nDhBOdxYq4pj+7cUDofCP0Xg9xemPKN1K0qAo54/1CcRoHwIG2YwvwJpAbIy4zcuHVBhj3OKLRQ6F/wdQkk8f4BPAOExhoADAO/oYDnHlCuAB3nyr01iVrkD38MhVL0Z0yD3hlPgAMxZhR51yiVWlp/VvAoWi6PlWOPpCZZu9Zh1usKyRf72qsx8pRouybQ216Wv7ETVvcIlZ4l9pV2F5cDB82+S1rZ/NIowZzA5+RCkNkE5t3iF2+VHHgSRiJXQYwY74Jv0GhQ399yHOrB7lAhKHAwM/qqCg3OVHI7DM2ynl6reBUujArwfHrsnY/o2vmQ6e/d0rSSRqxGYs2Hy0MaJKW9J+DYqNgPfYBTaPqf0HjcyI7Wi8qhDNJ0UNNFKJr+T+E5sAUGMapWYl4obuX2Bvlxnc2JqGN046OWnK3mX++ILhvXYE6xMSlTcfEI3eru/WWyqtIjE6WkN+G00CnYZixDRhAgcKXhLQRYiKZA5n6EhvXlJWmVU3xFrn X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e15153d6-da58-4770-3404-08db6e9c4c38 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:57.7178 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VSipxwvi8jAscsPkljHGjmlz6rYZAdnvitxnyl8+NhFFXY22uHdPo8rjPrWBq7/5 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5912 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120316_873608_D6008217 X-CRM114-Status: GOOD ( 14.18 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org What omap does during omap_iommu_set_platform_dma() is actually putting the iommu into identity mode. Move to the new core support for ARM_DMA_USE_IOMMU by defining ops->identity_domain. This driver does not support IOMMU_DOMAIN_DMA, however it cannot be compiled on ARM64 either. Most likely it is fine to support dma-iommu.c Signed-off-by: Jason Gunthorpe --- drivers/iommu/omap-iommu.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c index 537e402f9bba97..34340ef15241bc 100644 --- a/drivers/iommu/omap-iommu.c +++ b/drivers/iommu/omap-iommu.c @@ -1555,16 +1555,31 @@ static void _omap_iommu_detach_dev(struct omap_iommu_domain *omap_domain, omap_domain->dev = NULL; } -static void omap_iommu_set_platform_dma(struct device *dev) +static int omap_iommu_identity_attach(struct iommu_domain *identity_domain, + struct device *dev) { struct iommu_domain *domain = iommu_get_domain_for_dev(dev); - struct omap_iommu_domain *omap_domain = to_omap_domain(domain); + struct omap_iommu_domain *omap_domain; + if (domain == identity_domain || !domain) + return 0; + + omap_domain = to_omap_domain(domain); spin_lock(&omap_domain->lock); _omap_iommu_detach_dev(omap_domain, dev); spin_unlock(&omap_domain->lock); + return 0; } +static struct iommu_domain_ops omap_iommu_identity_ops = { + .attach_dev = omap_iommu_identity_attach, +}; + +static struct iommu_domain omap_iommu_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &omap_iommu_identity_ops, +}; + static struct iommu_domain *omap_iommu_domain_alloc(unsigned type) { struct omap_iommu_domain *omap_domain; @@ -1732,11 +1747,11 @@ static struct iommu_group *omap_iommu_device_group(struct device *dev) } static const struct iommu_ops omap_iommu_ops = { + .identity_domain = &omap_iommu_identity_domain, .domain_alloc = omap_iommu_domain_alloc, .probe_device = omap_iommu_probe_device, .release_device = omap_iommu_release_device, .device_group = omap_iommu_device_group, - .set_platform_dma_ops = omap_iommu_set_platform_dma, .pgsize_bitmap = OMAP_IOMMU_PGSIZES, .default_domain_ops = &(const struct iommu_domain_ops) { .attach_dev = omap_iommu_attach_dev, From patchwork Fri Jun 16 19:02:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283210 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 70D0FEB64D8 for ; Fri, 16 Jun 2023 19:06:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BkTESgIdAEyU5X7y5xSLnsdnpP+4W8rK5HPgtIlFHTE=; b=VjHAxdQ52E/p1E Xsd8Ix7zRiEQ3mUbIzsGyFwPe0ZZkO6ZYuYV8S/i23TIVO6KS32v+85RHmfIsBBUdYMeKo+iO3pkb L+1z3g//VhjErEVYwG4N23tHLcVubNfRl54sOYjfN9m02dxFhkFxW5m2DXj4f0ZCMS406qGBhMfTM l4qD+6/70c1rcnGAnvjkO3l9Hf41CO8+z+7if7QPSYOGmt2tVG/QelqvhSQ8OTpA/e5x9vaU2JhA4 me3Gny3SnZOAv/aHvcmQQjjQSxO+lmxNqjrBQHohgIMnUwxL9qJmSnnvCRT0IuxfaLb88PbekiX9h IySyM6fLmFnP+SMnTA8Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAElq-001Zna-1F; Fri, 16 Jun 2023 19:06:06 +0000 Received: from mail-bn7nam10on2062f.outbound.protection.outlook.com ([2a01:111:f400:7e8a::62f] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEj7-001X1S-0l; Fri, 16 Jun 2023 19:03:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VBlHn2HR1tj/ifcc4ASOiHLh4XYL9DuonDJXWYv+mVB5BbSgqdg21l2K22Jscv9YM+94j9mNe7OdkTk9e4sUK3+b3WnjYYTJcOYI59GAixvuKTPcNNiEang7bKDW8gNeflasX4esQQ7OIsPy4tu/h4lVrKcvugAxlb6VOLeMElmVSVn7CAFo25LeLaAEYJbeB3aZIPFvkHJ+3HNockpBCLNBawv1MzQcOX115wqET+YHTpMuZ+7LQziyskj9hHy4xK/rGc6gdjme+VqiQB6TCZKo/3qTtdqzp1EUCwQDZcXcBoYgov7uuVl87fC3whELOWWL1BKdk3wCTClM3TgaHw== 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=LFI6YlGa/rRO/LUho1t6NDgB0fD4aHQKfGv6pVqsJA0=; b=P3NWaJQFC3z2TE3kIOVrDQJM2Al9+0dkBEhFQ69EnNvWbTZdCRr5NDDZHflzMwflC/KNo8+fxoJcktPZ0hekLxDgkDBglWM+0XXil3Qo1EQ99UuLqHgyuwZwG+gqF4BbouGDSrtfjohmbnslUmL430Tv+c+1MlqQ/qR0FhX8RO0XvNEbsXj7G7C8NsI902jaLnsQNg9ZcNqExImYxbhMdeVkd8U7uH3YGl2+ibQtKS4pnaAo0gC93LbA0ETfijSn3zAiF/WyVYoplhzxEslxpgaRpnFRBwnMWtgY6PLIC6Lj9bXFKOKK+6A4hmExhUSDBLulZ+SHJGPdaAas8yyNlg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=LFI6YlGa/rRO/LUho1t6NDgB0fD4aHQKfGv6pVqsJA0=; b=ONxIOThkM3E7AW4ZgSPhF46OtqmQHNTBKtgX8n75TLElY8Rj2VgUYBc2Ce+VdBBF0yEUpxJSTorZpoMUm64LHRGFdr4hNX/qSC4CxUZP6gEcQMGV7Uw+eV0Op6V0No85AixpgaLs4D3HNwoXFvKh8zHf9chmUoMca86/fv9ELguGMIunqOu4en1kaZWS9SEGk5geN25LqhxZFzK1zy5/s5T3hLIHz+E/Jw/CusmO+sbhk9K7UpjnE68CJX6Nw1Ek+EWMgGh8wj+qBiOpJx92h/xS8iA+XG+pNr4gaqcWh48k3cso5DRB2M0/AKTxjz2K8oNWLTX1tNGw5v8wUDyXLg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:03:06 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:03:06 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 14/25] iommu/msm: Implement an IDENTITY domain Date: Fri, 16 Jun 2023 16:02:43 -0300 Message-Id: <14-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR20CA0049.namprd20.prod.outlook.com (2603:10b6:208:235::18) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: 8b1c951e-1edc-4e03-015a-08db6e9c4be0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6y1OUPj2yfzpakAH9JJ1ssrLz2xtYyn6k2QkEaMDPozzAzVrBLxKYhmLu9RlMCpcBCRnRlkNid9CC1CqcQLoM4yGcuF2KIYdJNEdckQbPX6Om9oGZYwgNUa2Q86XgozUNtxGFw4gakQwkmrsJFKwnprmetjKI+R2eOnw9Aj/9VAQQMMy8UB8u74us/1kNCVATfhTGk59s8jpnK32vMiQra+BalFLUbTrxIpBj0iNGZJuEM2bgayQyFD4vUBo2YFU8J6NHV1xAfytGe8FskclIgTD5Mc8dPQTNEtPE0hejcDo/kA74UHjte/BhCBfh9jR4UHvI9YLbwZSg5vSN/rm4kucqITTlhopuC4EvHnUuVC3I/yqH2vahBZpck5cidjnIBnTQ3x2PqypgZxNSZD6wnou4E+YILmFXCtWe2IFw1ANL1eVaf0KWaUKhxv09v/eJA3+Al8lTOTCAySpkMqdOmqT9RBqtShvk11qxf0fNgyNEEczOMBd6+tS29JP0vVFgQ2XavxqIsWKHTAEU2LKWo59g5W8BLxbWcJwO5HSPunl0+s0jzRVsGNzk1VQWMWltT2okJsJ4AQkMjyTObDYmZZw9alg1dBTOzF2ls9FHxs= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fL2fYieiYy0mEntm6Za9cRiowu1XVA/+FtlDUiDyaRr92vcSZtHs1/wE7vl1EVo+tcb96zkVy4SWbPWtcWtStD6qDFSbCZBb9dyvCpWytlx/tyK1w8YOz6cgKQSMBIbBw6+KsvwDN8DruNSbb0N0uHQg8CSLgVGPs3sxlL6eO79w+h85pkgpXhfQRt/vtDkathQAQ57NpgiRhCxf3LeCZle1gQDR4B2PuNT6ESgOyfQw1Rk8lhcFCKmO0fxEthJLRumE165ODcf+yEVv/QIPtfx9Grb0p+SBBIt6wGFAnRvo7nIW3Z6IgCEj3MEeyFjokYkJb/2RnwOfOW6atcBV+d2qir47eiTSm5NtWekOKsRI++h5KANqLpxemnbdFcRT3nTs3j9eNMiNZPeKtaDFKPTjb3i8ewU2lFz9niQB0AE6BstRIcccXfAHkyldiXib26QT4Hut9HCl2SSzQ6+u++W0ElYsyBIrZ7yKQke/QCDu4axPaGZaObCHXA9B6COjTSjgolPejaQ+Dequd4QHrx+0mEyVoTHrdeTzB25/Mt/h7jPN4zRftL/PgdAHE33UyLGtbA2WE0MeeWKAbKPBOC5Ao9EbnIptGnfZ9tFZnicbTJh5SEpOO7dJWytewoaIV50UiRY2I0E33s0XQKlhjWgaYo2FFoguwxSZmrX8q3dzrFIAOjz2/L2HPzJjsrVxbRgoAKTfvNSMRhVyfWqWOyAl2WbHbqZCRW72XnZl8a0d85XFK/nrQ5NXCnwDzUA5oY6H0HOimLLtIiv6YXHcGPWFa1GNVCMTYKtQcq+CtM4Hk2Xu5aGQKKnpBAkBdpyxEPpFaD2kiJckXXWfLeMpLy/YoIfgvm5xgOTSYHU9xWIhgtFda2rYH7fa3vU+0GDfy+rb1GaMmNhbOQKuqkm/i4l+Of2Tm9fNC/HWEU0lq6TLaZPf73VS9MY/nFLfae6pytwALHNW2Y0cKC408O+Kun+ZDZveH9xvRRGun2dFx88svL36DhEyCzxayHP+gCYxEQEgM/0Mk7uQ5QgsDw55bd5DxUczqq7XlYnuSknQgBFagczuDSyQgNh8RYZP7B8US1VzFK8Bo9eyvAGpJZzZOkXAuprm5OTGN1GYfKwP4ZBjTJtDytpTzs4idzOWqHSnon2m1P3hm+BK6y2LlVPW6UEuwK8yeOb+UDNlSNfUzsbV1jFMKaz4nxOBdSBQDxFt+j1eGXZwNuztJY/8Xnxh44QZE+UDoPpZB7UU9tDcDiTDdl78Q5oJH7Zd2CxjCTPjMbb7DKBWed3rjzUcBJufSO0741D0zskPo9NN45ZnuOWS2wCBeNsITa5QmswTc4tbnZJ2wCe6EQBx09IIR0srimaeYbr2jhm/TTnHVASxtiSqOBwrYq+96MJEwDppW15scBlNJ+3As+mCCEFsbHwRS1UNdhmd9MIkXgFTPzTv4KFe+f9QnlhOgdZUvJaZ+FHdS4ffo9n9YFuGbej6PexJOCJ1PSrAdAFhWXaBaLrstSUFqbEKBEazifOCNEqPt4GVdzviROw4Znm695Ub42uZf4rOdlukHGc7h7RK6j3bjsoO3hIOOA8Uvbv6s9CiGC68 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8b1c951e-1edc-4e03-015a-08db6e9c4be0 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:57.1430 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XtUi2J+xpHy+60QXEs3ROS20LkFeg1pZTqozuCSTffnsDda6RkbvJfTZ+h4Pfl3S X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120317_330156_E07BFA79 X-CRM114-Status: GOOD ( 14.83 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org What msm does during omap_iommu_set_platform_dma() is actually putting the iommu into identity mode. Move to the new core support for ARM_DMA_USE_IOMMU by defining ops->identity_domain. This driver does not support IOMMU_DOMAIN_DMA, however it cannot be compiled on ARM64 either. Most likely it is fine to support dma-iommu.c Signed-off-by: Jason Gunthorpe --- drivers/iommu/msm_iommu.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c index 79d89bad5132b7..26ed81cfeee897 100644 --- a/drivers/iommu/msm_iommu.c +++ b/drivers/iommu/msm_iommu.c @@ -443,15 +443,20 @@ static int msm_iommu_attach_dev(struct iommu_domain *domain, struct device *dev) return ret; } -static void msm_iommu_set_platform_dma(struct device *dev) +static int msm_iommu_identity_attach(struct iommu_domain *identity_domain, + struct device *dev) { struct iommu_domain *domain = iommu_get_domain_for_dev(dev); - struct msm_priv *priv = to_msm_priv(domain); + struct msm_priv *priv; unsigned long flags; struct msm_iommu_dev *iommu; struct msm_iommu_ctx_dev *master; - int ret; + int ret = 0; + if (domain == identity_domain || !domain) + return 0; + + priv = to_msm_priv(domain); free_io_pgtable_ops(priv->iop); spin_lock_irqsave(&msm_iommu_lock, flags); @@ -468,8 +473,18 @@ static void msm_iommu_set_platform_dma(struct device *dev) } fail: spin_unlock_irqrestore(&msm_iommu_lock, flags); + return ret; } +static struct iommu_domain_ops msm_iommu_identity_ops = { + .attach_dev = msm_iommu_identity_attach, +}; + +static struct iommu_domain msm_iommu_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &msm_iommu_identity_ops, +}; + static int msm_iommu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t pa, size_t pgsize, size_t pgcount, int prot, gfp_t gfp, size_t *mapped) @@ -675,10 +690,10 @@ irqreturn_t msm_iommu_fault_handler(int irq, void *dev_id) } static struct iommu_ops msm_iommu_ops = { + .identity_domain = &msm_iommu_identity_domain, .domain_alloc = msm_iommu_domain_alloc, .probe_device = msm_iommu_probe_device, .device_group = generic_device_group, - .set_platform_dma_ops = msm_iommu_set_platform_dma, .pgsize_bitmap = MSM_IOMMU_PGSIZES, .of_xlate = qcom_iommu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops) { From patchwork Fri Jun 16 19:02:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283216 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 08EE2EB64D8 for ; Fri, 16 Jun 2023 19:06:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FkWdZimjGgLf1+vC5LNSBTov0LXY5inNrDRbZlUbVo0=; b=Qem6JDgOGojCt/ 3ms3stFAQsQGsDpUf2HOqD909R4BaKwV4iLPHG+GN1CAVBu35uFOOADXb5ocHRa+84dlCRcB+HcCN lGm+eg8HNPeUIGxxluU2jce2sIc1fjmLzzCecYOJq0pFO3V4pwsifiYmAzQOnOXXmEcEKb2J2Wz+F sBnPXh7FXKd+4HKnXcO/O8X80CMH1pF7FUb9TwPJI0Bmk4tU1ufywc5mf15Rr56zdyaPtS8zElbwJ xxYh+IyEIfPGpFpmN9aD6jEe9uohq3vrjkLITUgUPLgcq2XPpwcJTAznEK6LGLMKry6QWyayX4uDu A1eNFGs30Ynuir2YaYuQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAEmH-001aEA-1z; Fri, 16 Jun 2023 19:06:33 +0000 Received: from mail-bn8nam12on20626.outbound.protection.outlook.com ([2a01:111:f400:fe5b::626] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEjC-001XAt-2y; Fri, 16 Jun 2023 19:03:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GRhEmnHwLnr9Ez13B9Ep6kg5Naa0iYZmUb89fx/rWs6WKiLA9ODjLoPjSVyvpFvJHLUDhchqCSotpb6uAmUGiPDCNB4LAvHtznfwvro5f3nVX/9xn09BpJ3B+0716UvScQR9CC8pCIymAVUNuTsrwO+Vg695cpsSqh9R/GtNf950M2KjPj2e4lSZBKxmzZo5Wn1GqrRZ2Nn1tBuM9cXDkLHdpiG09OfvwQ1RFqZ+gGZ3KrSDRQTVz6btbHloimcTXOUBGFLseIDoE82bUzscHnvRk8NtzwCHqC1UPxFph/jr7vC2ug7BYMi1N2PvE8SDpiZUJSkJXFgRGjSBR3gyyA== 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=ufSWSvsleexlF3GNgDXWYBv3/yHgBGse/HO/S7+KY9k=; b=Q+bXc9qS/Ma0U6zuAjELIX8HDd0XcpAUOLkjcq7q8JakY2mrG3aI6wEByoUpIq9GmUQ/0ueeah1pHjVc0eHBpuzDefCyCkmixZexDXGXKHVQq367gIREVUZWX+pDRdPA1/5yDfbAbODd494gVbHU0sK1kFjVpq8s1q6cG6wR18a4SVVwHayC2pbnHsRKZYoflSt/mHLYwblK+/TdMUmitQzvzkQdIM+eIH50FHacyMC5ZGa0kf5f9tmUaebczX0WaBPSNmJzsWfCixcYu/ayK4xpHfvacrSKR/cCm/koBUYFuYWUexDEG4QtfH6GI8Yq7qEhBPeijXmRv1BHWwlGng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=ufSWSvsleexlF3GNgDXWYBv3/yHgBGse/HO/S7+KY9k=; b=efz5JtpQCCHYuybGKAF5/iCbkJVxIaevIvslY/euuNw0metlnaj3AY05PbIzMbxZjtzgtRJy4Bv38OxKXEspdFM+/tWNeVbdRZCleRky7G2Q4HNWyBUjkjhlVjwD00pljzS2c/t+138yZJagsQCFLBDDuzCAwxom7Fn3eMXHFiWu+yXNc/Ngcunke8y9J1KalYMXOlntGX0tx3D6Fgt857j5vYLJ+B/uFouA2Zjfijwsx4b3gDO0MaduwE3Bnzo7O2MHRr5IBcvR/DAnQzLauLuwi0trsXenp0EM0otSA32ZYs+NIqHkIH2W3XZyYsR1AlQqwDTRt/95A7bDhhhyaQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by DS7PR12MB5912.namprd12.prod.outlook.com (2603:10b6:8:7d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.29; Fri, 16 Jun 2023 19:03:10 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:03:10 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 15/25] iommufd/selftest: Make the mock iommu driver into a real driver Date: Fri, 16 Jun 2023 16:02:44 -0300 Message-Id: <15-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR03CA0061.namprd03.prod.outlook.com (2603:10b6:208:329::6) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DS7PR12MB5912:EE_ X-MS-Office365-Filtering-Correlation-Id: ba463ba2-4f3a-4539-4f23-08db6e9c4cbb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GF0G29oxabSmmqdQN0BnFy2tB5iNCES4gT0yZW2eoqkutCfko0YX7QrjgqWOjSKcYuiAHVoQDsd0imyrlf1swEZpd0NdSpd+gnlfkLU4XFYCBWoGyWVkXpsvqwzfC7NGKBmjxYENHW24R4azcGlR9PVh+r+xUbLI6F9E4vMGBYMtYzvgxh7o2uzXyAd1EwlsUQM8bU1jJYn84UzeQiNH3BEl9xbpw65EjGB+z3AMIByYPVtNDqBG3C9o/fa+28smDEDOqk5P1hr28C1OHOESiPY8YClF/66qIwsijcLaj2EHUsCTAvHZxDBGQTFPwnFDowEMZJNNiGf3fFTMmKWDjOdH/ovi6SbK4/1SYEzCcuyFg/7Ei3mYFBtONdattUIZiVXHeu7rZAcGhVeJDPLbBMlcPbj+q8LROIARY+IgSMh69Na7ts/tXL5uNkSgEMbIYGeytk3jNqLurskSz3kx5FgJ7KmYu3zEpd+MiJPDAP9ppBqYkPNIGSkiho3HZR9Msn9F84G2MuDrDciISiezaCYDKpSCfN/jSoUPegsI5B2uXsUd8HaW6M9ZB1UP+ri66sdlh0ksuUBM8yIC78TLHhypMom7JhXqvFJep3ko7VM= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(376002)(366004)(136003)(396003)(346002)(451199021)(36756003)(86362001)(110136005)(66556008)(66476007)(54906003)(4326008)(316002)(66946007)(107886003)(478600001)(6666004)(6486002)(7416002)(41300700001)(5660300002)(30864003)(8936002)(8676002)(7406005)(2906002)(38100700002)(921005)(2616005)(83380400001)(6512007)(6506007)(186003)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OD3URbfRUK6XTLLO446Pg9h7hT/PoE7wKPu+5Yx5BWOXClT0U23qVEZfaRjEpVoogRex/H+LwgbY4qYScVtVQ5iy+7+AOv8GCwM/TFh9Sn/kdh5uDVbjpXOLlf4VpB4EogWyjpP3QJDTg9uw0Y4uvsg3wtzSRE5sopcdpcYp1xh++W7twuZfSSIj5js7pWLw+e0T/GhioCshFkU0lLd6/kFm8bwomaW1V7yjIh6lCgPHkKmEVa8kaYc38HH25vg8/CCyBrHKyjQSSOXIIAgDhZk5G9aa6KLFR70kq6FZ0p9gBZO1I0nE3lIxEYxg1vtFrxDJq617ueb/hpDD5vPl1b2F2dO+OcIgXKvT9IV+KdkuEzyap+uB+kJ+Tv8zN6GZmzD58/1bRqqZEFe7KJ7GQrLc0/6WwVhvC33B+7n6p/Ciwq7F3yD9CZ6qYcMylDxuXjKJQyQl3IVXCBRjvEhqKL09H1SmoRwjtftnEIYquwKt37pQenWLSYommzA9a/hVB9rejwoWQaFUkf+QTuI7l50Sgoe+yfnIHOWsyje++oN6Fhrc0GIbeafvIpjvWlpYxI1Xh2ZvRMaMS1XI8MLievZPGuY/HBXHcXgS8FGdF6WBLdug3L48Nay4Q74G/QO3HBaySIN13VbPn7ZNrOT4Nafh64oZuT9itVKsYZZ9OerC6igg9pOpzkVhIA3Ib59gRCaadGSIlrqB10pFX+H8MWw7gHyhuo+NLFmamIZ0mLQ5uWWi+Cjy6nmW8h+TiayjoVPCA46BEwclI1tXTQrUHEX/CQWYE6hFT43pVAPWDg9aIYSBz3U+JC1f5WeQu7MSASlpVYWIGTwDPGlO7jA6xsrIYY+94CHbDbFzQRB4dCEx/5pR0iOE4v78LorA4NRokfFsF9R2f9+E+jQAZ/6ww4CSEHkHKRx/Ln3hQeyhg0p0ipCI7ZWShHxpqmv2bXo6O3sWoguuHdGo2/NOGZ4jzMfgHvuMFpGpTsyrc9qLORvadJvgJnGquLxtCe1IO2TiFycFDTcLrS+e4VhRzuIKa9w3nUJ2PNvWbas/BqXEdnTg215my2iLFq6pgWRB65ewEAz6PwoEQMag0mxVmz9l7AWxXk/VPJOg4rN691W5ES09FQQz/UiJgWPzvxrUhhf4JvS5TnrZV1s4WkODKoCQxgeEuyJmF8RhK62gPhL1ucsOxtq5q4ysNRs4tEUHmefa9UUKADoffKvKjk/B92q3bROf6jfVAJMsLqqNHkv2wS1XnO1+H0KgyNqJ2lTMVqe+8ZSHSJosaD2WmgqHjBSf+6l4vK6qUZAAzmDAAc89BejJAClAHY7Ai1oN+tE2Ri5/XAxCFMk8XJDNPr8Yjq6r6JzC8X6PP6qT7aZ6uiC6ufKOU38Yqq++8PLamy8KSomW64dclNhGG0PmI/ROVe1/6+HiNsgq1NYunkTH+Qn4+IfiDsSTN2ztjEqAnp9R6DWbLQLlNH/EfJ383rCkANSt03HzZLat2YKf/60JXRDUN+MVFoG8rEwEECiacmmvqrmgGEAHFMWeDNNgZZ4SFw+Z/SlUD9MdT398fg2LbVWfOPTwGOsH6bBunvax5sirzGCx X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ba463ba2-4f3a-4539-4f23-08db6e9c4cbb X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:58.5860 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: y1OO0dJaTEJ66dkyxY9MszZL5cpEeyboyhRSQ2LdWC0XBhepzsQfcyVtezJyVgBT X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5912 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120323_032210_FC4979AA X-CRM114-Status: GOOD ( 27.10 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org I've avoided doing this because there is no way to make this happen without an intrusion into the core code. Up till now this has avoided needing the core code's probe path with some hackery - but now that default domains are becoming mandatory it is unavoidable. The core probe path must be run to set the default_domain, only it can do it. Without a default domain iommufd can't use the group. Make it so that iommufd selftest can create a real iommu driver and bind it only to is own private bus. Add iommu_device_register_bus() as a core code helper to make this possible. It simply sets the right pointers and registers the notifier block. The mock driver then works like any normal driver should, with probe triggered by the bus ops When the bus->iommu_ops stuff is fully unwound we can probably do better here and remove this special case. Remove set_platform_dma_ops from selftest and make it use a BLOCKED default domain. Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu-priv.h | 16 +++ drivers/iommu/iommu.c | 43 ++++++++ drivers/iommu/iommufd/iommufd_private.h | 5 +- drivers/iommu/iommufd/main.c | 8 +- drivers/iommu/iommufd/selftest.c | 141 +++++++++++++----------- 5 files changed, 144 insertions(+), 69 deletions(-) create mode 100644 drivers/iommu/iommu-priv.h diff --git a/drivers/iommu/iommu-priv.h b/drivers/iommu/iommu-priv.h new file mode 100644 index 00000000000000..1cbc04b9cf7297 --- /dev/null +++ b/drivers/iommu/iommu-priv.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. + */ +#ifndef __IOMMU_PRIV_H +#define __IOMMU_PRIV_H + +#include + +int iommu_device_register_bus(struct iommu_device *iommu, + const struct iommu_ops *ops, struct bus_type *bus, + struct notifier_block *nb); +void iommu_device_unregister_bus(struct iommu_device *iommu, + struct bus_type *bus, + struct notifier_block *nb); + +#endif diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 7ca70e2a3f51e9..a3a4d004767b4d 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -36,6 +36,7 @@ #include "dma-iommu.h" #include "iommu-sva.h" +#include "iommu-priv.h" static struct kset *iommu_group_kset; static DEFINE_IDA(iommu_group_ida); @@ -287,6 +288,48 @@ void iommu_device_unregister(struct iommu_device *iommu) } EXPORT_SYMBOL_GPL(iommu_device_unregister); +#if IS_ENABLED(CONFIG_IOMMUFD_TEST) +void iommu_device_unregister_bus(struct iommu_device *iommu, + struct bus_type *bus, + struct notifier_block *nb) +{ + bus_unregister_notifier(bus, nb); + iommu_device_unregister(iommu); +} +EXPORT_SYMBOL_GPL(iommu_device_unregister_bus); + +/* + * Register an iommu driver against a single bus. This is only used by iommufd + * selftest to create a mock iommu driver. The caller must provide + * some memory to hold a notifier_block. + */ +int iommu_device_register_bus(struct iommu_device *iommu, + const struct iommu_ops *ops, struct bus_type *bus, + struct notifier_block *nb) +{ + int err; + + iommu->ops = ops; + nb->notifier_call = iommu_bus_notifier; + err = bus_register_notifier(bus, nb); + if (err) + return err; + + spin_lock(&iommu_device_lock); + list_add_tail(&iommu->list, &iommu_device_list); + spin_unlock(&iommu_device_lock); + + bus->iommu_ops = ops; + err = bus_iommu_probe(bus); + if (err) { + iommu_device_unregister_bus(iommu, bus, nb); + return err; + } + return 0; +} +EXPORT_SYMBOL_GPL(iommu_device_register_bus); +#endif + static struct dev_iommu *dev_iommu_get(struct device *dev) { struct dev_iommu *param = dev->iommu; diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index b38e67d1988bdb..368f66c63a239a 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -303,7 +303,7 @@ extern size_t iommufd_test_memory_limit; void iommufd_test_syz_conv_iova_id(struct iommufd_ucmd *ucmd, unsigned int ioas_id, u64 *iova, u32 *flags); bool iommufd_should_fail(void); -void __init iommufd_test_init(void); +int __init iommufd_test_init(void); void iommufd_test_exit(void); bool iommufd_selftest_is_mock_dev(struct device *dev); #else @@ -316,8 +316,9 @@ static inline bool iommufd_should_fail(void) { return false; } -static inline void __init iommufd_test_init(void) +static inline int __init iommufd_test_init(void) { + return 0; } static inline void iommufd_test_exit(void) { diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c index 3fbe636c3d8a69..042d45cc0b1c0d 100644 --- a/drivers/iommu/iommufd/main.c +++ b/drivers/iommu/iommufd/main.c @@ -437,8 +437,14 @@ static int __init iommufd_init(void) if (ret) goto err_misc; } - iommufd_test_init(); + ret = iommufd_test_init(); + if (ret) + goto err_vfio_misc; return 0; + +err_vfio_misc: + if (IS_ENABLED(CONFIG_IOMMUFD_VFIO_CONTAINER)) + misc_deregister(&vfio_misc_dev); err_misc: misc_deregister(&iommu_misc_dev); return ret; diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index 74c2076105d486..5433c9c545526d 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -9,14 +9,17 @@ #include #include #include +#include #include +#include "../iommu-priv.h" #include "io_pagetable.h" #include "iommufd_private.h" #include "iommufd_test.h" static DECLARE_FAULT_ATTR(fail_iommufd); static struct dentry *dbgfs_root; +static struct platform_device *selftest_iommu_dev; size_t iommufd_test_memory_limit = 65536; @@ -108,10 +111,6 @@ struct selftest_obj { }; }; -static void mock_domain_blocking_free(struct iommu_domain *domain) -{ -} - static int mock_domain_nop_attach(struct iommu_domain *domain, struct device *dev) { @@ -119,7 +118,6 @@ static int mock_domain_nop_attach(struct iommu_domain *domain, } static const struct iommu_domain_ops mock_blocking_ops = { - .free = mock_domain_blocking_free, .attach_dev = mock_domain_nop_attach, }; @@ -268,20 +266,26 @@ static bool mock_domain_capable(struct device *dev, enum iommu_cap cap) return cap == IOMMU_CAP_CACHE_COHERENCY; } -static void mock_domain_set_plaform_dma_ops(struct device *dev) +static struct iommu_device mock_iommu_device = { +}; + +static struct iommu_device *mock_probe_device(struct device *dev) { - /* - * mock doesn't setup default domains because we can't hook into the - * normal probe path - */ + return &mock_iommu_device; } static const struct iommu_ops mock_ops = { + /* + * IOMMU_DOMAIN_BLOCKED cannot be returned from def_domain_type() + * because it is zero. + */ + .default_domain = &mock_blocking_domain, .owner = THIS_MODULE, .pgsize_bitmap = MOCK_IO_PAGE_SIZE, .domain_alloc = mock_domain_alloc, .capable = mock_domain_capable, - .set_platform_dma_ops = mock_domain_set_plaform_dma_ops, + .device_group = generic_device_group, + .probe_device = mock_probe_device, .default_domain_ops = &(struct iommu_domain_ops){ .free = mock_domain_free, @@ -292,10 +296,6 @@ static const struct iommu_ops mock_ops = { }, }; -static struct iommu_device mock_iommu_device = { - .ops = &mock_ops, -}; - static inline struct iommufd_hw_pagetable * get_md_pagetable(struct iommufd_ucmd *ucmd, u32 mockpt_id, struct mock_iommu_domain **mock) @@ -316,22 +316,29 @@ get_md_pagetable(struct iommufd_ucmd *ucmd, u32 mockpt_id, return hwpt; } -static struct bus_type iommufd_mock_bus_type = { - .name = "iommufd_mock", - .iommu_ops = &mock_ops, +struct mock_bus_type { + struct bus_type bus; + struct notifier_block nb; }; +static struct mock_bus_type iommufd_mock_bus_type = { + .bus = { + .name = "iommufd_mock", + }, +}; + +static atomic_t mock_dev_num; + static void mock_dev_release(struct device *dev) { struct mock_dev *mdev = container_of(dev, struct mock_dev, dev); + atomic_dec(&mock_dev_num); kfree(mdev); } static struct mock_dev *mock_dev_create(void) { - struct iommu_group *iommu_group; - struct dev_iommu *dev_iommu; struct mock_dev *mdev; int rc; @@ -341,51 +348,18 @@ static struct mock_dev *mock_dev_create(void) device_initialize(&mdev->dev); mdev->dev.release = mock_dev_release; - mdev->dev.bus = &iommufd_mock_bus_type; - - iommu_group = iommu_group_alloc(); - if (IS_ERR(iommu_group)) { - rc = PTR_ERR(iommu_group); - goto err_put; - } + mdev->dev.bus = &iommufd_mock_bus_type.bus; rc = dev_set_name(&mdev->dev, "iommufd_mock%u", - iommu_group_id(iommu_group)); + atomic_inc_return(&mock_dev_num)); if (rc) - goto err_group; - - /* - * The iommu core has no way to associate a single device with an iommu - * driver (heck currently it can't even support two iommu_drivers - * registering). Hack it together with an open coded dev_iommu_get(). - * Notice that the normal notifier triggered iommu release process also - * does not work here because this bus is not in iommu_buses. - */ - mdev->dev.iommu = kzalloc(sizeof(*dev_iommu), GFP_KERNEL); - if (!mdev->dev.iommu) { - rc = -ENOMEM; - goto err_group; - } - mutex_init(&mdev->dev.iommu->lock); - mdev->dev.iommu->iommu_dev = &mock_iommu_device; + goto err_put; rc = device_add(&mdev->dev); if (rc) - goto err_dev_iommu; - - rc = iommu_group_add_device(iommu_group, &mdev->dev); - if (rc) - goto err_del; - iommu_group_put(iommu_group); + goto err_put; return mdev; -err_del: - device_del(&mdev->dev); -err_dev_iommu: - kfree(mdev->dev.iommu); - mdev->dev.iommu = NULL; -err_group: - iommu_group_put(iommu_group); err_put: put_device(&mdev->dev); return ERR_PTR(rc); @@ -393,11 +367,7 @@ static struct mock_dev *mock_dev_create(void) static void mock_dev_destroy(struct mock_dev *mdev) { - iommu_group_remove_device(&mdev->dev); - device_del(&mdev->dev); - kfree(mdev->dev.iommu); - mdev->dev.iommu = NULL; - put_device(&mdev->dev); + device_unregister(&mdev->dev); } bool iommufd_selftest_is_mock_dev(struct device *dev) @@ -443,9 +413,14 @@ static int iommufd_test_mock_domain(struct iommufd_ucmd *ucmd, /* Userspace must destroy the device_id to destroy the object */ cmd->mock_domain.out_hwpt_id = pt_id; cmd->mock_domain.out_stdev_id = sobj->obj.id; + rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd)); + if (rc) + goto out_detach; iommufd_object_finalize(ucmd->ictx, &sobj->obj); - return iommufd_ucmd_respond(ucmd, sizeof(*cmd)); + return 0; +out_detach: + iommufd_device_detach(idev); out_unbind: iommufd_device_unbind(idev); out_mdev: @@ -992,15 +967,49 @@ bool iommufd_should_fail(void) return should_fail(&fail_iommufd, 1); } -void __init iommufd_test_init(void) +int __init iommufd_test_init(void) { + struct platform_device_info pdevinfo = { + .name = "iommufd_selftest_iommu", + }; + int rc; + dbgfs_root = fault_create_debugfs_attr("fail_iommufd", NULL, &fail_iommufd); - WARN_ON(bus_register(&iommufd_mock_bus_type)); + + selftest_iommu_dev = platform_device_register_full(&pdevinfo); + if (IS_ERR(selftest_iommu_dev)) { + rc = PTR_ERR(selftest_iommu_dev); + goto err_dbgfs; + } + + rc = bus_register(&iommufd_mock_bus_type.bus); + if (rc) + goto err_platform; + + mock_iommu_device.dev = &selftest_iommu_dev->dev; + rc = iommu_device_register_bus(&mock_iommu_device, &mock_ops, + &iommufd_mock_bus_type.bus, + &iommufd_mock_bus_type.nb); + if (rc) + goto err_bus; + return 0; + +err_bus: + bus_unregister(&iommufd_mock_bus_type.bus); +err_platform: + platform_device_del(selftest_iommu_dev); +err_dbgfs: + debugfs_remove_recursive(dbgfs_root); + return rc; } void iommufd_test_exit(void) { + iommu_device_unregister_bus(&mock_iommu_device, + &iommufd_mock_bus_type.bus, + &iommufd_mock_bus_type.nb); + bus_unregister(&iommufd_mock_bus_type.bus); + platform_device_del(selftest_iommu_dev); debugfs_remove_recursive(dbgfs_root); - bus_unregister(&iommufd_mock_bus_type); } From patchwork Fri Jun 16 19:02:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283214 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 47CAFEB64DA for ; Fri, 16 Jun 2023 19:06:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WcjCXUzpDPgiTSsmVNM9G+f5f4ngYrQ5ArJun9C7RUc=; b=4vfmMbNEl+pLnA 0pGQvjVpwZzzTrxqO/b1mbkprx5f6VfHU4POjcrOcqxJUklmUSn9dOE2boFRxttKSf2kI8PPOYAAq QWghISp5dXQZ4QuVALs025ZhHe2YxdRSAzN0nStBmP9eSxnlo3LDDPZrlL82mmY3D/h1k0foz2oDo xU7euELZPylaLKi6j1QXcTgnUvbGuH+Tv+iKNtH9IEMgdjQPv7CNpcbOj3hQC6d/LSBPrtqNmcQML Bh+qknZWw31TZTItszQxmyRVHCGwjZeno6cmlMlLZCpO6fgUK89TCWLDIZZzCGz3/KqPG0uk+I/u+ Fg2TqP8o+NrA8EMXUOzw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAEm1-001ZxN-12; Fri, 16 Jun 2023 19:06:17 +0000 Received: from mail-bn7nam10on2062f.outbound.protection.outlook.com ([2a01:111:f400:7e8a::62f] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEjA-001X1S-06; Fri, 16 Jun 2023 19:03:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jOGTSeC8zYJr1DmwPNIXYySV1Av3/kUire3d9F6Qp7+fyQKcZRVWOsNbITzd7fLQuHEdnDgSU9LXxhmAP3kVLNEUbgqS5wIGpdK6Dp0h3t4iDLH8OkDT7ekMs7s1T6F7R9HuDH2CPOS0objRCoVNQcgiEt/wxIG+ITEijs82UhMV9Odcaz9ntsYLo2znFBNOda2E/o8duE2SRjAQ/TRWStqZsbT08iF8o12yKEC7hRac7Gj7MZdqP4AyUZHiEgk4aijzCESSCKP0Y/Gp9jBggLkQdMarL5fxG8/0URdzexTcK1eM4VONwh5Ay/1F2iQIf3sRqNA9wxYlSNOMYKSfhw== 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=YUJcfpNdGV7lboIiAgPA0VpwiRBsj+xi4myndKO42wo=; b=aTGcU7Sir9Mw7scqV8HGJ2A/e7a+ilz5ehuENd4bsB6uLee+1i6juXpFpBQWSFBLDV4sVfS0BUTbIKVU15VH5hXsrTibmrZIgDWIhNqN7D59cPUDnAYQmd+O8uA1M1ftcUFF34bUb9NaoEbEJUNg8mEqUWoZeK70x2tWFUzIz8IxJzKQCpWxJx918pgZPpXiBiG4Ng6PCztxij0DcSoSdLcxcnogOr0oXL1Eib1/CWgm94smQZceO01KcoZt5o1F2yYtvi7Jd5huFYV+2C67Q+o/Ou5lONN5ZNZcTPIZx7cjWxG0g6oaxFwPzlYztZPAexUnJ7zXNpo0ENWDCDW/Mg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=YUJcfpNdGV7lboIiAgPA0VpwiRBsj+xi4myndKO42wo=; b=NVxJS5IgZYCe1/L5WPip+HpLA1fY0Ki/1OENoQMg4vIhMUqAojuAjId4BG0BsIN0Ojg8Mo3JHir1X/EDvvdosVvYhXK37/uFRRVmsz+HERbaXEBkmHFLBUPevOCcDEj0HHmkXSMFdKNu+LiEJ/dUJzaAfWveyy6Ur44BOqI2iNfMOpffCB445m8AWhZrJ4KK2bwmr3WZc9Q/TqVJsjdnn8VcVnWNR0zgnoT4JLH4qs59e6KSIWQW+lzlk47+CqQhaJcXKCfkpLBAui4200A6Bw90RD/gQo2WPTfXRH0+8nigNN0ZWKgsDZ0hBVvH5nJALTbfzNdu6EY9sOPFl++N+A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:03:07 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:03:07 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 16/25] iommu: Remove ops->set_platform_dma_ops() Date: Fri, 16 Jun 2023 16:02:45 -0300 Message-Id: <16-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR20CA0059.namprd20.prod.outlook.com (2603:10b6:208:235::28) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: c3dfd829-b06b-4b5f-d7a3-08db6e9c4bf7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7XIf1xelxTdYWj1/dWcgz6FKGekMpXycQgbqA/1LvgL88CRridsQMPQCHYLGqldq9jHpNM9sRkXFVlcAA4k2uz0G9ovtg49Sk+NrtWUU4POYEhUAAET57TIrmp0A0OV0U+dvTT34loAF2+xJ5LmonSYygDJEM/vkqDYVkO55nSTFciVwdZJaC54DFYzM0Wk2OLkaQUgIdsqGlx25ZeDqaXZTTG02MTd95J2iJr74+WIP/Z2Ekt8xytIs3EqedM6BmvqCO6PGTIfaNpWoiVWbXSJXAWUAhsmpO4FeU1+Mtw4PC57WcjD3oa2BNND4t8Uwh2jRPVVRMef6gKmOO4xjfM03wxvunbp498A1nZ1eveQcVmeZgCM3frSTf/ED6bqsbB+xnrH2L8D1MZ/AKqtaEhp9gRy5VBoVBNhaZ3KMoaShCJU0TK7RSgX6pW3yyy8LNSQHBEduESN/eeVYf1giIIXqU6Lr8pTv/XZ2ev4Bl5twPWan7cRDbAEJeTQpcQyabSlR/uPSHzNFoW3kLfI6Hn4/BZk9RvdvY3r66U/rsJDxihpdyoukBNYjgUIQcy52xSC9wrURwcyJCq5V238B08C93bZzsEJDzbHOiemzByY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 984Whq2DXQLXIvf6/pyvp6EInUv/wNOQlmq6+2le9ysGYbQpMzaENGR8AKdmDbDvbuJf+vP812OfLWu3CW6Ho+z3uSu2Zdp4FXn4SIJ6MdOUVKBgsCtWyYKAuJAxGBzQ3IPaglysIl55REYURDErgT2UW/rxU8J4NXXIHs91zu7Bapq5BkuCA5eByqxEHByNA6bmSwk7VtPTFGzhfxIPdvvAPV/gmSOVwpEREiJ2YKNorhwzzYl2hfhznBmVGrRwtuoe2mO8t+u1PBUXPi0Fbm2iVKZ1YSP2O83YLNNSNlzndMzDlq1oRNoJcp8N0micqT/N9axdRk/L0sMdQkaeorla2FO8wO5eobBu8jOyQKkkbVvlOtoyLBSC0Ta94W1gtI9Edctf8z+vbqczcOXIruDdCYm3bv03kxsIxvEQv5QXimHW/VYbQsw0n091cMh8hmk9nzIQDBgjvGQaRgpngFpTd0HwFr2ggMo+hDIzXpfJLiIF35/e6JxzMc+QVVd0Hx40YXAmUVQCjKHApqpNjjUxr3qYA99F/aWLoDNFopDOAM1h2Bd3d042z2UDN+shVGJepJDh+Lwrqdo+kJkBB2oRJDY2hKQyLGAA3i9/37ytFlLHjNFUsYkKb1TFiGt0kJZkrTgtJyu6ql/ckaQoEoT+3o9PYUA1tLa48Q7pRFPiDoyCD7yFgADqMD/RUTTS/wvrLvn+DHTaa1ZM/NLHYvLeNIvvQj0Cyj4DaK44wOu+ZdJEQq56BlgJTGN6L1CaBufzV0pbJbT/+wbJcJ++4IzVbhFg6wWV0gqousIqYG4zIZ7dqy75zhM49AYjKmzc2z74UleKYvODSQWAHK3ArWA0izaC0ZTnZu1YezzzAM7lLiyD7Cvk7b+IJKjDpxsxknCTRX5ksuT7WZbqWBmZPDK3x0A6gvWAf1m9LekEzmPyw3GR4sr8BR6GS9klfeNZ8vzUSvAmVmsOmVmhl0zdX49R/7YE2V4hhiZLIBBLR497OycipJS76jEciL4YQr3sNR3v0lEDVPGU+ZnaMB/tgr1EUGkOH2KKU8TOf572MUG5vQwIthlymgcEcV9sJs86mB4gkXSoef9ZQB+aobV3KEakqQCzteOUY89p1np7/XISx7YKCOLBw1wK7gv9BEtr8uJa9xjIC1ilgSbis8lUKoNJ5Ug0mRKDF7yYRKTdcyb2Sk58c8meLiIJSSrzZIz+25KDVaF9eMiuMdgS5kI/ReGYlzZqb7XrdvEXpa9MsuFJZv8XmLfen0NBfQ4kYXeE7yDzNfnoSrkpwLHhONyA0klFveizot6Pl0arkGIZsZqeOtN+jxLtPZezJDIcOzYLfvaSwLAwYCMTyQEqJEd1/Ht74tnJ0kJTOg+lBZpVJr0q7UFSyuF/al5Wi+RUliXvu4offMuK3AeXJsyX1Y6eMkxMPabbVxecQqs1LAutq0mcTNLk0iueXE/o+KVRLZBNkLOIIlRq+T6dmyOmrLVWPZB9haH0kYNPocezYULl5UeI+NJCpRv9JsJKzdTpL5waKEvbS3lllvVA4E1eER7o5XDZAuiwZRf+qOIy5Xk/9l5DMaPWmUveqfYCYgKdrFP8 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c3dfd829-b06b-4b5f-d7a3-08db6e9c4bf7 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:57.3081 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nA8v8CV9CqPbTmeiggylA/33KWUmWZM/vyF5+NgIRDSD2H3sV0HLArq7wcLLhN2T X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120320_131267_D9E250C1 X-CRM114-Status: GOOD ( 20.69 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org All drivers are now using IDENTITY or PLATFORM domains for what this did, we can remove it now. It is no longer possible to attach to a NULL domain. Tested-by: Heiko Stuebner Tested-by: Niklas Schnelle Tested-by: Steven Price Tested-by: Marek Szyprowski Tested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 30 +++++------------------------- include/linux/iommu.h | 4 ---- 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index a3a4d004767b4d..e60640f6ccb625 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2250,21 +2250,8 @@ static int __iommu_group_set_domain_internal(struct iommu_group *group, if (group->domain == new_domain) return 0; - /* - * New drivers should support default domains, so set_platform_dma() - * op will never be called. Otherwise the NULL domain represents some - * platform specific behavior. - */ - if (!new_domain) { - for_each_group_device(group, gdev) { - const struct iommu_ops *ops = dev_iommu_ops(gdev->dev); - - if (!WARN_ON(!ops->set_platform_dma_ops)) - ops->set_platform_dma_ops(gdev->dev); - } - group->domain = NULL; - return 0; - } + if (WARN_ON(!new_domain)) + return -EINVAL; /* * Changing the domain is done by calling attach_dev() on the new @@ -2300,19 +2287,15 @@ static int __iommu_group_set_domain_internal(struct iommu_group *group, */ last_gdev = gdev; for_each_group_device(group, gdev) { - const struct iommu_ops *ops = dev_iommu_ops(gdev->dev); - /* - * If set_platform_dma_ops is not present a NULL domain can - * happen only for first probe, in which case we leave - * group->domain as NULL and let release clean everything up. + * A NULL domain can happen only for first probe, in which case + * we leave group->domain as NULL and let release clean + * everything up. */ if (group->domain) WARN_ON(__iommu_device_set_domain( group, gdev->dev, group->domain, IOMMU_SET_DOMAIN_MUST_SUCCEED)); - else if (ops->set_platform_dma_ops) - ops->set_platform_dma_ops(gdev->dev); if (gdev == last_gdev) break; } @@ -2926,9 +2909,6 @@ static int iommu_setup_default_domain(struct iommu_group *group, /* * There are still some drivers which don't support default domains, so * we ignore the failure and leave group->default_domain NULL. - * - * We assume that the iommu driver starts up the device in - * 'set_platform_dma_ops' mode if it does not support default domains. */ dom = iommu_group_alloc_default_domain(group, req_type); if (!dom) { diff --git a/include/linux/iommu.h b/include/linux/iommu.h index ef0a0000f09326..49331573f1d1f5 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -237,9 +237,6 @@ struct iommu_iotlb_gather { * @release_device: Remove device from iommu driver handling * @probe_finalize: Do final setup work after the device is added to an IOMMU * group and attached to the groups domain - * @set_platform_dma_ops: Returning control back to the platform DMA ops. This op - * is to support old IOMMU drivers, new drivers should use - * default domains, and the common IOMMU DMA ops. * @device_group: find iommu group for a particular device * @get_resv_regions: Request list of reserved regions for a device * @of_xlate: add OF master IDs to iommu grouping @@ -271,7 +268,6 @@ struct iommu_ops { struct iommu_device *(*probe_device)(struct device *dev); void (*release_device)(struct device *dev); void (*probe_finalize)(struct device *dev); - void (*set_platform_dma_ops)(struct device *dev); struct iommu_group *(*device_group)(struct device *dev); /* Request/Free a list of reserved regions for a device */ From patchwork Fri Jun 16 19:02:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283120 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4AAE0C001DC for ; Fri, 16 Jun 2023 19:04:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Ch3k2FxlXgq1/QU7n1mjYa2tH4Q8G14icGwJYxdedN4=; b=JOZ66ciZ14XiD6 hMlgSPfdGJIqV9RTvxJyMJfVkhVaY17hxVL+JsbKA9npnlZ9zS3IH9qHtw4RjJlPfXNGrLKDcVNVv TAuTSh9UD7TeXfGj3HurGVC36h5OVimp6g+WnjO4DC+gmgxByRFupddqH0CDATVn7gw/9wNGS8I5P ANYSxyc4xqFrM0P+izeZD2HVm1ZzRmcXW3FSei+WIiO1YrfxiVSN09BG0SUR2d2RppBk87Tl5sPa+ raS4rxnJ8+W/NKgjMNOpKi0VJQt2+R9S751I270xfvaAg2QTfpalp3IiPoAGFtx9HXKvs3CdAMjkH E++lI55e6zukKibpadEg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAEji-001Xri-1v; Fri, 16 Jun 2023 19:03:54 +0000 Received: from mail-bn7nam10on2062f.outbound.protection.outlook.com ([2a01:111:f400:7e8a::62f] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEiw-001X1S-0g; Fri, 16 Jun 2023 19:03:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lgOTRIFmaQWbuvdM+Yv2hcPi4DGkWUBqiQFysiw3G9FLN+4MuCWGhfJrANLpOgjlF/lHymaITwOfHL+SukChyYQyW8Bbyg1+7Ro/e75cXR57SQOkl0eZ//T1mbG45hG5ovn7H0T6EOwlzfwYNFZT9kPBCy5+dzhzp9k22FkHqStdKykuxMm6ApKjzgeaKY0yshvXpInnRXIFNt7qnVZeYGqcvqxvqHhxob4993r7tJuyG0tIcerWKCXN0eJBeB3a6/wxiV/z8UIRXT8H7caQ3hDUWQ1MsbCHP4tHcc67OWL1O5NjO1ndD/b0+BGqQmv1vrOBLceiTQoAS2X7HAes0A== 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=JplaZHxMiUJROKD+qTnd9x2wQ0YQIobZhUNJsZ+z69o=; b=TslVR7pJ2gqGuj8PMNq8nzTuWaEIG9qlmU60ON/1qQB+JnpzHjCDk/GEw7ll87IS2YXa3c/dt7sMWsNTcscYK2BlmdpOacR2cG5lD7oujC/pZ9mc0shxpZHuFJCiqOEovNfws5Wd7HUQCt2c6Uh2dJcKPbnZLXF6tnnE3sekZfDiwmnzR6F6ti29UAURwghdCk2c3S1puxoPc6CKZIUsMuirRhGrXEYQS/blDIZDWWmP3e0oOe/WrQeRfNnQOVNBmDh4CJUhK0RgzNTyEs8qSJV3tMxPqGYI4HJrNpBjuYIy4Idf9Ccz1vmxYWg5pxykL31+Z0Ujp0JXwwJt3M0Eog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=JplaZHxMiUJROKD+qTnd9x2wQ0YQIobZhUNJsZ+z69o=; b=QRznYFwus6PCopc1qnLso6vsRVDhssJbrFoBW7BcqUCDCzuckUeiOB6L25c40gDQFpn0GfDsQ2WZnrvhh3MTPZgsqiKUvUQ8GO3mFfsXtMcasLobE005KyV5yzsRBl2SPpFIqLvy/ayaLRh/TwohOU8zJD7lsudaPMzMYVbipC2XetNPxThWe9+xD4O7vAQF7NHKuk2CkzKGnp6Ir6S+p33JKcnQJpKhrj2dQ4cOonbdNfvE+kNuWGdDisQJabj7QmiK9gKCzQoVdmL31+LLj3yRKiCCUtiA4Y/sUvcFCB7qyxYzr2svXF89scIRZVtCshdkscjr63bAMA73i6rVgg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:02:59 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:02:59 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 17/25] iommu/qcom_iommu: Add an IOMMU_IDENTITIY_DOMAIN Date: Fri, 16 Jun 2023 16:02:46 -0300 Message-Id: <17-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR20CA0054.namprd20.prod.outlook.com (2603:10b6:208:235::23) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: 72f61003-6088-4c58-3c5f-08db6e9c4b0e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mbpUyd5bj5mRBJ1CWromeW25uppkt8W7LHUch1TCM9X1t7OBxf/qGQSpTBF+3OvPz6djlT390zKuMA0hlWOtgnLvXRM1jFYIaP5uVXZC1hIWrrweWcZYO2MFsenSl9gbkibExeSIsj7bji3OpKOHqWdwLzC/+6IZVMnnV18Tut4qUeAyhOZhVPY5IKGEVqACNN/VfHREQ3EuFI/8B788hd6FFfgQkKdNO8r7k2oQfcj2EWh+h1spUjZZRYZ7XIsQyXf4AINFADU9c5SfUMW25SsZ862EUhURSH6fbuig3ZxPYeoJVmvwaJx4X9d/WpfpmrdGNU5ZDrQK1fWCxg2TP4H0BGV959TabkOjVyt/jPLHzISPkz3z7afXnF4LDSYfkkcanoMV65xOv49p8KcHx6+fNGmA29qvum00CpdWw66LWfmedHMmzUgMAMmuBQwhL9OvYwoZl14dweRVyxIY4zDrTLLg3o0rumyl7eVeAiMkeI0knZYfQp4lT7R2WXPtQV+fpt1s1YhtuJMqHs21AW7ohnRVWp9q0IwQilcXZVfkr//fdsyGfTsezy2PrvWSkkdq5xOqrXEhi92SIIjXzj/Xpt6Z7XmmqR4EO48Aj8E= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PKCEE4valAP33d4nw3GQMpAVppM2vKSKObW2xRijtBqlxijqMsndDNmdbPUdlS22eNSXnq98RZEXPxzSAhxENlP6A2mhltrwxWRoEOcHEykB5j1m4rkEra/0/iWOXatwnhc6v7XX17tIl2RVLgCTiUHg8QuhSQbZ6BePp6ha0l5eH/SBtAuOOhqM+w1kc9MpegqTN2NlCrbwpDJvbcMwk1isLS2yJ2zVNfut/g/bSGzIIS78USX71IcF0wS58KHUxkn5JQ0fii8Bmmh/SPVEBQwx5wfGrRtLRTiA6iJ68iDCEgCF/MN0sh3xdPptj3CfDXaEYgeQnhkccP7Y/WzkAQEkQV8acoea1p5bL+SmsfMjzETsE8nYcOEvgdKtK3820vYNgi9nPq+A7vpd2LGp+E/ErUIsGFlMirW53yAMr5EcKCn4TfW600oc4sm0KLSteclZl1qDkZ7syDywKbr48cQ3C5815IBFFFaYwUVyalYjdfBFFDklOEwRLVLByqSxgDmpfJt6fbjhQ/IngAVYjonJG1xVvc0/4YWAeDfN5u9fdffoL6FpiR4p3sbWERksqLNXJp8dFjneVgFcmk1WZMRYZCylfxTB2JJ0//dvhQWJY7p9zd55xYU88e++BT5hXHfCJCw7qzwktU37sETiIR5Vp8cAWbPGhePo4zFp7J1HOWLLtVjlC9wyrs245RNaH/Ev6jjrqkc3HEyeZrOYeKXuv721aGdLo/PZSxnzLC799Gk7GMoEOjB9XOzhr0ID25KtC0sCVYlBqsHZa/UK3fg4YKHkxWCxiSGnNG5mJEmLKlJcq4z+ZubRtsI+QFImz+G1p9gQVrzT1P0zK2Wvj5dDDO5XDQSnxcXFNUNzuY3XDRIKHxzIAE4x6XmrDQdni55jf5whh1Uq3wTdxvK4+OE9uPpmDwMdzP3cFQoHeDIt7cUdLqjRsLS78YZ8dewJixoQG5mlR16d0wARc9GqSF6N810oVXHqxcATnIj3XuIxTkwRnpG2HVIMvwqEc/502P+RAJjW4+oOk0BY6NUsosojRwDtsQw6+OP5teQnALDDIcPrNXPoVpLTr/4FHoOxxMiwdm35s5ZZzXD9A3x3fT3PUJjEpHN4+lbnWN0GOunS3ak6DjnC9LedvEHt6Uj+jplnZKcONAwfc0HTJBpyEu9pfphBmCM7/2yYRgUf+gwfuD4g2fgWKSgRLt47cj7MEBjVUwEl+x3mTeUDk1/Tzd/4sm6StFLwKXMw5RNMSTIhJbJxBOAO//17hcOJjziewN70khosBFubFxzDZwIDJKECi0kiKVb1ZhEIsOZal3wuZm6uq1Lz/LcDP3+5dAnJo/Y4ICDyulCqp7Dt33TnXQIyJa4fAssfdwf1iAiDrZ9WS1lds+uYmTC14QkIWYVWtIk9fCLwauMa6GjLe+LWUqjTSNTZtii/dI6ZTTSdJB+vWEDhzCjI2krjUTLuA1+64KAy5VjvpI5o3ac7WVHhrct0TwcgLZj5AKs2RLTYIbjsfWctHPbx8REINIe0RhBaUYV1QESX+N2s8I3V24FKLxtUn8vxWTGobY3jSTC6CJ3L7FcmH/A3YUfAt9nClDft X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 72f61003-6088-4c58-3c5f-08db6e9c4b0e X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:55.8024 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: it+Nk831SPDoQ4rSqGeUUoaboc6VOf4zj56+vJBJY8/zib/sdrwMxDtXeuJi31Cn X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120306_282235_C23CC96A X-CRM114-Status: GOOD ( 13.29 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org This brings back the ops->detach_dev() code that commit 1b932ceddd19 ("iommu: Remove detach_dev callbacks") deleted and turns it into an IDENTITY domain. Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c index a503ed758ec302..9d7b9d8b4386d4 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -387,6 +387,44 @@ static int qcom_iommu_attach_dev(struct iommu_domain *domain, struct device *dev return 0; } +static int qcom_iommu_identity_attach(struct iommu_domain *identity_domain, + struct device *dev) +{ + struct iommu_domain *domain = iommu_get_domain_for_dev(dev); + struct qcom_iommu_domain *qcom_domain; + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + struct qcom_iommu_dev *qcom_iommu = to_iommu(dev); + unsigned int i; + + if (domain == identity_domain || !domain) + return 0; + + qcom_domain = to_qcom_iommu_domain(domain); + if (WARN_ON(!qcom_domain->iommu)) + return -EINVAL; + + pm_runtime_get_sync(qcom_iommu->dev); + for (i = 0; i < fwspec->num_ids; i++) { + struct qcom_iommu_ctx *ctx = to_ctx(qcom_domain, fwspec->ids[i]); + + /* Disable the context bank: */ + iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0); + + ctx->domain = NULL; + } + pm_runtime_put_sync(qcom_iommu->dev); + return 0; +} + +static struct iommu_domain_ops qcom_iommu_identity_ops = { + .attach_dev = qcom_iommu_identity_attach, +}; + +static struct iommu_domain qcom_iommu_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &qcom_iommu_identity_ops, +}; + static int qcom_iommu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t pgsize, size_t pgcount, int prot, gfp_t gfp, size_t *mapped) @@ -553,6 +591,7 @@ static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) } static const struct iommu_ops qcom_iommu_ops = { + .identity_domain = &qcom_iommu_identity_domain, .capable = qcom_iommu_capable, .domain_alloc = qcom_iommu_domain_alloc, .probe_device = qcom_iommu_probe_device, From patchwork Fri Jun 16 19:02:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283130 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9D886EB64DA for ; Fri, 16 Jun 2023 19:05:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=W2FGB9mAgRTJ9kPxBEzNQFmtX1f17qKZQn76RdoZyEw=; b=04oDnSd9jLRWgf kKCegLV+gc46KJXelPVD2HIAuwoMwLGGDLJ6Y2dwnRGd8iQu9ofp3H6l50xyq687m8hWNZJgcJUJo VXqeFeiP0W47xiCIs+nKHZ9Ezpwnvru1iAQsZz4liPMOskqEOx7xjJ+GhAQZr4pEerYauMsdexpJq VDAZj0dTqYKnNxDeyc0cak3DnnrjFBVdnrAaZQ7k64+6P5j7I1Ll7h14i3/JvjhpqW+V/IsJjKkyd F8pdrEVD5aeelkoYcBl4cvq2GoLiLPt9oPu+K34jI86eNvKGm0X8Xl03Ap41dfh4qY+wYVIW6Hr9T AETt3EvhRG10gmfOACvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAElN-001ZLc-29; Fri, 16 Jun 2023 19:05:37 +0000 Received: from mail-bn7nam10on2062f.outbound.protection.outlook.com ([2a01:111:f400:7e8a::62f] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEj4-001X1S-36; Fri, 16 Jun 2023 19:03:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bD0zS4K2sVuyELWL3hRonA2MHNgWezjEQSxmDwmjmv+berYiVbLikiW7pPYMO3vT78bzs6yS/+ftytBfz6fxoqa3jjGioteUINZZV3gm+GblFxbEHFUQ3p2BQ/yT8VFWBsnbsUrHeKwE1I9tDKUgvu8U8I7x9pIZmI3gSZT8+a/x0vPnpDkJEQtNbRoF7p7iR/vjv284Ap8icfjfN/wCOuHDopeYA/UywB5A0VYPP3bhKULPZQJuljn/qydHtiEhBBuL8SK74c9fI5GkOIyKcL5vxQHpxjuoqR7qVJA7ZPy8hQrPeB6Z9K9il5Eb/rh9Xz1TI8gS7oul1iWvXfJw7g== 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=EMhb/bqTdUCpbXJCspFn2zl/ilrxq2bDon6W8QDV/+g=; b=blZFmr6lfF2wHhhQ5jeqim4fOgEVmjHJtOOIr2hxOvjEa36DJA1C+sBtdf46iGRZg1FVG0b0d6nfP2u87qAL9gBFXqmkBUZVp9xX+g01/EtMmFMugnVusVpRZdB+w7zGdKOcaLLx4Wy9TnVNISiSaDNknEXz+OMxhh4P0jq2U1nAGz19pC7INb5jbqj2UCUJKTjrSe7dZ9myN4wDw+Pl1TaqlUiLXJLUhtGXVBIsujIlH4czf842a2Y/1KoLMXzfuFqEQBIC0N6/CGuxzXpCVTYxA0+vrnPeS9s3S0lozc46eSVqpc8zvrCg4FPh2uyVSf2aFi67dPhtMXrB/sJh0Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=EMhb/bqTdUCpbXJCspFn2zl/ilrxq2bDon6W8QDV/+g=; b=R6I2cXDndKw+KeHvPFc7L1I619RqdH0S89sIVgR2sGLrsxTFuTae/hv+a8ksoe6Heux6UeJ0tYuDtihRf+Gjz+rOXZg/RtSUOjbOgaUN0otJ8dgN8pfwxS3DoyYeQF7xzolznRT+SaT0oFHfDea+UUKztt0voqAhYNaCPu846iPCrJLfZ4dX2GV+zN9saONiz8qhbyNfz7AZPOdO6bCdoiS8o8XyJdWfsBNEdHNXUVUuJMvtXJZ21zlp5nH7spd500ZngM2hJ63i8aobdeSS0pDi+tA3SxTE0FfyNEXWayJBy6VtZLcMqLQWI2+m6CIQ1QkZ5W/DxOim1D/K3XdDWw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:03:04 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:03:04 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 18/25] iommu/ipmmu: Add an IOMMU_IDENTITIY_DOMAIN Date: Fri, 16 Jun 2023 16:02:47 -0300 Message-Id: <18-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR20CA0066.namprd20.prod.outlook.com (2603:10b6:208:235::35) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: ed5521ff-d650-4346-696f-08db6e9c4ba4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bZn5cnTWJDJlrabgJ0rhSoyddOG9zJp3Je/B7LxGj0rOuhx+Mnt/EWb3FlHGqpNNnZfcxNmkyG4CV7mrLr5aDjPKdfJcbFW9yLjujiurECZ0bIyHvgQg/Apla7KDcRFbw29daLUgkrjOtbm5KG96XqL0ZMg5aYrnBBimKJIKdqnH79OwhF2UmT4OcbdXGi0GapHszD7F0sVcorDxY53Lg0sAbDXkqOiGdZf8bm5/0Jje0lhEY+9RUUCTr8PV6rM+E1lFVuGBcF8wmmlcXnVNnqLO29ZP5vnUAky5kah0eg/kfCZJluUd/P5EysmThedMd/qdKiKn/eT9KtNVkbk289K8xaKRt6LZI89y5JXbP4+382f+E2YsgiKFit/3X8gFnO75iLDc8w6jq9TPC3PWSmEoOkAxZYeoVyVJ8C0abyRwj4Y8Z49j+oo/xLHDyVhYcPKCyWXs91zEo0zdgFPe5S9ySLu/8FGnL4OXwLsVk7dylELywv9Sok3r/jvgQ/QQTg/Xicy+/Lvc0yPNzGr+XvNLq2MC+Xi8py/Hm6v4FbLTn0uvEoZ7/yZN4UpA6PHPFlHOHyq7uGtyypIQqy+bSI5xbip07Rt7nZJqR5jX6z4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GXD7G2z5GYJOQSMDizAjxSxIOcU68V/jvY0vZN+0OD0kMh4GvgbHYtOBLJzq8DZBKYjIYIT/xIXzZb594y9ws6FicoaC5iWtOotcLpGV704IXRCvir4JTPX0ggUy+usvs7vkF1grYa59tZ4JHu4eK259g07OwKwD5Kpm8eD4Za4M2zBx8g+H7c4r9yTKpBXvooijo6D97TMnFNc9oic0I3yjAeKeQJsUAIyRkfQZwQY+5uvrrKVL8obThTOs6JCv2nqPW0vX0EXxtaWvf1CJz0XIc7Y22/IjU162BbCb10dET0J8+6MwFehKKaKgcPyBCnG0YoeI9NOgH8qRbbas51e637L3stnY+e1x1h4ZuVf1kTuk8erzeDGT0y9f2Idfk9Uign8oV+BebLtQR84bxL8468BXTRBXIREWg6R8NHGnfI7RFWgmyFKGUcPWYF6AmjGY/i3Ma/2zVtfgeIeZXtwpAByaHsUExS/BEJ+vveEDuZTJ2GrBKAWjMwL716hnEXgq8LybyB9t+If2psZ7dnmgGVU/JadDla1e32Bq2YhZ6GnGxoJkuiFIP1+8cTCqJ+enCJDfyoIIYLBLXPk5rs5vVl6r2IZWgm6qs/Ntm52Us6pHSihg09l8ymQzKOFIGCcAI/Kvb5GXEMNj9ub0Pnylp2ClnDEPIzBlshUkj/o9zCJmIy1XuKrgW2xZNLQcrZbW/LvakRxvU+Swo0qh5sqNdIxHjSK7D3RnpxSlvauvkgTIariVNKKEcXUjiVIsb0yemSmuQiWiY9/ev06fyFh78jhnCaTCU4N8d/sf9/S1hZSFSyLHRzhRKtdC44ZzSQ6TjKcu3Uz0qYpI9ZEhVjeiqxwmSdRMfYW8GrrMyH7ySi2wLZLsMSGz3U5h5KIzXyGLeLAd2E8Zazy9FNKDgsyKWQHgAc5Pi9r1xJ3YeEOZ1zcIppbhIjaYokLEdlwnBCQ+CvTmTvNdKuGeAkpjdAo1V70mTrAK4WpMa4xk55THg4gyRCPdjRMNdV+IkojQHhpLh5EmPvPVy7XXwX5rw5LhvJcXv0/MiMxBHUc1Ho2lp5Vnyuw+tyaGwPid3bMjWUFebBeet/D6JaKnZcNrHbrlfyQdM3+W6Rc7PU/9IRsTDPXLn3nLh52yOQYsK3v+IMXI+JeK1ZyFX21v5r9m3G6NXfXBlA2M7zujWRSyXM1zQqpyEz7RJ898UvIxNAmFNDZcG4MTqK2rzYppeCv60EvWC0iPkQxL+MXO7SZ7U6tGObVXCS013da+v13cCPhFBBkanXsSVYAMKIswOSerSDB33dRV7g9eRGEKO0fgpilD8K8OHAPFQCER+fB+f91n0mx1U9sMLZz6wrnOb4bNOkgyWP1QS7ZiLjV5RCM4wAcCcGsj4St7Fs1O9rHhPbfDIHh/JHofSdPo+2hkVZF46iB5OgLlcU1azsSKjt0JnTURvgQqhZFlt0mHCRcr8ySllZwpQ1JHpD3rvoUhD7p8t3vU5Ud3WPxbpYjIHmJKUHwXIJis55GEsQP/wBEHyMb4gdmlpw/kKjJGLxzGnKITxsu4xeMdc3SQM3rzXfoM0nKBrDFkynWFscMSazWY21oo X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ed5521ff-d650-4346-696f-08db6e9c4ba4 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:56.7333 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RNuzraxebkN9dWjZ06vF/yWaQS9qiY8lvzjEKypJ/IAzbJ81unqhkIf64+3xF8Vc X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120315_030658_C74D0C56 X-CRM114-Status: GOOD ( 13.70 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org This brings back the ops->detach_dev() code that commit 1b932ceddd19 ("iommu: Remove detach_dev callbacks") deleted and turns it into an IDENTITY domain. Also reverts commit 584d334b1393 ("iommu/ipmmu-vmsa: Remove ipmmu_utlb_disable()") Signed-off-by: Jason Gunthorpe --- drivers/iommu/ipmmu-vmsa.c | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index 9f64c5c9f5b90a..de958e411a92e0 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -298,6 +298,18 @@ static void ipmmu_utlb_enable(struct ipmmu_vmsa_domain *domain, mmu->utlb_ctx[utlb] = domain->context_id; } +/* + * Disable MMU translation for the microTLB. + */ +static void ipmmu_utlb_disable(struct ipmmu_vmsa_domain *domain, + unsigned int utlb) +{ + struct ipmmu_vmsa_device *mmu = domain->mmu; + + ipmmu_imuctr_write(mmu, utlb, 0); + mmu->utlb_ctx[utlb] = IPMMU_CTX_INVALID; +} + static void ipmmu_tlb_flush_all(void *cookie) { struct ipmmu_vmsa_domain *domain = cookie; @@ -630,6 +642,36 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain, return 0; } +static int ipmmu_iommu_identity_attach(struct iommu_domain *identity_domain, + struct device *dev) +{ + struct iommu_domain *io_domain = iommu_get_domain_for_dev(dev); + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + struct ipmmu_vmsa_domain *domain; + unsigned int i; + + if (io_domain == identity_domain || !io_domain) + return 0; + + domain = to_vmsa_domain(io_domain); + for (i = 0; i < fwspec->num_ids; ++i) + ipmmu_utlb_disable(domain, fwspec->ids[i]); + + /* + * TODO: Optimize by disabling the context when no device is attached. + */ + return 0; +} + +static struct iommu_domain_ops ipmmu_iommu_identity_ops = { + .attach_dev = ipmmu_iommu_identity_attach, +}; + +static struct iommu_domain ipmmu_iommu_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &ipmmu_iommu_identity_ops, +}; + static int ipmmu_map(struct iommu_domain *io_domain, unsigned long iova, phys_addr_t paddr, size_t pgsize, size_t pgcount, int prot, gfp_t gfp, size_t *mapped) @@ -848,6 +890,7 @@ static struct iommu_group *ipmmu_find_group(struct device *dev) } static const struct iommu_ops ipmmu_ops = { + .identity_domain = &ipmmu_iommu_identity_domain, .domain_alloc = ipmmu_domain_alloc, .probe_device = ipmmu_probe_device, .release_device = ipmmu_release_device, From patchwork Fri Jun 16 19:02:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 50C5FEB64D8 for ; Fri, 16 Jun 2023 19:05:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Q296bQx110RrHongrT+O6BRtPAfviQ6TkLlcFupjNgQ=; b=4Yv+PPVr/egQLv Q5B1EMi/0TpwvTuIZC5hArUSdJfCGMPWJZKYZkBOVr5p4BTUSVOh9XRWM24xaYrxUSWDHP60k2/7A ooEjoypunin3bp0RfhYXdXrJWBJNcS2OY7xApz2BXT3ayrzsTj96+CxVnx+o9ob8Jm34gJ8msvybS 0Uc2w4lmqp8v65H7T4U7AG1pYnMmBNKxokqGYNNCI9T5gIWsYdEAvRR4jl6BYaUoNYr72nIYkGozB NhDWDr2LoJc21QFonT4FcqEW0QEtNT7yPG+mwDRKRJqznuKhzDxM374RdOunnmBHdgNctj4FzS22I GIu7NEtvSirxt6fIAXvA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAElI-001ZGY-2x; Fri, 16 Jun 2023 19:05:32 +0000 Received: from mail-bn7nam10on20620.outbound.protection.outlook.com ([2a01:111:f400:7e8a::620] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEj5-001X3y-05; Fri, 16 Jun 2023 19:03:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mE52CDJvFZIAz/pd5K7s+xgYS4v/NnhCEZZQkISLeGJfJMcs5EJvKBEwrg3JnOPcBG1x+q8IDz72C7GYmTA5xw8bvFuK5ddQPGYBeR/pG1TanFKwJtKJXk/tWUhvl+CC1DKKANHV23t8jPGRwmBLshvIyb10ny31JIjtRkCD3za6VembIdSeM5vNxVKyKu5ckwAHdZ8D66oZkfd6ah4LKinXXruTb36Hy1ZXzIptQ0nBTFehVttKKgISl55xsYCKnLO4JMnlJpMl9WZq/E7JZtqhsj+wALfhFv5Ymc+krsZ8yttUmIWADLRWt/SAATr0li8BWSv6V6t2PVKITvEw2A== 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=WKNaZwKctNyYbRBuZB+xdODMOwwW/nmEM/YaUXrFqNI=; b=kDVzaoFiNeIavXEzW4StyUy3RVxzzwq9ep71KJG06q41cfmq56qg7lsddOlrsZ9a+HiT1JntbMnjcNbJTQDxC1HhO+iF9ed4lDAVqvBtLFe3o8vlCxtkqiAMekxkccbyalyUm+fc5g9y45FzXjJr0fpjDZH0eHKCkrG8ubz3LL71XmL65w5i0BA1fd1r3Ny4B6b1K7PTWKmjsn/emvlynli5pqZQsqutDRQt7WsJ7ea/EfI3RLJI6Fgkk+80SdfSdp2HhmUo33NcTIBoCSSV0ZrUIqVo0np59i4tqerx6LoXkkw4P6LEKLVwJResEdcVbg6Y9yq6CgUS6zqXj5217w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=WKNaZwKctNyYbRBuZB+xdODMOwwW/nmEM/YaUXrFqNI=; b=k+7yPOjPZD5wesC4N6PCgL6OnzNBsCusCJllh/bWpjMVAbgEz5tO3cwMNBzqd7dC1AT8yFGFlxfKSrn6w2iqLEAJmUDWz8sCt4P9URUPHlGkNzdMCGMVIdugYCMK02ocF1GTD8GGQPPkmQdx5V3zuTS2jSFWjwQAuhHrUVVNB8BXbaCTUvxpJb+vra+ks1lcH6mfzwtMaeOfj8Jlwd25BsA5S84pJm0i3CTs34QQDFxoUM4yR+1gPkfysNI4ESbHUioUpzIookYpiL76/AVKnzotRFK7PrY9XDsVHzdM2/PLdJJ2yfqINV+FnYF/U28xsB/HXoG4/RxKApZLdwBPJw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:03:05 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:03:05 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 19/25] iommu/mtk_iommu: Add an IOMMU_IDENTITIY_DOMAIN Date: Fri, 16 Jun 2023 16:02:48 -0300 Message-Id: <19-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR20CA0061.namprd20.prod.outlook.com (2603:10b6:208:235::30) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: fb37472f-804d-4dcf-2deb-08db6e9c4ba9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mp/XKFBJdS7hVhMhwYC03AhYl6aFd+JZIqk1DZToPCnRHyrrjrZWo77eMIja7bHBNBc4VVZ202tqH4ikE8x3Fqx2maWX62h1Fy7Mu8dmkCXcZ2H3t+G9Six95RUeUQi4S3b7OwqsBOYGk1pNkxoL7xlt0o37vMWVcFcMrEwPP7R0FSPoW3bv7VD1EhkpITCTW1Dee97x6yQXsrU3YO8IGofBiBjSGQMk+kMYI3IOHJxFQf4cl5L2Bdik3xxodvHFj0FabU3+SuzJJMWg07bQqiDMI9cbczPAsM95wHShEBi86OvBYnpQmw/jFvkwGlQhkwubZWR+n5d5eNVFJd0ehB6XU2PSzKLpT3iWFwW6aoTnZEkifoHiVHe4svsn+JdStdstJGdLe21CEkyyuRNGaM9VmBO8O1GEzPeYNn/JsB1Gu4CgVfLc4lJClu3qTxhcMOkCcYp41GY8/QFbA7u6boxkhyAiFXsqwn5sXxtzjzvkC+XBJNWB91FFOx+cG1qjpKVjeRetQqU2weYJ6ENyDjxMUBtsbvGTIfb4ZqFEPRFsuTa/aZQ8T2DLf5L8ue1RvyBd8KJ/r7KB2V8T5AhIaNKqgo84KzdyzceYeqnooEE= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VgREuTnAz85QySWRSWkXTM3ufrZSDn9I/TmX730+bK54LVdhK8awSScdSu2e8jFZEFadS7OaSX2K/RI55PfZ5/R6cXX4ZAGqiRL/EmuiqRMGDvYUTZ9rRTtcRVrNVGT8Jog+IOyG03AuiGS/ok38SjHQ7qZecB0GEnERwBYwfpmvZcAmkUr2bhzmQgsgSJw6bgC4K5Bp0c2K/eLxT8wR3427EfPiVGoCkoWNtfHIkl9toNIpX8ftNfzvGiCGgykSfH17VLkHq5MoqHkDrk30l9Es8+kygAV7Ovq0idQgjlhS5BVljNora+mYYjsotrspHRD7B9wWF7p7pLePrPjYLRXJSx/zcgIPO4xzw22GiSEScu43abMiSWQkJHQCXGE5vJuMcvf3YFG/h4TfscQCEq5i+q5xU+OKXKbXvITO9kdnYjYgYn+1F3y0e+NiPG/RFRm6urqchRU3IAzZzgsQqrSbj5aHm/NErS4kt7iVQdNJKUmAIH91UEckCJFJ5N+ef/zdcZgzO2D2OiYaFuvceOESlegBrTmHkn8ecnXmz+LeYzKnJWB1DR3Yp37xvNROHw6A7ZEqITeKyfDGaYpuHvDJNDf/w2Zzx8taNmP7CZU0NDhMQyKwwvtapu3vUb4NppVybOBhxdB+ZRFntH3i8XZ30noPjlihkLU+/neeAyHNNHJ1vS/0NkRAGc1qg1ktPTQAqUHKlweSgiTGY9mG6nNC++u7y9J1g/Dtdr4BN4sCL3Unds5AvTg1N9PUWBOu/J9uTBmtn/x0WjjPFR2OiwppvFfIaan/155r2NYHsW/qAC9fy341BL5m67izzLiupehRVrZRmJXC+vRNt/iAaIE0qln2AnT2xrgWiG4PurLqQGqrT8MP5QcsxKpwlKwIjhJDlNWlXwj9gP2u64YAMTFacnTPCRybLVgtAUUN3kqdWga+6KWb8s+hLyvNuqvdmZTlRDpGisaR15LPuy6S84ll2QxJhM17ICnWGMOgWpt3tzqucXJmHrn9yRAh8+7MQSB1g4V919lZxgK7AevyKOLQT0qYSWH/gSIOmVeuziPckEWN8Dvh1Hk6X2wKxS0h2E3Wok8IlDiI2mTx8F3u4IFv3w8C9M5N80+yxvqFRkzIcYfILM7ChfduArz+6c4YbUHylknPeOfh/NL5EvbYRYP9yapsgBxN75rlQInIAsKpHpWVh7liTLvECRVuDn8GhrocXwwVKytHl2fw7W1sJ3vaI51u3LphPo7IK9TVr2s4xPrQfAQnPWPneJCVIWteLksCUg113D2u8sk5K3GErmEThG6N06aHLq/sakapFC0royfSVdoYR9wQIW4PY+AN4ragvsGN7P8FDTM8RICNRs8AQqiB25JasTcHVM+mFdDAoECdIo8QQpRH1dzQ8fSR3m29kB7knVqnyMJdegZKZhwIuTxmm1j0g2GVjO+EIVze1zU8jZsK47IWFlqX4LHiN1wDCq/UQM4LQa7HsrkDm4j/nXdpCmd9geqpMxZnRV5ReIUXLSNGFymSDwdZ7PIwpP0/vZWu6x91HpLwd7HFUsdeSOxVGI4KhnJRKpp0ZTC06ta3Q7R4LZh9dzJn85KE X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: fb37472f-804d-4dcf-2deb-08db6e9c4ba9 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:56.8417 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: WX3gc/RvHVrYAwxhQevyj2cmnVvRQyrKs2fZwZ/ITdNmUFTAhTLV3hwSopdDO97Z X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120315_140330_B8F05E72 X-CRM114-Status: GOOD ( 10.28 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org This brings back the ops->detach_dev() code that commit 1b932ceddd19 ("iommu: Remove detach_dev callbacks") deleted and turns it into an IDENTITY domain. Signed-off-by: Jason Gunthorpe --- drivers/iommu/mtk_iommu.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index e93906d6e112e8..fdb7f5162b1d64 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -753,6 +753,28 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain, return ret; } +static int mtk_iommu_identity_attach(struct iommu_domain *identity_domain, + struct device *dev) +{ + struct iommu_domain *domain = iommu_get_domain_for_dev(dev); + struct mtk_iommu_data *data = dev_iommu_priv_get(dev); + + if (domain == identity_domain || !domain) + return 0; + + mtk_iommu_config(data, dev, false, 0); + return 0; +} + +static struct iommu_domain_ops mtk_iommu_identity_ops = { + .attach_dev = mtk_iommu_identity_attach, +}; + +static struct iommu_domain mtk_iommu_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &mtk_iommu_identity_ops, +}; + static int mtk_iommu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t pgsize, size_t pgcount, int prot, gfp_t gfp, size_t *mapped) @@ -972,6 +994,7 @@ static void mtk_iommu_get_resv_regions(struct device *dev, } static const struct iommu_ops mtk_iommu_ops = { + .identity_domain = &mtk_iommu_identity_domain, .domain_alloc = mtk_iommu_domain_alloc, .probe_device = mtk_iommu_probe_device, .release_device = mtk_iommu_release_device, From patchwork Fri Jun 16 19:02:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283211 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 53DC4EB64D7 for ; Fri, 16 Jun 2023 19:06:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IlSEZSxhopeOrX2Ut8moV4uzDjmSU6y2NhGA5Bt/g7o=; b=KibuYXcZyIhXOK 5WyXflWdXHuhqBS4lDbC/0hZIObjt06MwHOaJZaS6mUnPS7Oom3ZLAuuBms3QKq+FjbeM6M0Xht94 f4Vj/6iYw6JRz02IImRYLI++AGLp2L7ZvAWs/0jz1C1PNNCl5Oxm5VeTEFBe64tCEt+8IaY6AZNgT OIHGld+Mb6uOgG/aEDCKTtdrvy0Ef8Qgse29OOtOuB8wb1/luUquUjsF5qTb/vcYLy7WTK6JEpNRE 2W4wEK6dnZDWIg4hGaIdJVP2yY7UDrbVc8xaILz4Mmm2x9ay9we7IK+pYbXn7Q7spwiR1TYQ3Q6nf KCxvHQwqeOn9duOywbVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAElx-001Zty-1d; Fri, 16 Jun 2023 19:06:13 +0000 Received: from mail-bn8nam12on20626.outbound.protection.outlook.com ([2a01:111:f400:fe5b::626] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEj9-001XAt-1b; Fri, 16 Jun 2023 19:03:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RoMbPQpahfa9+H5UtY45H3VoXuyMALMFEBfaszRiGbNR3DkF8LH9EONv8r8h/evhIhX/GK2n3TNj74K0LGDHu8YGyPB+MIX9Oy7qlLiXND4wbT7hT7j2eznKmcya+BQKITr9XaG8b4yWjmg9m2QpVNa6wFPy8vXzYMvU0YWEl7qvvxZ9TSFpIAPUAZ3KLIJWuzKcxQn1u57rrAK5RQ64ksCFqnMeYGKmv1k0vZoLTZuhyECUIW9zYrRWPMLGn+yQP8fsUihDfnvIN2l3JKv5pqba4L+syro9UPEMS7tAs+PqK75rYyFsBDWlzVyJEC4tSdwKZxWxe6TeNtgW84g5xQ== 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=ccdy4lMCVhPTXmPL2kfCI+rEpB3OgvMl4gKeFc77hkA=; b=Nl7Pl6McSj+Tlfnjnk+ySwFXSEcgrEQzA1q6qdA1tGCZGtAPlKNXyarw3gCEzpHe0tDLbK/dZ+s6b3ii9e9Pk1vqzenWzfvoWWNbRhodY8oSArU00tEyDBUbKNtbto8e5bntf/emN+MmJOVwrKV3nTc0Gb4Hw96wWa8pxSBKRfQ24Phs70ql09SaDSAD6w2qE7kOU/bfrn0VXMlTzJmyZbXTkSbeJ8YWNQYyiszwmnr3VOcyuFDhIUkMeFnCRY2jEGbCsVsvKjeMFEKfgqupCbLgWeRK+nt+fDvNA4seTCEXJkaeZ49fAgbp2/o7M43zhTpVqW3+BmcGALgkY27dMg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=ccdy4lMCVhPTXmPL2kfCI+rEpB3OgvMl4gKeFc77hkA=; b=ZCXR1QGlC5MkhYJy6DS/2UBIqH+Kpv4kVhXXv6ulVIXza9QIdvmiiR/E4mYWHtGYk+n8tfQMUYf9Fzdr8TfBiZhfUvyHG+iElEKHryWyk/u4fniavlRXww1SnMOqk0zLAIJt/dRSv8djw+IMiAo65s3PQWq2tUNtM6hTs8qAjrsmbSNVObAyA3636LT5WgRvgwVqTQ2WncR0CG3u529oQw9G8yqtWjnzPA6AMFbKvC0bNGr1dBzDhE/D8zqJZyis5EW+sMr2H3KEiHmqDFD123IxsqKsIAeAi/naLpSCvZHIBhPsXsZdg7BEaHmektj+C+zQy3gpeg0vpUkgVTiF0A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by DS7PR12MB5912.namprd12.prod.outlook.com (2603:10b6:8:7d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.29; Fri, 16 Jun 2023 19:03:10 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:03:09 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 20/25] iommu/sun50i: Add an IOMMU_IDENTITIY_DOMAIN Date: Fri, 16 Jun 2023 16:02:49 -0300 Message-Id: <20-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR03CA0080.namprd03.prod.outlook.com (2603:10b6:208:329::25) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DS7PR12MB5912:EE_ X-MS-Office365-Filtering-Correlation-Id: 243370b0-228a-4c54-69d3-08db6e9c4c71 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4KNOAyckghr1R0cTx9K9qQxJLw89YVDVP9QFntSjd3egoZIM0dss9RLphSByT1kGmNaLJ33kWzZmd4rT0Fcro3Iq5Xsfmm7jGHfI13WGdWTj/y4OD/bZBMVf2AWiRwvHca3JgDDX59yPcCTpYL4mMiWp+EpS8sx5IxFtq3ZetWD6/+BdCDNGe/mju/EaYKpDMlCQ+62uKJgTGnhf3B9mTM0SD4NHrXy1qq4J2jtc8NULxDArgd7/1uGAkm1sTGmDNq+8fMTOm+YpS2QSPRCW/si5p/fKWpb4PFFbcLePneFN7/p6SyNl9eqK2ACYie56CEE1GeHezAhJXo6klu/DoWhvE2iKjxImIYROIC+jvBZ74xnRKjO594Fr4iacLPoEfQN7yLKP1rw31YucdU8BjwBoDl8BjaRa2OhoCi+urXsp/+uuD8U4QlH9464mO3HbOLZS7JJ72V9k8DtWNraxZ6GucGFyV+vG0q500BxIMHOOtlaBvrHO0azUw1FooJ094ZJer2HlvHXke/dD/AoAckasExGyOkgGoM2SyFAz19zI6y7Ac3LcAeSyGnUOT4rqWQC/cJidUZGO9lEl88HVEQP5aZjovnjazQEHnVnqnwk= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(376002)(366004)(136003)(396003)(346002)(451199021)(36756003)(86362001)(110136005)(66556008)(66476007)(54906003)(4326008)(316002)(66946007)(107886003)(478600001)(6666004)(6486002)(7416002)(41300700001)(5660300002)(8936002)(8676002)(7406005)(2906002)(38100700002)(921005)(2616005)(83380400001)(6512007)(6506007)(186003)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gT0TwwhLM3Z/x7TfJ30sEot3l4DDnJt7j1oI1DK2BB6yVahn27VYj83jd90VEl+AwmAqwe48/INtezwT0MEaLBrTDRowEUbCHImT024GIaSit4ANyO8Xzfo0p3vSnYZJJgNRcrWJ3OBlN9SIHn2yzPrhmitEoPf+/MUxzee8es5GWbuFX2uFCOfXz9XA7UzKSAg8wFUiDc1vwyIszieH3BQIh7gGXzUcJSPJAlKQMb0QEoDgUMEsO2A+rDod+o2NmDnjd8xtGIQyu7J5ldwj0vmXn1rA4JTVZ/KY/fA3d8N6aDQG9ySVGQh/xnjWpj/MCAM2K2vukv/swXdkVepzpXhaeHKxPdEPtiFt2ly03lPm28odvOxFbTMqFA/N8iFtrfTlUqWiRf8dTOHuvCeE/DNjHZOKsvOsTU++q1adBTPOG7LM8npYLgMSsna6yS9Gsij3E9/vo5rKcOB5UDRuHI6uzU4DJ7rzfH3PZ3UXVbzZ/YDYPz5F+McoScPJ+6pW52eQTrMErhagmqwIvF9LnYYJ8M79Ha4WLP7JB9nUeTsljCi3sKRndcSMC1c2K0xJwi6YavoHFTE5ef6lpNswOX0NuL/jvGYtgOpNK7f6wIvY3K3tby1oVQtqXaDGhqpvNkbPcbbG2fToXcouKwqNsZ6fyMwEP/kJ5rsyb05buLW7LwDUYvTwZ49UgkQSCGY9Df/uoaesHcwfbj8b9Hbbu0XGcxxRGM8sJt1DNXswMBje9AvJyLA2VdHZg55h3A5am4YE9Ar0ZbERuzI80xpkGqW/gxJWLwwXGY3KJzJf4n9HXDamgANH945ZP4pBzoM5dJlRoBMaacpFXAn5OyY4bGCBAebRPusy/i4DXeqj78gd0wBxpocrs7VD/4AUv4G4y2B9SVEKWfYYJQFLl2CjkV0CM9AKM9OGosUVra3MEQZKz7nXbu0BqwBEkBWCqtZAZ4RHodqZL0G2xrjegoP/GCYg7jQwLgXMW2UwIcugeUMfdC/J0Fnvqcc4AKF6cGNQYi8SCqQWR0JZd/UdSFWFVUAiy/9vCkhRXna8TPH3FIy+UBbGBDW2CBkSJtpAcJatLhE0Hlbwa7BbVAVMfXkMMVjt/7gNP5SPP/jVteS8Us2beNFy6K+Oi1k34Dtiyb7MhVHc/+h6KTRGbCaAWdUIezN2D+Z+w36zXyzk4eYbYjIa609f2lSImVtrN+wteIgL1Gb30jl8BpD2LPqZZSjV8lEWBln9nYBoFbpWiv+e7JKv/Ef6BUynnn4/2Fep1z59BE/r9TwbVEOF8PrgdY/OAYh92diJs17p8TCp3GZIJVnjyPwtvexmTwg7hmRmaBBe20WJYgDb5WASTvV2dA2LcBHFkRb3o9Ee1IGlWWKy7XQZ2WaaTATUftFmZyr5AimQzuKvh1Ieg/sq4QM1jRxqaczzppCJxDkE0l01R74cV/p7nRDbyvDgh+zEiJR4CAH61pGSHTxxNJ/wh78mUCN3rtT5UuW9X85JHCy5r6FeQahl63KB+UzJcTCYfDmc+P2j0VsrlyHR5eSZ4x1/pPg4yHF/DzInk6lI09Hh9cfDHEyYsr9eiazK0gjnZ8jOqGWt X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 243370b0-228a-4c54-69d3-08db6e9c4c71 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:58.0687 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 08Tr1ZvAcoV/f+P3urqgiGgkPGl6D9fzWRMCAeN4kuXFb97PSarUn8rFeaSbrhLD X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5912 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120319_569466_C1587FD4 X-CRM114-Status: GOOD ( 14.14 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org Prior to commit 1b932ceddd19 ("iommu: Remove detach_dev callbacks") the sun50i_iommu_detach_device() function was being called by ops->detach_dev(). This is an IDENTITY domain so convert sun50i_iommu_detach_device() into sun50i_iommu_identity_attach() and a full IDENTITY domain and thus hook it back up the same was as the old ops->detach_dev(). Signed-off-by: Jason Gunthorpe --- drivers/iommu/sun50i-iommu.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c index 74c5cb93e90027..0bf08b120cf105 100644 --- a/drivers/iommu/sun50i-iommu.c +++ b/drivers/iommu/sun50i-iommu.c @@ -757,21 +757,32 @@ static void sun50i_iommu_detach_domain(struct sun50i_iommu *iommu, iommu->domain = NULL; } -static void sun50i_iommu_detach_device(struct iommu_domain *domain, - struct device *dev) +static int sun50i_iommu_identity_attach(struct iommu_domain *identity_domain, + struct device *dev) { - struct sun50i_iommu_domain *sun50i_domain = to_sun50i_domain(domain); struct sun50i_iommu *iommu = dev_iommu_priv_get(dev); + struct sun50i_iommu_domain *sun50i_domain; dev_dbg(dev, "Detaching from IOMMU domain\n"); - if (iommu->domain != domain) - return; + if (iommu->domain == identity_domain) + return 0; + sun50i_domain = to_sun50i_domain(iommu->domain); if (refcount_dec_and_test(&sun50i_domain->refcnt)) sun50i_iommu_detach_domain(iommu, sun50i_domain); + return 0; } +static struct iommu_domain_ops sun50i_iommu_identity_ops = { + .attach_dev = sun50i_iommu_identity_attach, +}; + +static struct iommu_domain sun50i_iommu_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &sun50i_iommu_identity_ops, +}; + static int sun50i_iommu_attach_device(struct iommu_domain *domain, struct device *dev) { @@ -789,8 +800,7 @@ static int sun50i_iommu_attach_device(struct iommu_domain *domain, if (iommu->domain == domain) return 0; - if (iommu->domain) - sun50i_iommu_detach_device(iommu->domain, dev); + sun50i_iommu_identity_attach(&sun50i_iommu_identity_domain, dev); sun50i_iommu_attach_domain(iommu, sun50i_domain); @@ -827,6 +837,7 @@ static int sun50i_iommu_of_xlate(struct device *dev, } static const struct iommu_ops sun50i_iommu_ops = { + .identity_domain = &sun50i_iommu_identity_domain, .pgsize_bitmap = SZ_4K, .device_group = sun50i_iommu_device_group, .domain_alloc = sun50i_iommu_domain_alloc, @@ -985,6 +996,7 @@ static int sun50i_iommu_probe(struct platform_device *pdev) if (!iommu) return -ENOMEM; spin_lock_init(&iommu->iommu_lock); + iommu->domain = &sun50i_iommu_identity_domain; platform_set_drvdata(pdev, iommu); iommu->dev = &pdev->dev; From patchwork Fri Jun 16 19:02:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283123 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C29EDEB64D8 for ; Fri, 16 Jun 2023 19:04:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tfVEbhqxF9yOA6aTXfXDYxd2Wk7EoBZYVXET7GlFFeo=; b=YzNZs1GEL4vFf/ VyV0weImUmHkGkd++h+qT6su1XR/isWt6Rqi9OTzM6S7vqjcnRjO6IiKOmSlxtU3mJzB2kZv4l83M YtjwNNdzmDKomkpYkkuj3e6Dns1R2u1WWHsHDOZH3719Myvj+wGWcDBepP1d3R1v76t8ZQgKqlyRX c9Y7cxVA+dglvL4bS/waIBYpWM76ZxmpBfDKr9FMi00GD2N57N0Y/+3CWCVzAOz0xPiVHuYnjZe6v QDxKvQ6KMlCWGSQ9m4WglOHCyk8H9PKSS3wDqm9JPWkiqYg6K30HlS8zKzruL1c6edKGuIj1V3q5p EsIBdc9WHu7yXxcK5vcw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAEkE-001YIp-1o; Fri, 16 Jun 2023 19:04:26 +0000 Received: from mail-bn7nam10on2062f.outbound.protection.outlook.com ([2a01:111:f400:7e8a::62f] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEj0-001X1S-0V; Fri, 16 Jun 2023 19:03:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hL7oEFOIOYlMJTfG5s8wuiGrdvFoKQpHlxW8uFedZt5ri4KKehb0gbeoT9+hhcCk3F/8c34dkFIe01PyfRau4wXuLBemPgoClRRnv4msY9607KVcknj5hhKQCr+FyPdUdNs1dm71pmAWZZqCIXH5qZao+GqobyldWjkQeBqMgdBfHRUaQ9xcRW0JjhgkXDTn3MbotzOFxFz3MiVh6w0Ic9p03h9yQ022DMT3OkvgK0fOP4qnlRddDu879gJt2pLd4CNT+7+WK94yAZeXt6LaUkP+h3xgQk1wSfsjP13PdAWCv95goBF6slMny3U84PltuVMPEtA3xkpPrr714qZGlw== 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=ZbWRU94XzyWJt6kncIgWnjN2oHbRSgh268gPeGHXQkY=; b=bjpHLtUwn3khMoHoHPwVD6ImwRttXtF0WUAkxEYOu50fiyY7VSvBGkyGi4HcirpydviLgtyRq/G9hmYuoBJkCD0sgBVuybTNev9OvtcOrprj6dJzutb/xzAjm5pa8pmJYlXXHYK1Q+LEsN0GZAsgihQgsWOs+U658y9DnXI4DCsW1MUmyme7442nqvu/94MlKGHENhhUd4dTy/HZqcHFCArO5S+IMk6hF7lAxdNCMeh88HJPGl1vov9VCj2/v/A7DV7zMEnCJbcd77G0Fd0osz6hD95f8CPOD+vZLfFhNNOiL5rPqD6qNNBBYsAffWGeRrnwU8W0EYlV3wYuhMV0Xw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=ZbWRU94XzyWJt6kncIgWnjN2oHbRSgh268gPeGHXQkY=; b=cgaUnfgJCbfsFTTTKrs5EFNbgnLR6PIfbfTnPIT8S9zktQbLzdVImRD7ALbPmJrywahBco5TH7jDma95St6xNIu1ykA2eVGl0oIpuSJStN/9VcQ/ufDyGqMKC5xgKI6VEvcBQjUdjTIO36DWIWBUlSkib6o9gU9vTbz8QlpgzSHlPyqkIUzQgmLsMoVTGsKj86iSPhmqGWteXdw6VgW8UxaE6fVZyDt/x/5YLtwyNL4jyafzTKP9u1uiUsSrEqF5wCRrR+ExljfRF2Q/ZrPvcU0lp4LiccaeJAOwDHwEfIXe+MvOjlr76cJMo14PnMXqB/1R+q5EDandEzKs1u95cw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:03:01 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:03:01 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 21/25] iommu: Require a default_domain for all iommu drivers Date: Fri, 16 Jun 2023 16:02:50 -0300 Message-Id: <21-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR0102CA0037.prod.exchangelabs.com (2603:10b6:208:25::14) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: 237df817-974c-446f-ad9c-08db6e9c4b42 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0ZtgFGeopVKtyBx/YlpsVXLa8zNiU3axIkClGf3F9n6n+PirRz5lq4Lqo8RflKdu/zrZyGS6YSVHq5D10IvV52Q4LatBw1nL6+UL1FvG6nfX29MBZy6rBr04DKytU7BwSpHxATIDV4b6uWpfmTXGSD/MxaelvYzPg3LCh1K0KqmdKlWwNXIIjpGMEM3WsOMBHa5dY0sLZnOK7/zI4OWfprgXjogwaFg9xJGD4mjCAzg9/YxjNl8ZmIYR7zTgsrmujszrS2DqLUnyxBn3yhDGGKivoNqPiZRg9tpp+yNlNTbahTpPCuL5M0m+mm09/zFT0q/ulK7ppZ2v/yUC6bLNcQPnIiAQHZ/ZZZb3mEv/KUaNQRkVfkNZ74aQVrmw/5Ibtr4T4ikIqXKr1YrxiSrOJE+xeMyseEq8E6DujnlF9C8c0bgFbcM45lnCVmjiOeor8wQKisJRnKZBy3GFns/peJt2ll772PfKkb4dYCTlCyyqrMgthjzQrcoeJ2QIhzdHdMTGdksrbBqEbcgGn2c5vz7mhGJzZyBgyOR0laHFRCAaCs+n0s9LPs5Wlq/+/7pyWEweF0W4cxT6P04ci5la6NkyENbxd89cXxJpXKXB6+o= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 29ciVHdt2riRB30SGJX8hslgcRRdYEBI4mVnV7P7r7RYO2cAINScF3G5yros+G4VgL/7flbHa1vW7pcYieUHcfLAI70Omc9wyVVvgMK6akT9pFTCw3lagLaA9375kdJ9monpoJC410nlTGgl4o+smMqpi+AXFp25OeAHu+sKwmr6Zd3Hg5cj0x85i26UpDmnbBZpm5j5yE3Q5h9h+2i4dgmSQ0RVfMeWYpGjvFcXFF0qqOTlwmLKY3bR4uzl2nDhbY/pSvmO4cMAJDBDLoTn303AYX3HDYezeYRUQGHEYwbP6U7aazTy8LrrcdVzeItSEzkpVsg74PWwzssQQ9S/ZtT/Uu1tKQ9asimv85AjuLgXWliO1G9Cso17Flnv38ZpeLgTmuimUvgNzawePTQPPsb8ez60AQY81WgwS9NViD+DWH3mFA26KVNULxUIl6/QE5FpHhIyEdL5/sHEEYKI42D/2cVPXlgrXgB7xDNRXoWLOGQqKeUzn1d4i3qJ4pDjg2WA9OY6icPDBWUMj9M81AeT/86f/5aM8+O0KkaXdjmtGPEETzeMRNYR6D+/xx7hgCwmd+5Ih2uR9NGqXZ4+0iyecJZBOsUO6O8ZHt9G574r1wS70N+R5kQKxvLb9aqLUlXKrsQQLsXNeY02giBvL+rlViYS47PlTM81G2UBpqcUgaUwiGh7rKvaXhfiCyNq6Ommr4fZ1h8XLrSoLImkqHbRkfLsRPqmmgXaDm8o9Vp8iVgP9dr4LPjhu0CQpXKLeTFJlNd86XhxPJjoF+oGlP7ldJ4daxV95zicWhd3pCTtUyUJ0mHkNXd3BxYkUXT5emMLQzOgVOZIacSAIgslLQb6kMjD7H4S+oSiqgsBAus8F5bgEaa/aVrkMVMmnohZLwuUb3z5suP+4dXjUsS+VncdVqxaAQwa4w53yCnxfFzbOEVyOTBvnSQakRpQwhbkfZX1122bx1I19SRlenhIzpKeTAc1p3yo/cYYYuAIcDarTqtAjICwqDs0agDM/NRhiBvhVu4yToDDTIk9wHyTRCJO4DRfFlvARwmyZlH2JOjJqgwgj7A0RjTTc0ba4s5+MPXRZUIXEF19XmRs7XikGNCIIaRfAuA4YoI3ZE9oVeosmStSCT0tFKycY0NrRkjAAulb1OShHdBHrmwjE233UJkVJeTe7zIbBC0FVtfasmJEuQzbVlihJ/4Bhk6nV9DFZNAhw28+/KP2Gd9auQinWSdXKnke8bvkjs5EZfUXwCj9tnMrYaLhBdVPI1xnYiYkfjp99Klu4smAQvuNLUNGhHC4eA5wvBU0zlqIBMTe0Gi5CYnaWBe73acX51mosFXsJgjl+kVJ/0jfaMdmHXylYnRxG/2gdH8r8nE+zJLP9/RX3rPRx73N6snPmsJYF5dA4ybjXXO8X3rr4n/5DSEo1bXZntq+9WrVfO1XOffoKI+ift1eTWymBfwHtObBovYbWrMunKarywBvqBzPjXaUS+a/L7rp/noDtfuzF5H+p+VmJMAsVtuh+CBh0iL1THvqcc39RR0JJEy1GJtDm2oEf18LPW0sdGL3SGlfc+b0+igIU8msvZ+nERwK1zB5NkWe X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 237df817-974c-446f-ad9c-08db6e9c4b42 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:56.1082 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: tqHSCZ5AY8BIEc9a/7XhGziyjUnqcD93dujecZCm1wWB81Z6J024qec0sYZ7bt+3 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120310_240187_95662B4D X-CRM114-Status: GOOD ( 20.32 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org At this point every iommu driver will cause a default_domain to be selected, so we can finally remove this gap from the core code. The following table explains what each driver supports and what the resulting default_domain will be: ops->defaut_domain IDENTITY DMA PLATFORM v ARM32 dma-iommu ARCH amd/iommu.c Y Y N/A either apple-dart.c Y Y N/A either arm-smmu.c Y Y IDENTITY either qcom_iommu.c G Y IDENTITY either arm-smmu-v3.c Y Y N/A either exynos-iommu.c G Y IDENTITY either fsl_pamu_domain.c Y N/A N/A PLATFORM intel/iommu.c Y Y N/A either ipmmu-vmsa.c G Y IDENTITY either msm_iommu.c G IDENTITY N/A mtk_iommu.c G Y IDENTITY either mtk_iommu_v1.c G IDENTITY N/A omap-iommu.c G IDENTITY N/A rockchip-iommu.c G Y IDENTITY either s390-iommu.c Y Y N/A N/A PLATFORM sprd-iommu.c Y N/A DMA sun50i-iommu.c G Y IDENTITY either tegra-smmu.c G Y IDENTITY IDENTITY virtio-iommu.c Y Y N/A either spapr Y Y N/A N/A PLATFORM * G means ops->identity_domain is used * N/A means the driver will not compile in this configuration ARM32 drivers select an IDENTITY default domain through either the ops->identity_domain or directly requesting an IDENTIY domain through alloc_domain(). In ARM64 mode tegra-smmu will still block the use of dma-iommu.c and forces an IDENTITY domain. S390 uses a PLATFORM domain to represent when the dma_ops are set to the s390 iommu code. fsl_pamu uses an IDENTITY domain. POWER SPAPR uses PLATFORM and blocking to enable its weird VFIO mode. The x86 drivers continue unchanged. After this patch group->default_domain is only NULL for a short period during bus iommu probing while all the groups are constituted. Otherwise it is always !NULL. This completes changing the iommu subsystem driver contract to a system where the current iommu_domain always represents some form of translation and the driver is continuously asserting a definable translation mode. It resolves the confusion that the original ops->detach_dev() caused around what translation, exactly, is the IOMMU performing after detach. There were at least three different answers to that question in the tree, they are all now clearly named with domain types. Tested-by: Heiko Stuebner Tested-by: Niklas Schnelle Tested-by: Steven Price Tested-by: Marek Szyprowski Tested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index e60640f6ccb625..98b855487cf03c 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1805,10 +1805,12 @@ static int iommu_get_default_domain_type(struct iommu_group *group, * ARM32 drivers supporting CONFIG_ARM_DMA_USE_IOMMU can declare an * identity_domain and it will automatically become their default * domain. Later on ARM_DMA_USE_IOMMU will install its UNMANAGED domain. - * Override the selection to IDENTITY if we are sure the driver supports - * it. + * Override the selection to IDENTITY. */ - if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) && ops->identity_domain) { + if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU)) { + static_assert(!(IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) && + IS_ENABLED(CONFIG_IOMMU_DMA))); + type = IOMMU_DOMAIN_IDENTITY; if (best_type && type && best_type != type) goto err; @@ -2906,18 +2908,9 @@ static int iommu_setup_default_domain(struct iommu_group *group, if (req_type < 0) return -EINVAL; - /* - * There are still some drivers which don't support default domains, so - * we ignore the failure and leave group->default_domain NULL. - */ dom = iommu_group_alloc_default_domain(group, req_type); - if (!dom) { - /* Once in default_domain mode we never leave */ - if (group->default_domain) - return -ENODEV; - group->default_domain = NULL; - return 0; - } + if (!dom) + return -ENODEV; if (group->default_domain == dom) return 0; From patchwork Fri Jun 16 19:02:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283122 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 94569C04E69 for ; Fri, 16 Jun 2023 19:04:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zOxsPAQMfVF0SLP1QR0HdUojE1uh2kqUevsXyIlDEv0=; b=qlIEVTeTwk8mKR CSvxzPSsOHwjRl4mkZ39TGZWJcBEQCtCVmFdFqHPhvVCPDhkIeYk0nhz7T8Txevy5RB0Hk1GR2DFz qpPxFst7TvymgEPmt5kPL/u7hexHpjwKHIQ2zBBBBgeudmHlnxi8so8th8dTjnGKZgkLzH+trNemf aCp17NqurT6Qzk0DPG7m/U11V6Apslqgm3dw1VNbw4renS07gfUwiGIhUo3fnofI7FepSeLvBJVlB +5kREOrB/uxUnITP2mbTcDtQJYqjj/be6Kp93U3bXVU+SVjwbCATzwKVv80n1595sKP7cCRCGdEkn 3w9AebnBdi+V1WPXLGiQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAEju-001Y1y-1N; Fri, 16 Jun 2023 19:04:06 +0000 Received: from mail-bn7nam10on20620.outbound.protection.outlook.com ([2a01:111:f400:7e8a::620] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEiy-001X3y-0K; Fri, 16 Jun 2023 19:03:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C8gVspyDOwr3y4MD+SBZjp9CkVJz+5KtXRp4ge20xTBludg8ANuOJr4ILyMf2u55l37kw6yYwlZ0TCq51nf5Ts+WxySDkj+9yTME6ptyyzqLgt1IuiV6oIqmvevqStZlpuQdmGvvOPGobKMIqvl9K4gDOtLKboyQ6SlaDF1b98oE4CTOP3zYc+CFoZ2Hszep1AgGU6jVdBpFq/O744M+BbeFTmw8h82XvCzd+o7URhIxVT1ZIr7BWwPSR8cOPa9lD2vKwaNPgNTvu2puZG9fPEuL0w6QTqvL1ZlxVotvfpqS5yhO13XevJy+fZmFvlNF6NUCHqSjL5UZ65G2rHmWuA== 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=UGJ9OhSGaMcQ94+sOuAW3uy5BsT4kqLXHivmJ7O0hfg=; b=jJLG9BikP1BbOo3i89CU7HzWNEOswaDcP1JykTUvN9JlD+4LhR9B3lvsHvj2fyFZD09e5irUlbZCr9gelxI8Rq9PZYH7kuKVdRLhtlPa+6B55BMCiXcaN5kaALUCm2XhVJZjDTR+JyKYydAcGxmHp2fzyYczEm/UDO9c8vEtsW2Ic7v2BYysHOjZFsL2BPJPQycVAl6on1hFpM2Y2L07cKtibLuM79MQNRCw5rZ8UXgJrrslPS4phc1FqgSikeikoniMRRK3s6Swb2X1dRkOlTH2XyBnpxqIkn/tXBNfAcPqPdVC15sUKJCZ/31xxS1tJWl5uk2s24YGej4aOsdNww== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=UGJ9OhSGaMcQ94+sOuAW3uy5BsT4kqLXHivmJ7O0hfg=; b=Xx83ko7vPjX03xpNDGdXJqZsMRhgAvDtb+3Wk8w1Tg4xKxgpGtL8LMIXivX6KcUd8f1lZcoz2MnsszwCcvpg2J4dp+fjU58OKd7/6Ssv3ktpCqRLQoHRmoaQ6eA3HYxGBFkNxPMCwhIWnq5c+RotsBuRFkyiGrI8hWWXFbXejXZOEGeT7UKn1mavMX9tkkHcQ00jzJzeh1z63W3ERuAF48B2wilDXnmrkD0Uvlxc08p03EHjmCT0Jrl1DxAi8280m2QDtMiuLAYcSncIV7XcBIJOfj3I1s65NeB/HUoMdZm1bEl25JKed2IdNhJ0nG11kfsJtjDH12f8QGhewD79nQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:03:00 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:03:00 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 22/25] iommu: Add __iommu_group_domain_alloc() Date: Fri, 16 Jun 2023 16:02:51 -0300 Message-Id: <22-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR03CA0087.namprd03.prod.outlook.com (2603:10b6:208:329::32) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: 2da2cd77-dde2-494b-12e9-08db6e9c4b26 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Bb7o1baGLsaGCLaeruoJW8GL3T+IoioQthazHce94MlJupFbW1oFlWlP+kUr+KAK2NmM6oqyHSeTYV0ERG2KyDqPCg6vs6EAAtplvX77XbgM8Bef57gUrloiZWtIRo6OR77MAYIElKkZ4XHuCvc30ciXtukWw9/YYPcNRXCM1oBBaAC1a93L1jo3s2gTAukloqUMLLWWVvQYgmA+YjK+6BmtHwExh7Xf/SJzSKVveqap3+p636JJcFMrIs/YgI/LpsU+qW2QJJMkX0tO6AbvRHtS1ku5utTYB8DFpRrMXY9SuHo8q03JCOxa1d/J7NBc1SCh09LaxZCedJqTgqOA8GgKLqqdZzIOR1BjLoWnh7G21ih/aPpY9YjgeVFLq+ruDbmBLmjzZ57JAsvikGkF31z1kN9XU8u8X/9sFHm8HIrgCqNPMsIQr+VzWdX2lrUeIm1GQbVPyTT4m/rrU9Z2emHLzRIKzTxm7DTfYAdaVKUcXuMLv+kmAWgDciFtTpTMJuD0GvNY0005k8nQWzirNO2gcQfvhEOsQz+DtkloMESQzLgSKRAWNzkAkLTrIWdjORiceii1MgHa7Lsw9ME0Tw8DBd6OZbDtirQZ2BvYJcs= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: U0Jcw54Y6dFGBhGrm+7+XoP0yClOjJOXeRVgjr3zqju3Z5cfEF62s7CnZnqHi/1CprWkmf1CYQo0wLZNwUIOCNCEjWLDwNrWHyHi+veWIoqUj6B/52enhX32sy2QhLyxnMOEAjR1ED8rdOkwifU4qV+4+sVE0cpIGeOr1n/+5YQwwT33ZArRHX9+gQ8X13gFgEbs41sxs3pi7DGBtrCcvUkvtTNLHATXf6HK7sSNMPeT3bycNb++N8T0c+Rx05FrosGZkfSxcVrqK06Sr5wTj06oi/JBrex3iyT3YSBAi0cXQJQS6yOgDCZh0oNWLKNl/CsplJlYYXR8t4hwG8AjaP0J8qePtOMVEstXQjzRgieLLLCp4lybAg2uwTFojf2kN3cvOcudZu6BRtXKrAnWT6gXt2DeAgU4CTHS8FJ9poEcaP6K3op8IRTrn8gU2YaNXcqPoFlV3eh2hnFXOlhTMeb3ZlZ6fWpYZBlPDxUiVBbpgHMw0n2WDArY5AFk32CGT3Clp0STtGudADjqKQzWrP3cilTFq3OOC9Vg8ity1DhTHxcj2LTEKJNrv7qqNXq258oP26DpjtdF9TuVvbmr3OofL7tgx+HHLCKZJtMnagbDbK6qCJMLBzcudBfeurEvVL4FgvA9hJctrGAKg5mPSBDOCALsf3i01lE0ANHvVdgrD5fxHU/dE/e+E6aYPW8r7RERohLKp4EJQkBuR1J8I8Xu1cxm3wghdGln/vizXU1ZnfmBliTv46LiHHF3CvdupRFHlOmewAIaYqJr/InKrjPG0Kz3Sy6D3QydYFDr/wK284CCTEgNUYItbNMXbHFlpEdbc2RJLalm+bv4h4UDZukCVSgrgHyftV0X7ek8pdCcHA9aWOWPL6ENmmqVRJsqCSG5hvSG0f2k19Upk4tCIDuYf+MIEL2aZa2eIJrDlLWYVUjBlwGrB+Qhq0YmSsBp01tf1evYyY9keZH2M+GvbB3gzvxvaV/FU5V8IKGQvM/Ne1Up7QKTMote6znvGJBi5uytAAtZBZp4q+U+kqvBGNWQrrnFRkXQnv9sZnI1mSB2oSjZ79GySiD5v1r0G2HZyZFs7RuxxnJ400xCBwC3cwkzNvhNr+kwyZCzsXMQ2b4nwBKLbsIpxWkem+zfuWohYiA5W7fk8Aw5k/8CNBmSWan6GfxWeilLCPpHyCyc51+wlmgPeINwmw3GljmE72uHZwW+LGwKc4z2ykscXSgFv0IZHs8EIk4XY/MhvQjzmaqLqUZgTwpuGkTFuTw6za3RX5awFn9vZzOIsLr/P1BXEaSh0OMCTXdDtp+1WqD19ZeArxGpmLFSCK9DCke8HCV8Ods5hxqzvsdg3zjn+fo5BGBDP6MEGRIKh6+5fu5A1cRZQ3arwa3q/LGFs88cWKjgSnbz+Z3Q0QhWKR+QDy8eq0o3U2lQyG4AV/V5fa7Zyy3CSVPFtLSp+ediV1qbOuhcxAcYxkOsivrlunFtPkFs/uDnNCJ+SxAdhyRuMDOkZZiQqrQ/q3TFkCC430mS53e+UsLJVzP4WtbMEFqDHvNnCqoxksudZQdY7hhYPiKH+O9kM6MfBfF5/YWfTYQFeKAB X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2da2cd77-dde2-494b-12e9-08db6e9c4b26 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:55.9525 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VHSd87hHy9pS40u/7zbdQwYD70LuJHgvuV4lNkZUa0OxkUT21Jd7SYu0dzqyEdNH X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120308_174723_1F3E4FAB X-CRM114-Status: GOOD ( 20.53 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org Allocate a domain from a group. Automatically obtains the iommu_ops to use from the device list of the group. Convert the internal callers to use it. Tested-by: Steven Price Tested-by: Marek Szyprowski Tested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 66 ++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 98b855487cf03c..0346c05e108438 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -94,8 +94,8 @@ static const char * const iommu_group_resv_type_string[] = { static int iommu_bus_notifier(struct notifier_block *nb, unsigned long action, void *data); static void iommu_release_device(struct device *dev); -static struct iommu_domain *__iommu_domain_alloc(const struct bus_type *bus, - unsigned type); +static struct iommu_domain * +__iommu_group_domain_alloc(struct iommu_group *group, unsigned int type); static int __iommu_attach_device(struct iommu_domain *domain, struct device *dev); static int __iommu_attach_group(struct iommu_domain *domain, @@ -1652,12 +1652,11 @@ struct iommu_group *fsl_mc_device_group(struct device *dev) EXPORT_SYMBOL_GPL(fsl_mc_device_group); static struct iommu_domain * -__iommu_group_alloc_default_domain(const struct bus_type *bus, - struct iommu_group *group, int req_type) +__iommu_group_alloc_default_domain(struct iommu_group *group, int req_type) { if (group->default_domain && group->default_domain->type == req_type) return group->default_domain; - return __iommu_domain_alloc(bus, req_type); + return __iommu_group_domain_alloc(group, req_type); } /* @@ -1667,9 +1666,10 @@ __iommu_group_alloc_default_domain(const struct bus_type *bus, static struct iommu_domain * iommu_group_alloc_default_domain(struct iommu_group *group, int req_type) { - const struct bus_type *bus = + struct device *dev = list_first_entry(&group->devices, struct group_device, list) - ->dev->bus; + ->dev; + const struct iommu_ops *ops = dev_iommu_ops(dev); struct iommu_domain *dom; lockdep_assert_held(&group->mutex); @@ -1679,24 +1679,24 @@ iommu_group_alloc_default_domain(struct iommu_group *group, int req_type) * domain. This should always be either an IDENTITY or PLATFORM domain. * Do not use in new drivers. */ - if (bus->iommu_ops->default_domain) { + if (ops->default_domain) { if (req_type) return ERR_PTR(-EINVAL); - return bus->iommu_ops->default_domain; + return ops->default_domain; } if (req_type) - return __iommu_group_alloc_default_domain(bus, group, req_type); + return __iommu_group_alloc_default_domain(group, req_type); /* The driver gave no guidance on what type to use, try the default */ - dom = __iommu_group_alloc_default_domain(bus, group, iommu_def_domain_type); + dom = __iommu_group_alloc_default_domain(group, iommu_def_domain_type); if (dom) return dom; /* Otherwise IDENTITY and DMA_FQ defaults will try DMA */ if (iommu_def_domain_type == IOMMU_DOMAIN_DMA) return NULL; - dom = __iommu_group_alloc_default_domain(bus, group, IOMMU_DOMAIN_DMA); + dom = __iommu_group_alloc_default_domain(group, IOMMU_DOMAIN_DMA); if (!dom) return NULL; @@ -1984,19 +1984,16 @@ void iommu_set_fault_handler(struct iommu_domain *domain, } EXPORT_SYMBOL_GPL(iommu_set_fault_handler); -static struct iommu_domain *__iommu_domain_alloc(const struct bus_type *bus, - unsigned type) +static struct iommu_domain *__iommu_domain_alloc(const struct iommu_ops *ops, + unsigned int type) { struct iommu_domain *domain; unsigned int alloc_type = type & IOMMU_DOMAIN_ALLOC_FLAGS; - if (bus == NULL || bus->iommu_ops == NULL) - return NULL; + if (alloc_type == IOMMU_DOMAIN_IDENTITY && ops->identity_domain) + return ops->identity_domain; - if (alloc_type == IOMMU_DOMAIN_IDENTITY && bus->iommu_ops->identity_domain) - return bus->iommu_ops->identity_domain; - - domain = bus->iommu_ops->domain_alloc(alloc_type); + domain = ops->domain_alloc(alloc_type); if (!domain) return NULL; @@ -2006,10 +2003,10 @@ static struct iommu_domain *__iommu_domain_alloc(const struct bus_type *bus, * may override this later */ if (!domain->pgsize_bitmap) - domain->pgsize_bitmap = bus->iommu_ops->pgsize_bitmap; + domain->pgsize_bitmap = ops->pgsize_bitmap; if (!domain->ops) - domain->ops = bus->iommu_ops->default_domain_ops; + domain->ops = ops->default_domain_ops; if (iommu_is_dma_domain(domain) && iommu_get_dma_cookie(domain)) { iommu_domain_free(domain); @@ -2018,9 +2015,23 @@ static struct iommu_domain *__iommu_domain_alloc(const struct bus_type *bus, return domain; } +static struct iommu_domain * +__iommu_group_domain_alloc(struct iommu_group *group, unsigned int type) +{ + struct device *dev = + list_first_entry(&group->devices, struct group_device, list) + ->dev; + + lockdep_assert_held(&group->mutex); + + return __iommu_domain_alloc(dev_iommu_ops(dev), type); +} + struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus) { - return __iommu_domain_alloc(bus, IOMMU_DOMAIN_UNMANAGED); + if (bus == NULL || bus->iommu_ops == NULL) + return NULL; + return __iommu_domain_alloc(bus->iommu_ops, IOMMU_DOMAIN_UNMANAGED); } EXPORT_SYMBOL_GPL(iommu_domain_alloc); @@ -3129,21 +3140,18 @@ void iommu_device_unuse_default_domain(struct device *dev) static int __iommu_group_alloc_blocking_domain(struct iommu_group *group) { - struct group_device *dev = - list_first_entry(&group->devices, struct group_device, list); - if (group->blocking_domain) return 0; group->blocking_domain = - __iommu_domain_alloc(dev->dev->bus, IOMMU_DOMAIN_BLOCKED); + __iommu_group_domain_alloc(group, IOMMU_DOMAIN_BLOCKED); if (!group->blocking_domain) { /* * For drivers that do not yet understand IOMMU_DOMAIN_BLOCKED * create an empty domain instead. */ - group->blocking_domain = __iommu_domain_alloc( - dev->dev->bus, IOMMU_DOMAIN_UNMANAGED); + group->blocking_domain = __iommu_group_domain_alloc( + group, IOMMU_DOMAIN_UNMANAGED); if (!group->blocking_domain) return -EINVAL; } From patchwork Fri Jun 16 19:02:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283121 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 47E96EB64D8 for ; Fri, 16 Jun 2023 19:04:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4n49qvk++PmqlP05YDaqqnO1vU/mGFTBdA4WYvWDsIA=; b=QRZX6Tq4rVZXqZ CF+GN5dp3dDjgHyprwWnhWYamVrr25sabn7xOKJkUbB47kOxJ2evDNNYnrZOxDjKcxQiJKgLOv0/c fz926Gs+KA3HGa4pT1pgKOIviH3Qv36JJwPxrCvIrWR5ZrhGOKoU86RnH1yDQUfJxnx/I7F+wlOyC N6TKBdb5dGdvPxn3zVXJ1Wd6GSLzegmU5hq/6DkL7KpMIlqNMlRFJ2mJMEpsUGODZam55QsVZN5uP GlOIQC4dtu6IirVSvu4Yd/tTman+QNfGteIR1ft4JkYfp4b1EsYgl7RvPCFvnXExSZHx4VU87TnVU D3HaivcWb8NBJygny/gw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAEjs-001Y0P-2g; Fri, 16 Jun 2023 19:04:04 +0000 Received: from mail-bn7nam10on2062f.outbound.protection.outlook.com ([2a01:111:f400:7e8a::62f] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEiy-001X1S-0P; Fri, 16 Jun 2023 19:03:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f2KTCxvjDQUqsm7Ae0nxl4ecGQVbgN8bwsTy0tb5jKP7Now6WQLp8MsvRsxHXaDqKsYpg6EWHB7wk8SZMw2pVv0dJ553XtxNch+hi3p6hGJD0L3UPxvOKyxePNbZdeIc6w75pH4zbhr2aXn+v9zQUGhrfFvDaRQABTxaeMunfEtxd4eGS6TtVkvUK5ix4aP2Hbf4xK2XFTyH41NOhY4WGlLSF/vEQCX0y9JAci0EQFk4GzA14Kwltix2AJ947gR6SEJkvDnLuANJKFWECzvdC3PqGA3djgPRgyusgjeGtpdKXe/XXbEST25y9TVA2cNrbomlUgDW7kOW3OM1k2Krug== 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=wtwsG7Y4uCGU7mH6MbKK3qYDI3hc9WHokBPbjewgzx4=; b=Mqr4vsNL1LtvYm2/wGqQsH7JKsuez9tLYIzdYOkpgW/I2dycFZFsuSSQWGVVxk9eA6qTTPZ07rjPgRigY3PfE0Cdy+X94lTJlx9c78FybH3bO/7nv0c89SO6l43M+AkmWLlz/bb57UukwKIb8cM8hRq8d/1wOCaAiUR7OJPN4SF8sM/U7w6EZyb2v+Y/SNl4w08agHo6qg7Lg5xCwqZ2JhFFq46QnvzT6JxqoeTUZbVWe2mMDU3Afsqg845WZLjqnT5G3mLEI0S5FUdHxdJsl2z5p6d3uxSAKHqHEywlSbFMxVZDaG4CcSvcgIyYot+f7akZo9wFYyLoPBsEmDcTpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=wtwsG7Y4uCGU7mH6MbKK3qYDI3hc9WHokBPbjewgzx4=; b=HKWqmbmKtUQ/nazqB68n0Rbqe0obIN53UNZwTV6pSLTkyGFK6LU7Ly+c9OYrwayVVU2MFXGZNH8zKSmtBIJR2Aw5wFqaT/hyzLPUOOHxdFpDvKdFOEZq8srme+SBL8yWFqtM0wEq+VQA0ode0EjkidYYGKZ8pDgiIsSoHAr1TBXeWVslUQ4hhqUrwr0LQrDMmTQVyHfl3zLxKf2imiEPzmJca9AhyzlsZutsblR68IMLLxyl2MU90ly+D7fWtPa0U5rRhpWZwEpqR5+cVTIhybGQDGouNjZwis9Xi+SB0k64/h1r0G2cwb4Y6031SjccMl4vZ9/5v5F6kHuWD9daGg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:03:01 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:03:01 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 23/25] iommu: Add ops->domain_alloc_paging() Date: Fri, 16 Jun 2023 16:02:52 -0300 Message-Id: <23-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR03CA0072.namprd03.prod.outlook.com (2603:10b6:208:329::17) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: ecd79999-76aa-4c52-24b2-08db6e9c4b39 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Pgk9mMpsY2urgIhqXmAGoXzL3yXXvM10FGUJ4oNnZp+Z3wDoXMPsHU+xljCvzWp5LyTs21M7uBi0tjWRQiVX9EeTVWZFqGd8Nzvsh7A39vV+qwJb0PBsgll3njZww0Tx1KLnAt4hs4JNxze10ZA/UKko1nzf4Ij2QCxcTJ/pOwLXIbOmaRYztSmjrY6zsLAOoqr8qCtJKReHE4WVP9YYImgquw0v4xEmV0A1vyOrMvt09cat6i+Ec7mqLPgAa4XTztXBlAG7Xy540NZoQCoxqLLG+8Chcn3T9rNiTQslJCcURu1lTqPY9JafpLC8vu0d6jf63EdQ37oM82CEZQ/2eA9kRHEhMrUbkdS7qfKeOgBNHazsLK795TLOqKLPD5BnQhUiNixbQ8n53EbV1M4qHwvSKIDk049Ef75pxv7uzzWfHm7THxaOuKCf94+6by/xrztLPdvyOqICvFQyLiqFxguhfCQ3Da5r7MmFv1y07ETz0OOR7kqKtJynstYBve53SupH5OgFKB3yqxJ4BPTBT+gZhWf4D0CTrgcVUvMEeS3t/PFsXVwMzwwxmeq4dsATi5jb4g2hqL7342ZOzViehh514sfscwXyM0T/QBf+cZY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MW+Sm9XVB23zTEh36hHAByAmtaZli774ZADhXkDD4hjWuQPxYmFMg7AlJ/HHBIut/aRa8mbjzvYRa9sqSXci6Hz4WWSF6N4knZIFCqje+lfuQPNih5Sy8ldynzb99uJ3xesr/IakceNx6uANBE8Xq4SST1Sw3Gw94uUAzvBPhdn03HAc0XENPjAuydDf8Y53lfXaymSFDjgKIiQxW7XJTC7G2F96OLbdmXyjO88IrqVJNbHjEuMVjX2qGA9+SQ85UUYcLEMWLrk2o26f6c5h48aNMTvt8phTBNLe448uNcgZgbA2BJh6thXE7nEilTephKEQBKIGEDCiMrLcbqZs47YQeN6g8zgd3L7uIRMIQjmfmoRBUXYocriklIA3wgddIISgGcOEeuivwwlhKboL4a5o+YpVXQHnwG/w7HnNix978qy/IYgSCLzj3ZiSq5RYcE3MDdfsHBKydhWPi6fgu7VOsRvIZWMfhyIeUSua7V90+tb6FiWJq/3SnBruOS97v6FDBignWQWdtSSAxrh5utbmkXjddHtikpXp1z0hdspt2EsDF17b8k4OKE8y9LIm/29B9FDCCuoIPxQEiCLEFogCclQ0uCUBRgPL1ZCTfjNz2Gd2LO2WP/0hdgJa3sTp81p6/GHuNh7CvLq42ufeRKHlm1KGOSwyA1OFbCmfnA0I8TSui163jy607tk2/Cip/IFa9egCuKL+FLJ31TfcN6trafMOz91B4PlQrHoJNpSZB9nrN3uDLTTGYDCyt+oGpAHiyP1HSSV2VsrHcSlyWNQp6c4h+QBViIdJrWYfrMt88wiWLDunUiAhoasqLdgJZq9kENprxaRfZAdKDrqK/MBXf1MgH/LDTQwjN6kU0uCsFCcktPleR1Fviuy2Q72HytiZ5e29MYrw8Q7EP7Iw9qByBE9pBLYEB7lz0smmL8Jg66bmTjq0Wut6rd4vSoFdJXqIfv4Z8KasF67rpkDl3oh9kJjJ0jP543GLYpjjdkdE06EWHobsXQWyeKuR/QhkGn4JwP7/oM0MJuInaPdh3kbN75fJpPCokRMIYdf5VDF92a0KFl3yc6iAknzgVT/N1PLhcXlOdoT6oqini6TiWh8WQMQ0H2uQok42aJ8Sx/BKhCWXzXCa5cg7T45dlNmD7sP48ZAU7CoDjydBR0ZUdJn+klQpaTxUpbGEYvOJRd2CM6nc1I31k3FkdfChE54Hij1oh/qUpnZ3U6rhKcAQJR8ZV00tHc27638qmBJ7GDfgNPtgzlnRVbYVFnh5ftHHn1kqihiLM4rCLmtEf4rA2qoOYPjrkjrx1THyeWpHDVJWXiSBSbtDaE5zvEglrWsNB0FVGlIAvr2NzBhGgcBJ57Nai+HFr8jSS/3yq56pBq11fXLKvoILfehAI6PNMxqC+/OF0211s9GJgRNa2sJgU2AofS/gKDNE6JBkf1TlYI1rvDIfdfO3CcNIKYDoHA4Na+wIBVT3PUJiymHP6q17f5rouu7WsTkCz+AQ0x0NemwIjShap/Nxt7/FuQYapYqJwYFAeHy3vhZdMGsGFy01ouE6UBXalWvbcgsjOxUppdEr3q0mtOwRp9eHZXzNEZWn X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ecd79999-76aa-4c52-24b2-08db6e9c4b39 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:56.0466 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: o2yZOfniEbWY4EkqeVWCiPu9RCjRVQ9tD8quy89d3NhVE1c86QryOHDqmb9+UJ44 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120308_180710_0627DB9B X-CRM114-Status: GOOD ( 19.46 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org This callback requests the driver to create only a __IOMMU_DOMAIN_PAGING domain, so it saves a few lines in a lot of drivers needlessly checking the type. More critically, this allows us to sweep out all the IOMMU_DOMAIN_UNMANAGED and IOMMU_DOMAIN_DMA checks from a lot of the drivers, simplifying what is going on in the code and ultimately removing the now-unused special cases in drivers where they did not support IOMMU_DOMAIN_DMA. domain_alloc_paging() should return a struct iommu_domain that is functionally compatible with ARM_DMA_USE_IOMMU, dma-iommu.c and iommufd. Be forwards looking and pass in a 'struct device *' argument. We can provide this when allocating the default_domain. No drivers will look at this. Tested-by: Steven Price Tested-by: Marek Szyprowski Tested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 13 ++++++++++--- include/linux/iommu.h | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 0346c05e108438..8f3464ba204498 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1985,6 +1985,7 @@ void iommu_set_fault_handler(struct iommu_domain *domain, EXPORT_SYMBOL_GPL(iommu_set_fault_handler); static struct iommu_domain *__iommu_domain_alloc(const struct iommu_ops *ops, + struct device *dev, unsigned int type) { struct iommu_domain *domain; @@ -1992,8 +1993,13 @@ static struct iommu_domain *__iommu_domain_alloc(const struct iommu_ops *ops, if (alloc_type == IOMMU_DOMAIN_IDENTITY && ops->identity_domain) return ops->identity_domain; + else if (type & __IOMMU_DOMAIN_PAGING && ops->domain_alloc_paging) { + domain = ops->domain_alloc_paging(dev); + } else if (ops->domain_alloc) + domain = ops->domain_alloc(alloc_type); + else + return NULL; - domain = ops->domain_alloc(alloc_type); if (!domain) return NULL; @@ -2024,14 +2030,15 @@ __iommu_group_domain_alloc(struct iommu_group *group, unsigned int type) lockdep_assert_held(&group->mutex); - return __iommu_domain_alloc(dev_iommu_ops(dev), type); + return __iommu_domain_alloc(dev_iommu_ops(dev), dev, type); } struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus) { if (bus == NULL || bus->iommu_ops == NULL) return NULL; - return __iommu_domain_alloc(bus->iommu_ops, IOMMU_DOMAIN_UNMANAGED); + return __iommu_domain_alloc(bus->iommu_ops, NULL, + IOMMU_DOMAIN_UNMANAGED); } EXPORT_SYMBOL_GPL(iommu_domain_alloc); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 49331573f1d1f5..8e4d178c49c417 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -233,6 +233,8 @@ struct iommu_iotlb_gather { * struct iommu_ops - iommu ops and capabilities * @capable: check capability * @domain_alloc: allocate iommu domain + * @domain_alloc_paging: Allocate an iommu_domain that can be used for + * UNMANAGED, DMA, and DMA_FQ domain types. * @probe_device: Add device to iommu driver handling * @release_device: Remove device from iommu driver handling * @probe_finalize: Do final setup work after the device is added to an IOMMU @@ -264,6 +266,7 @@ struct iommu_ops { /* Domain allocation and freeing by the iommu driver */ struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type); + struct iommu_domain *(*domain_alloc_paging)(struct device *dev); struct iommu_device *(*probe_device)(struct device *dev); void (*release_device)(struct device *dev); From patchwork Fri Jun 16 19:02:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283125 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D409AEB64D8 for ; Fri, 16 Jun 2023 19:04:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pq/Q0cq1tkBbbiGOD05nLRaPz0IXVpzYcRUMIBjhy1o=; b=O9BmGQ8qu0JRJw ErPaU2xu6yrrkD0cD7OZSc2k7EGPuV+WoP7Gixrsp1JQCZHVgyU/N+fQ1TlyRt4GcdhZo24fKrSXs B49C9xVLge+na3gdqiUzyldye/+LLEO1CUWeZ2nURF3ePXtdxuAz7R7ws/62/d5ImQnp3Fe66uFp/ 1ccILn0FtcfKb4v2eqibEMf5tGglWOkw2ao6sSe/NYGrCe3w01yiqbGWW61lIqRxDS4HtP9AoadkW PIlGsje8mL1rSV0tPoMLB07dD8CK4gjy17Tn2fl04ACyBSdP/9RhTNVdxVO6/+RTAVVNRh+qj4N6x xBUW107pXcMd6CPC9Okw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAEkc-001Ydx-0x; Fri, 16 Jun 2023 19:04:50 +0000 Received: from mail-bn7nam10on20600.outbound.protection.outlook.com ([2a01:111:f400:7e8a::600] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEj0-001X8M-2U; Fri, 16 Jun 2023 19:03:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KvlNl7E9meB57ntElOq6fxXSvKi3DVILeVZSDuvob6QSzdbSSzR2kkSgr1ONC0iv/NJeWGg8ZWmmFWMlzAhFf6ahrw0QMuitY567QDTM62BL9z+b9Ts6MXk1WY/B+Gn9IxZrhJ7jUoKZl5ksdQhC3cXJOI9/F5QdHvlomtbeXRSNAWwBF3czfBL88HO301a7ZvvL4D/V1jlliTS9vVKWJukkVTkFvNhE4xwC0qw7MaNXdmvEN77e56Y1qnjbjwk6FKVwWHR2RqgmRQfJ3+XTatGE2tHhE0+qyymlRLMWRckRTxfPeA/7ScrqafXAjcbCVArA4hxUYCCIZZij0TwAMw== 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=QoElIesssKEjdPfTMK92RQw64fGEXLOoFDEC+x6aHHs=; b=O1OhofoAWCa5fIftgnWLN1HJ0NpQdi9Mx0nsThUbW9Gy5r6LTH+E25QKK2HMRKs413vxvTpY9ChTVjGaQ9p9FDjtv/xQegXRizoHWEzYAd9yK7j9C76vh2DUjfj2PDQMtwcCvzMwGRTB6WQ05/2xdBmuzSoMazi7mhug5pcqggaMFC4b99D4BUgia7iB4Epun/WxZrS8YCGZCPEKFOp1lu3J7c934mcT1WjXurWhntsAt6s3bK4e4wnPoR+45qpx4eVSa/Lz5QSkD1HgVaXYLiI8+QySFlbPNj5kCegvw1xjMB2YObyiIVW2nY2tKTHIo4miI5zJXLNzdD2d4ZWxvQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=QoElIesssKEjdPfTMK92RQw64fGEXLOoFDEC+x6aHHs=; b=g6hSsnl/FwOeSPOSZB+wpkrRosQDVX/dx4DPfXayUd5EtleJoaNPFtNontVswWRecLvbwLrIIOd5a89O17ySUmjDVrZH9a9eKxin0+rBkvG3S7N36N+qsjBrWkAocDzi7gBU87vyqCoZXBh+eX4W2kfY8LDyUA7UQ0fdBv9RLrZ8lz7g4djRn1VIdj2tGHUkXtmbpjqAjN7xFQtXqgdcanG8LIe+QQkyFSlnIvh3yJMgf5RN8XUc1GygfuktN32R08iuZlErAsKf4IEMenezxa3Pot/NulnWpbsJS8tS1PvK3ZPFLuCsJxeVp/pMw2zHa99fBQOh/6ue3UFZQLNZxw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:02:59 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:02:59 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 24/25] iommu: Convert simple drivers with DOMAIN_DMA to domain_alloc_paging() Date: Fri, 16 Jun 2023 16:02:53 -0300 Message-Id: <24-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR03CA0071.namprd03.prod.outlook.com (2603:10b6:208:329::16) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: c38a6189-6436-403d-7822-08db6e9c4b09 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3NDFX/BaUgO6PJtlyuonUFNproQ9i3VyOelnQrfhJA0sXO/priWqXFbMBhsddc5c5eTqoA9zjnDNGORDMrVn64dMQ4NR5SBMU27QMJ90jrhju8TGNqz2Penn0wxdyuMXXkO1pnMn4fz7NhWDiuBURoTjdBxPMs/h1/yUesUd7LgbuV19SbYaElgwgIvCef/Zs0Le8SFAy9xOvuiOAzhOIQhcdJ9fZyzabk5d2RumjgrMKErhHMk4U2PHk8J2EPC7ybr4g1V9QCzPxV9k/3LfvGph52x1tgXiV0dlr3xh4GLtkJg27bSJSXOg1l7QK2itu0U4Wznvhr9wvadAMnSKVEne6PUB2Z2+2r4mmHyS2iCufYLM2V9l8a0dyz0ZJvTtEmEMEBRJnfFmo/OgMNQi4oHCOSsVEK4aXYkhWb+88UyKl0mb347A3IuV/CDUiaNjE8YVpglPWNbc9QKE5BhzdZEE6seQ21X2AALlXK1ZSZPOb9ezch46x/ylhA+5jrxucXlxdZdmieYLmETE9kAQ9lxCX3pkKhjkHWNbC90yup37Eq8AXRijtXoPD8ofDZwVRSPg9ibpXROm0MBRfcVGY6LWQ6wHmBXnXOe8wQzJCSs= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JUF4+8qtMwfGsAT7GJTYN774USy7jyBvUK+gWGUt44zyqGvAcaMWM/kbHhsLs7fsFDGU72KOUMV3trYk/83dNHI4qiJG2z/q16dXUycPcFN9Sw8mKIUBM95pkd7N93/dGNwGYCiSDz27almhP36GPuhew8njUYG9Q8lRNlR74n/zIpvUa+bk7lSZnn6WNP+sv3Fe9iP1xbXYx6poUXWWZJdhJG94EPnl9W0HCZB5ozAkiFba5k2BoXdSalDBYaP+Ob/KQBAT+sembdzTRms+IrhHbpUzSslHh2kcTnBMaWt2T+QStXOFUTQ3rgpnRjMyW6/M80/mGzmUP7qoZb/5mBA27nsbmQaVICPD7AHHMyHSKS5O/Xl/xEO8wOikd9Q6tKiRwuh31qYrQF9ti9uzvObDe7XZH3M6mF3l5KJOsovIp9X/I3yC0eiEkd18k5Oo9/XwjIgb34EjE7YUqr9pIbWCBckD6BN1UZCfQtgwtiHquh5Y3PyshF5+SIrFPLySQynXDLrmyzsSOvB0fmNlywsZbHduuWsmHjwJYRr7dKrZlgqn/GAbC8mzgtVrFJz5xF8W0hDOR7Tlqwrx1/xWOpDH8xgN5BEhZlLei9kkcCoSugqLqLm3CNrNcpU/HMzcKNJKMfNjXiNVGDca1nFNVLPd7O56A6W6A1T6JbS8eVhQaZcwOVhX9OQD0iixWBEBRxwbb4oMJhljpQYLGe+KLQKAHfhxk+T5v06l0DMj/TIl6CrkyHAzZfg3Sefjlufp3z1wvtHdP1KzIyNy0Wq6X9wVzvDx0AlbqcQiyAjwqqEUBCP+RC2Iv6V4U+ekaQKmouprnwfNVsl0XkN45G9e4mXwDpNfpccOz28xOLJhW5M8FzF5GUFh5GD5dQEjXMxJqLuUsS1O0RqY5JaU4Fooc/Mt0Jt6cgOeHqRk517v8R1sBQ4C+Mp8xI0NbHm3mpfOV5IkkxHGqeTo+hgv1NxfNRSAyNe9WJLdEdIMYYP4BErHGVzOzeZ3nKs67lgfifAmsjuO9QROY+ORHKxpCIPEVotlOiRa1aqp5fzTpkjMBwzOrWoTF7IexTeHr37sC5/42mJXtCFBBml+UU//X/SPccShHGL4HGvtTUgO7SFcX78i2gZ+oajaVRu2l0TSoOYzWw09Vu9m6YwD1RjXyPtsDiAigz+JjlTF/idgjiA5mrNJwfdnnhWr04iDaouypEBnLCri2r55nRyh1SZQBfyp8i2POwoKp1ZRcwKrqFG7JCjD8E98a/KUUMXlJrsQwlygT2bvDpmLaxPoJzD1pizDtIG5NZZi7u2gNfvNZRL5l5oLVPOa9yXMnz4rn+xIJUCQ/1gPpCEzakTG1AnDB5xnmxDXaWuR9VE5WTkitcXzgJPCQeGn+M/El5r0mML+ebaYoTSUcRhKwqH63wciY18vK0ivavv706kz0b4lxnl+NPSGCuGChlZV/tLjKAm7QeVvhmszlP2tJ9toqSMP0NL90ZiDfau7GvqRcL6UIocIy0bP5n8EAS7vv+ETQXQF26IMQTFhm4ff/spoacG1uKsG6b5KfVfD2d1mtfE7yjMGvOUt3HQqaitZLZFeMyjotNA8 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c38a6189-6436-403d-7822-08db6e9c4b09 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:55.8261 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: WBPYu3pUKGzZel5L79Nj/3NLOKP67Sa2Hc73PRjV9x+KINf3VbzwrmlgnxKTZAhw X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120310_919325_80DB48FB X-CRM114-Status: GOOD ( 13.32 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org These drivers are all trivially converted since the function is only called if the domain type is going to be IOMMU_DOMAIN_UNMANAGED/DMA. Tested-by: Heiko Stuebner Tested-by: Steven Price Tested-by: Marek Szyprowski Tested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 6 ++---- drivers/iommu/exynos-iommu.c | 7 ++----- drivers/iommu/ipmmu-vmsa.c | 7 ++----- drivers/iommu/mtk_iommu.c | 7 ++----- drivers/iommu/rockchip-iommu.c | 7 ++----- drivers/iommu/sprd-iommu.c | 7 ++----- drivers/iommu/sun50i-iommu.c | 9 +++------ drivers/iommu/tegra-smmu.c | 7 ++----- 8 files changed, 17 insertions(+), 40 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c index 9d7b9d8b4386d4..a2140fdc65ed58 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -319,12 +319,10 @@ static int qcom_iommu_init_domain(struct iommu_domain *domain, return ret; } -static struct iommu_domain *qcom_iommu_domain_alloc(unsigned type) +static struct iommu_domain *qcom_iommu_domain_alloc_paging(struct device *dev) { struct qcom_iommu_domain *qcom_domain; - if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA) - return NULL; /* * Allocate the domain and initialise some of its data structures. * We can't really do anything meaningful until we've added a @@ -593,7 +591,7 @@ static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) static const struct iommu_ops qcom_iommu_ops = { .identity_domain = &qcom_iommu_identity_domain, .capable = qcom_iommu_capable, - .domain_alloc = qcom_iommu_domain_alloc, + .domain_alloc_paging = qcom_iommu_domain_alloc_paging, .probe_device = qcom_iommu_probe_device, .device_group = generic_device_group, .of_xlate = qcom_iommu_of_xlate, diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index 5e12b85dfe8705..d6dead2ed10c11 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -887,7 +887,7 @@ static inline void exynos_iommu_set_pte(sysmmu_pte_t *ent, sysmmu_pte_t val) DMA_TO_DEVICE); } -static struct iommu_domain *exynos_iommu_domain_alloc(unsigned type) +static struct iommu_domain *exynos_iommu_domain_alloc_paging(struct device *dev) { struct exynos_iommu_domain *domain; dma_addr_t handle; @@ -896,9 +896,6 @@ static struct iommu_domain *exynos_iommu_domain_alloc(unsigned type) /* Check if correct PTE offsets are initialized */ BUG_ON(PG_ENT_SHIFT < 0 || !dma_dev); - if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED) - return NULL; - domain = kzalloc(sizeof(*domain), GFP_KERNEL); if (!domain) return NULL; @@ -1472,7 +1469,7 @@ static int exynos_iommu_of_xlate(struct device *dev, static const struct iommu_ops exynos_iommu_ops = { .identity_domain = &exynos_identity_domain, - .domain_alloc = exynos_iommu_domain_alloc, + .domain_alloc_paging = exynos_iommu_domain_alloc_paging, .device_group = generic_device_group, .probe_device = exynos_iommu_probe_device, .release_device = exynos_iommu_release_device, diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index de958e411a92e0..27d36347e0fced 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -566,13 +566,10 @@ static irqreturn_t ipmmu_irq(int irq, void *dev) * IOMMU Operations */ -static struct iommu_domain *ipmmu_domain_alloc(unsigned type) +static struct iommu_domain *ipmmu_domain_alloc_paging(struct device *dev) { struct ipmmu_vmsa_domain *domain; - if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA) - return NULL; - domain = kzalloc(sizeof(*domain), GFP_KERNEL); if (!domain) return NULL; @@ -891,7 +888,7 @@ static struct iommu_group *ipmmu_find_group(struct device *dev) static const struct iommu_ops ipmmu_ops = { .identity_domain = &ipmmu_iommu_identity_domain, - .domain_alloc = ipmmu_domain_alloc, + .domain_alloc_paging = ipmmu_domain_alloc_paging, .probe_device = ipmmu_probe_device, .release_device = ipmmu_release_device, .probe_finalize = ipmmu_probe_finalize, diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index fdb7f5162b1d64..3590d3399add32 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -667,13 +667,10 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom, return 0; } -static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type) +static struct iommu_domain *mtk_iommu_domain_alloc_paging(struct device *dev) { struct mtk_iommu_domain *dom; - if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED) - return NULL; - dom = kzalloc(sizeof(*dom), GFP_KERNEL); if (!dom) return NULL; @@ -995,7 +992,7 @@ static void mtk_iommu_get_resv_regions(struct device *dev, static const struct iommu_ops mtk_iommu_ops = { .identity_domain = &mtk_iommu_identity_domain, - .domain_alloc = mtk_iommu_domain_alloc, + .domain_alloc_paging = mtk_iommu_domain_alloc_paging, .probe_device = mtk_iommu_probe_device, .release_device = mtk_iommu_release_device, .device_group = mtk_iommu_device_group, diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index 818748a76e2469..64e32b3bcd209f 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -1071,13 +1071,10 @@ static int rk_iommu_attach_device(struct iommu_domain *domain, return ret; } -static struct iommu_domain *rk_iommu_domain_alloc(unsigned type) +static struct iommu_domain *rk_iommu_domain_alloc_paging(struct device *dev) { struct rk_iommu_domain *rk_domain; - if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA) - return NULL; - if (!dma_dev) return NULL; @@ -1200,7 +1197,7 @@ static int rk_iommu_of_xlate(struct device *dev, static const struct iommu_ops rk_iommu_ops = { .identity_domain = &rk_identity_domain, - .domain_alloc = rk_iommu_domain_alloc, + .domain_alloc_paging = rk_iommu_domain_alloc_paging, .probe_device = rk_iommu_probe_device, .release_device = rk_iommu_release_device, .device_group = rk_iommu_device_group, diff --git a/drivers/iommu/sprd-iommu.c b/drivers/iommu/sprd-iommu.c index 39e34fdeccda78..af68b3a2c123ab 100644 --- a/drivers/iommu/sprd-iommu.c +++ b/drivers/iommu/sprd-iommu.c @@ -133,13 +133,10 @@ sprd_iommu_pgt_size(struct iommu_domain *domain) SPRD_IOMMU_PAGE_SHIFT) * sizeof(u32); } -static struct iommu_domain *sprd_iommu_domain_alloc(unsigned int domain_type) +static struct iommu_domain *sprd_iommu_domain_alloc_paging(struct device *dev) { struct sprd_iommu_domain *dom; - if (domain_type != IOMMU_DOMAIN_DMA && domain_type != IOMMU_DOMAIN_UNMANAGED) - return NULL; - dom = kzalloc(sizeof(*dom), GFP_KERNEL); if (!dom) return NULL; @@ -419,7 +416,7 @@ static int sprd_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) static const struct iommu_ops sprd_iommu_ops = { - .domain_alloc = sprd_iommu_domain_alloc, + .domain_alloc_paging = sprd_iommu_domain_alloc_paging, .probe_device = sprd_iommu_probe_device, .device_group = sprd_iommu_device_group, .of_xlate = sprd_iommu_of_xlate, diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c index 0bf08b120cf105..056832a367c2af 100644 --- a/drivers/iommu/sun50i-iommu.c +++ b/drivers/iommu/sun50i-iommu.c @@ -667,14 +667,11 @@ static phys_addr_t sun50i_iommu_iova_to_phys(struct iommu_domain *domain, sun50i_iova_get_page_offset(iova); } -static struct iommu_domain *sun50i_iommu_domain_alloc(unsigned type) +static struct iommu_domain * +sun50i_iommu_domain_alloc_paging(struct device *paging) { struct sun50i_iommu_domain *sun50i_domain; - if (type != IOMMU_DOMAIN_DMA && - type != IOMMU_DOMAIN_UNMANAGED) - return NULL; - sun50i_domain = kzalloc(sizeof(*sun50i_domain), GFP_KERNEL); if (!sun50i_domain) return NULL; @@ -840,7 +837,7 @@ static const struct iommu_ops sun50i_iommu_ops = { .identity_domain = &sun50i_iommu_identity_domain, .pgsize_bitmap = SZ_4K, .device_group = sun50i_iommu_device_group, - .domain_alloc = sun50i_iommu_domain_alloc, + .domain_alloc_paging = sun50i_iommu_domain_alloc_paging, .of_xlate = sun50i_iommu_of_xlate, .probe_device = sun50i_iommu_probe_device, .default_domain_ops = &(const struct iommu_domain_ops) { diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index 6cba034905edbf..69c40c191ce4f0 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -272,13 +272,10 @@ static void tegra_smmu_free_asid(struct tegra_smmu *smmu, unsigned int id) clear_bit(id, smmu->asids); } -static struct iommu_domain *tegra_smmu_domain_alloc(unsigned type) +static struct iommu_domain *tegra_smmu_domain_alloc_paging(struct device *dev) { struct tegra_smmu_as *as; - if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA) - return NULL; - as = kzalloc(sizeof(*as), GFP_KERNEL); if (!as) return NULL; @@ -997,7 +994,7 @@ static const struct iommu_ops tegra_smmu_ops = { .default_domain = &tegra_smmu_identity_domain, .identity_domain = &tegra_smmu_identity_domain, .def_domain_type = &tegra_smmu_def_domain_type, - .domain_alloc = tegra_smmu_domain_alloc, + .domain_alloc_paging = tegra_smmu_domain_alloc_paging, .probe_device = tegra_smmu_probe_device, .device_group = tegra_smmu_device_group, .of_xlate = tegra_smmu_of_xlate, From patchwork Fri Jun 16 19:02:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283124 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A2740EB64D8 for ; Fri, 16 Jun 2023 19:04:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8Wz9mBKCEghb3y/3lX1oSDT+Gmvv/e7HrQMhVNzfk/g=; b=ACzfl0iTprZPJq L3Ay+HtJfA1jCObTcIDM8AFOhJYbU/Q1Qukzr1AxyLfv7RsdgJ3zAHsPgiOj8Qne4m6xsW1kVw1lY 1IHEVIHTEk7bITBNRXcjs/K8RWDmhkA5XqW4zjxX3vN3pBzwl/DdSwD9ZWClvU6cuSThsPLIY9oLT z7/cUpO1cS0KyBCJWwPOznLWSKG3/9ccRySKIAG0sW8ERwWXQ05VKuNUPNQwtKF14WmpRtPJloFeF pPK8vYuiYGNKl/B8cXnIiYQYnMOrMSkEH47smgITYCNxdlLjpyAEUZFfNUQqq/o14aCmkpDVdPt6Q cYXDHVmqyntlEigd/lyg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAEkG-001YJt-04; Fri, 16 Jun 2023 19:04:28 +0000 Received: from mail-bn7nam10on20620.outbound.protection.outlook.com ([2a01:111:f400:7e8a::620] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEj0-001X3y-1F; Fri, 16 Jun 2023 19:03:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LH16qqhuu0/ONSdqsUApyTFzH2cfEMDtJKyQklBroQq4MHNt+o58gXzbhZMQO+bQ9kJsaYyy147LRk/JY33cbNNlW3n4j29RY0bXqoZnMLBb2gc5J607dUYfpA8NSVKfSHvC3agpj6e3QOupByExIFyRHkRBxfGTUIaVGvAvmGsyNu+4H93AwFzAYNHAxJjiz4eYCP48X7zLCSGHraaqsFs/zObuaUatbwyPuJYopKKaUNVKD6tTz3Y2sUUNopyQp+qGF6OLjblvlR7PJaDjiuZ8L2djv4JUzjOHMm3KiEj2c/TDPiZ3kLNK27LCT3YToI/MBim9Fg4F05fj8h+rhQ== 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=QWCGzrTaqbrXMG5crzEf4pxvfNiTwQ928/5BOZsI094=; b=Hvue8rteNnv7jZl/8VVVXP9sOghKzCx5+xxisTpWQ1ly+YUwDqT/ef6tjx4iaMC4ejBZ70inTTOug+mQg8PMiJWBFooP11Yr1DBqtC4MDsNfUPgM5DhLK5kZ895T/jFNKO+NyIgedpSfr9ieksAj7Tpq97qR6/pPIjFASiR/5scxb/3IUVl3ChucbUDk5LKd2yD764tuyTKGBEHuDZ8W5GwsszoRBQSQJrIs+XzUgjq+0YXyRfrRS0aI1VmOl01YLy2GJ/4qaWULhx6rivMqWtEdKhWnyhpjBm7O4As1QU9U30cWt7uP8XGsDwzdvkDN6CbSU6MbI2ybmqJ03ANwuQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=QWCGzrTaqbrXMG5crzEf4pxvfNiTwQ928/5BOZsI094=; b=SXGzW5W13aWTGphgiDo4fqcLGPHnOMSNWBDn/AY+WhBwU7B7gFFIFs4fkZbCoiZ4REHKTNvAS1PKNLjUtS9fJYpgo0cYt94MxcC7F2ZHNOxLilbXubqT8w5Dhk6hJzP/9Wy3uQuM6sqoWu0q8ug+1p9Xj5eh+iQp3iiPAowZyl7pBFFrFoaYc69GuSyj0xJkjo9NebjtNSldEUEl6HS2e+fYefblYNtlc8ZLEmAbKJCowNiv/wxM/EkTyCe+eLDWAEWkhKI9JC+ByrGIuD87m62Z+lEv13cJ7ZixRbZVP0W0MzC9s2aokWfjUVKd0XgqcD8f+Q81soknHynNu1aGpg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:03:02 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:03:02 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 25/25] iommu: Convert remaining simple drivers to domain_alloc_paging() Date: Fri, 16 Jun 2023 16:02:54 -0300 Message-Id: <25-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR0102CA0071.prod.exchangelabs.com (2603:10b6:208:25::48) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: 0110fe4e-8987-48c5-fb2a-08db6e9c4b50 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yR0LWbemdZpFm68pzG/UvTAooMx2joI+AaliaDgIIy5t1YS9O2z2nY+UJsMXfFpni7PF8a4YRqzOX4xEnvaxCM7zjD3HTMzC0jRLk8FPqpX4PfJIik5aSKXZvHC6xveynqAuu8uCMMzxiYrLkuS4ZfdNZVEEwpMvN8IjfnQJ3M5PCcy5pauVv58nqL01CkNlMnu99TRMdWvlhFp5UAImosZmfWHVAE8RlgBeG+STZdjWGBXZFmcFczpIbntTVe8COjpcyLJtCQmGJAMHZnY+h6emjZpjJOV9Cib4oEGGW1PV2inpWXFRv0Md7gFX+K08B1rRUTxxo3S9JV2Q8q1jhfYH/IFtxR34uXRW6FjtGoJPgI/a7afEJl/a2lAcT5VXfLZtx12u+LQ7AMnO1qOjsoKhCvNJ9Ch2DpU5VhTRWprD0+KPecssfl0U0c/k4sAUXK+2xS7ntCg35JuM8xX131UVu853WLytB9TGR3x5NiRFqkTDniKEnF3q155vslzoIZwKbkMSv+3YkwHsWnLAK6pc9OI+183P9CM9TvYrvCvkI/FARDYIqiPm+JVeVe1eolFFqW0SJk5TbNjbXuG21e7Zu744H9UZfITcjnumSug= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IOn58KqjfqGNeSIkK2ZEjKd5DP6tx58Cg85MaKY6viLqZLZzMpd247U9xQEtdSRTnOaUq0quC8PNaaS0SiFXb/axS9KaOlUD0+HVYShQAWNue58oE7rGvfLi5QtpfQ04nm1z6G70eVgp4x7OAi8ofEiyhCG1f5lITSD69h/ntYKtqTD33XN1x9iGfBWImJN5xn6v4qSuCpuZMy42yn0XnZe47KXa8nvyM+NuXeMGlsXlS8Oz65Nmln/Bv8uo/MsmaHA0thj/Kcm20ZCzwXQ0z9OJSy2amQ72C5k+aBQmP8iqIhjDH2tY5AO3XfOnBCiI05MahSIyrYQHpt0wd/IhAI+s5XppGeI7KKdjsNS1Um6SiKDA7KNcZfXJuCSv7CFHZGU4dHruuVWieUyLSSlMBCzKr+H39pOk9UcpQKdtXhpKhZNDGe/K/SBNZ5Ais/VSJ4/H5VkOl8FCtL+htrOEHsX8Qr/DpkwdsiXKPPLglzGgggDfW4nmGKp8emXb229GCSYVvm3ybuzaP/pxcqDHZmuKub5WEmQPPMK8JA4qYJolS/B5ya9ukwUed1ZMJCVr8MIctlrmEI32XwNZ5/7DuDoTvQBy29vvTg4RauIU1CrHaM4Fw3tA3JcGxDXXqAN9d6nM7qe1zbU6bwNs5hI+Hh1M1ykOz3OH+IWv7q+QV3nFSEkG/qjxddieQqFNZ2pMjs0XYPBlrssg/CDjeGGHFvCbcfcE9BgsSTcAEyTHlmv89maTxe0+tTfQQwWCOXzUODzaFgGdBluQJ8X612uTKJPHkm78RAwx3kIS7mdC/YIB6NP8fnLGGfrgrFtov/0vIUkvSvY8eqEKx6VDn6tHs0JrLgl5i5ry0i3elREU/MwUMhL4lm/F9OoyXLhdqee8g7dJWT6snEhW51DhoTVa7ddAHd5bh1oZSLHMtO7Sw5lhXM0UbCouXkdDQXymtTncbOEWCmTib9aDWhP2tBjvORUd5k/9P8LWo4+FhaA+InlUgRI9iWR8Kd4D8z8UMhWgntR4IOwh8pn9/pNfI2nHEOJASWAR/CzcJ1Lq3CIQHAutP2TLNGHQtLEmBxA+tzu0LHtMgdXTSU6Yr+AHnLSvbxtvjCZcDdAEY73XJRTlIV/NLujEYi26Z4O6FvAV6+VxArQi5vP6zWgZj2SW+b0wm0ZLsVfbHR42dLbvnrakLZA4XZzu/70BZYHL9Um0/mGVGqknjIfjxvvthXsHoZ8GiRelnWsBjMvSA+h2Flhi0HgimK5ACLUdey75WhPKWF6iACgv8NaMYUS9Qb3v7nNtQeQdJWfZkVtymoGOkc4ApZsieoQlUWmEaIGD9TDeSizrjXvtwoX9PlL9aaKHWRWg/+Tlln5X2a68twRR8wyKWVuVivCp1On5FVbOqxaYgpNJY29Bci8ckK852EoETK3cU6M1J9+Z+rmyr/8cw4bb+yuWc/+6HBxvwIGY5fYDS+DVWJHu5LtQsoKupuvyIHFkAH5/UJuLOvy+3UKyIfYeq1jC6ZRmKVh67XGaFDBqIWyE+pKDkAKA2KYWc99hKeEPrilJ8wS0g+o7SEp4klv2THP7Ny19ezS0yX0mDEd69doF X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0110fe4e-8987-48c5-fb2a-08db6e9c4b50 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:56.2071 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: IK26pWdshZuFg4GgDLtYSE6JNEK5MqpzSabcvCgbk5Xh8TT1qKM5NrT4/o+tKqvM X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120310_455760_7835C126 X-CRM114-Status: GOOD ( 14.33 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org These drivers don't support IOMMU_DOMAIN_DMA, so this commit effectively allows them to support that mode. The prior work to require default_domains makes this safe because every one of these drivers is either compilation incompatible with dma-iommu.c, or already establishing a default_domain. In both cases alloc_domain() will never be called with IOMMU_DOMAIN_DMA for these drivers so it is safe to drop the test. Removing these tests clarifies that the domain allocation path is only about the functionality of a paging domain and has nothing to do with policy of how the paging domain is used for UNMANAGED/DMA/DMA_FQ. Tested-by: Niklas Schnelle Tested-by: Steven Price Tested-by: Marek Szyprowski Tested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/msm_iommu.c | 7 ++----- drivers/iommu/mtk_iommu_v1.c | 7 ++----- drivers/iommu/omap-iommu.c | 7 ++----- drivers/iommu/s390-iommu.c | 7 ++----- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c index 26ed81cfeee897..a163cee0b7242d 100644 --- a/drivers/iommu/msm_iommu.c +++ b/drivers/iommu/msm_iommu.c @@ -302,13 +302,10 @@ static void __program_context(void __iomem *base, int ctx, SET_M(base, ctx, 1); } -static struct iommu_domain *msm_iommu_domain_alloc(unsigned type) +static struct iommu_domain *msm_iommu_domain_alloc_paging(struct device *dev) { struct msm_priv *priv; - if (type != IOMMU_DOMAIN_UNMANAGED) - return NULL; - priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) goto fail_nomem; @@ -691,7 +688,7 @@ irqreturn_t msm_iommu_fault_handler(int irq, void *dev_id) static struct iommu_ops msm_iommu_ops = { .identity_domain = &msm_iommu_identity_domain, - .domain_alloc = msm_iommu_domain_alloc, + .domain_alloc_paging = msm_iommu_domain_alloc_paging, .probe_device = msm_iommu_probe_device, .device_group = generic_device_group, .pgsize_bitmap = MSM_IOMMU_PGSIZES, diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c index 7c0c1d50df5f75..67e044c1a7d93b 100644 --- a/drivers/iommu/mtk_iommu_v1.c +++ b/drivers/iommu/mtk_iommu_v1.c @@ -270,13 +270,10 @@ static int mtk_iommu_v1_domain_finalise(struct mtk_iommu_v1_data *data) return 0; } -static struct iommu_domain *mtk_iommu_v1_domain_alloc(unsigned type) +static struct iommu_domain *mtk_iommu_v1_domain_alloc_paging(struct device *dev) { struct mtk_iommu_v1_domain *dom; - if (type != IOMMU_DOMAIN_UNMANAGED) - return NULL; - dom = kzalloc(sizeof(*dom), GFP_KERNEL); if (!dom) return NULL; @@ -585,7 +582,7 @@ static int mtk_iommu_v1_hw_init(const struct mtk_iommu_v1_data *data) static const struct iommu_ops mtk_iommu_v1_ops = { .identity_domain = &mtk_iommu_v1_identity_domain, - .domain_alloc = mtk_iommu_v1_domain_alloc, + .domain_alloc_paging = mtk_iommu_v1_domain_alloc_paging, .probe_device = mtk_iommu_v1_probe_device, .probe_finalize = mtk_iommu_v1_probe_finalize, .release_device = mtk_iommu_v1_release_device, diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c index 34340ef15241bc..fcf99bd195b32e 100644 --- a/drivers/iommu/omap-iommu.c +++ b/drivers/iommu/omap-iommu.c @@ -1580,13 +1580,10 @@ static struct iommu_domain omap_iommu_identity_domain = { .ops = &omap_iommu_identity_ops, }; -static struct iommu_domain *omap_iommu_domain_alloc(unsigned type) +static struct iommu_domain *omap_iommu_domain_alloc_paging(struct device *dev) { struct omap_iommu_domain *omap_domain; - if (type != IOMMU_DOMAIN_UNMANAGED) - return NULL; - omap_domain = kzalloc(sizeof(*omap_domain), GFP_KERNEL); if (!omap_domain) return NULL; @@ -1748,7 +1745,7 @@ static struct iommu_group *omap_iommu_device_group(struct device *dev) static const struct iommu_ops omap_iommu_ops = { .identity_domain = &omap_iommu_identity_domain, - .domain_alloc = omap_iommu_domain_alloc, + .domain_alloc_paging = omap_iommu_domain_alloc_paging, .probe_device = omap_iommu_probe_device, .release_device = omap_iommu_release_device, .device_group = omap_iommu_device_group, diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c index f0c867c57a5b9b..5695ad71d60e24 100644 --- a/drivers/iommu/s390-iommu.c +++ b/drivers/iommu/s390-iommu.c @@ -39,13 +39,10 @@ static bool s390_iommu_capable(struct device *dev, enum iommu_cap cap) } } -static struct iommu_domain *s390_domain_alloc(unsigned domain_type) +static struct iommu_domain *s390_domain_alloc_paging(struct device *dev) { struct s390_domain *s390_domain; - if (domain_type != IOMMU_DOMAIN_UNMANAGED) - return NULL; - s390_domain = kzalloc(sizeof(*s390_domain), GFP_KERNEL); if (!s390_domain) return NULL; @@ -447,7 +444,7 @@ void zpci_destroy_iommu(struct zpci_dev *zdev) static const struct iommu_ops s390_iommu_ops = { .default_domain = &s390_iommu_platform_domain, .capable = s390_iommu_capable, - .domain_alloc = s390_domain_alloc, + .domain_alloc_paging = s390_domain_alloc_paging, .probe_device = s390_iommu_probe_device, .release_device = s390_iommu_release_device, .device_group = generic_device_group,