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: 693581 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9C7CC001DC for ; Fri, 16 Jun 2023 19:03:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345460AbjFPTDM (ORCPT ); Fri, 16 Jun 2023 15:03:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345655AbjFPTDH (ORCPT ); Fri, 16 Jun 2023 15:03:07 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2087.outbound.protection.outlook.com [40.107.92.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA4803C0B; Fri, 16 Jun 2023 12:03:00 -0700 (PDT) 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 Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.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[] = {