From patchwork Fri Jun 9 19:55: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: 13274408 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 E79A0C7EE29 for ; Fri, 9 Jun 2023 19:58:23 +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=5p9XnTtaw7XJqQeV+6geG2JGmPtqlPmkr2vK9Cr3vUY=; b=k3OkYe1ieIjqce C7Ls6NNp8xjKNsj7d5mObm6vsZgnKu5lVY9fz9vaBUIjkGRoHgnSNhPxGRdzoUF+so1c4BOxqY9ur WncTy2xtqV3kFWr5Nb92UVO5JDGdQHom/7B7ERWalmkENvIcUnR4r+jDoi8lV7N3xBsVH2qn1eeho 56uquE3g9okENoVxBMxF6Tj7Ddo3dtq+eJHmsM63aXxInNmoudeRQ9JHdt6rwe2Qx9kzGPcQ0ryPp J79vW/5+bptlGGC5gR5po82iO7axyJWUy7z05WG1BMiX2pftBqigExc4S/58cz3qIgBx5m7jmyhnk DcBqw54WxC4VXgiQWF+g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q7iF6-00E5m5-0h; Fri, 09 Jun 2023 19:57:52 +0000 Received: from mail-mw2nam12on20618.outbound.protection.outlook.com ([2a01:111:f400:fe5a::618] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q7iDs-00E4Rq-1z; Fri, 09 Jun 2023 19:56:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V8MTy7gdLiRWFZS31tUNOOlzcnQLv5qO9e6SzhLeF7+gAT12ThnM3jTAukEYuy6mRWQVPNu8oGhrhOAD8AQ8q5e4mejK/+uFpsTPu+iPNUIhGJeerMPD7lvVV+Tnbga2Aet20VefUw2xcylKltAm8td4QPi6qaDxkZlDNb8EKWIpd8J7C/OVUF+wPOG++ZdyxMR/rs8tpri06xi1uH+9aPm/ktbfoSePEW6n2p2Um34ktOo9dByOohmKcH9gGrOGTsYnG4yQrReY342lyGMG0mLZdTLmuQt2uJbRVSrVLrXFmycxbzBGQaa1UVqi4ksDrf9R5lviIDKkQyi1VsRYQw== 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=CWe14gVrgo89CJqrhaLa8wB1azB48GXQlOT4CVDCZVgVAiel/Za4gWa9A9506EsD3tF0fDkplP6fzBJfc2yvS0VPW/PVJR2Ce/td+cEhCRFPx3gdFXL0MpHNglSfr+zFKMRzVnfs+9NXebMpmZi6xlUPgegfMeYhh4RNyWmbPf3M1KARA0H5p7/HVke4jUolQ4+z+XAB3tDSdPdm0xoCVnllpIx3yhRzxQ0prU4wI6OuaioPS9Mc0PeN/1fE2J4Q1OaibCPbGmoyswmgMmLZmk1vRPuyv/R+KfklIYS87hRfSuN+3Fp+zQF34ERhPyel0wansBA0JXB/+b6u5ENpDQ== 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=EnRaVg4o/b9OOC2Bc/NgrOZz8DrN0mFwNgxFufPtSC919i0YTO2B7j38koEBSjegO3+R2r45CakxOMC/ClH9yYDZ+HEZ+QM82+BAONaSOjazfEwpgBrliT51e5nuhRWg8aWcMFcnYirzxMkeq28NvaFlV/eW9UzlgQRp4mY4vndJsNiet2yy2Fm/3NSxnfkghwYzpQL5BZU83L2u3u18+ykNMY5MWZ7WOP4xafBZK765NqnJVbQXBjOdt46FxZa52hLYeqKyLeOJCgNA7sqxQsFiSu0/TZLHtWVJiO3mUf5YSWPSJ/pBO6Azph1XxHBYT0A3lL/nMU0lsY8eogqPBQ== 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 DM4PR12MB5264.namprd12.prod.outlook.com (2603:10b6:5:39c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Fri, 9 Jun 2023 19:56:22 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%6]) with mapi id 15.20.6455.030; Fri, 9 Jun 2023 19:56:22 +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 v3 03/25] powerpc/iommu: Setup a default domain and remove set_platform_dma_ops Date: Fri, 9 Jun 2023 16:55:51 -0300 Message-Id: <3-v3-89830a6c7841+43d-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v3-89830a6c7841+43d-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: BY3PR05CA0037.namprd05.prod.outlook.com (2603:10b6:a03:39b::12) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DM4PR12MB5264:EE_ X-MS-Office365-Filtering-Correlation-Id: 2d642ef5-1a52-49e4-e529-08db692397eb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rKFQY+kiusr0r9umgEWutoK/KiBT1UKltFa6/kDmFSugcYg3qtYnhkAX49knnHZ0kIvzoeX1KPzSTrRWJdCPJNFwZQQmOHcfoUXShxFkyjBat56mRRTShUMRn15xZ4qjvp7YxScYdEABue3DGy/tbHZ+rs2+9Txax49PT+QusG2vxJIyX1vmrf3ImpYDv5BOrBvKw9ZHinpa8ol0SRuotwLr7UOO49iC1/3YLyWnFDyiTg/xrbR1el9GMmDKWeHw9o0ZdjsK6DOLm5ya8yLDjDZP29P/HscGyD5tEvxqTxMNi3PBme6DPmazq4hnGr+Ls7wqUEhsM0tdDcjEOzpboJONlCq33tCAjIQzXYWCUl09ZkMsLywaCXkX0o+Nff5yyP4HtK0M+HJRQcY8/MyTMe9vdswoR0F6qVJ/NhHZqt0ZmMMmRSEKg0dZm9PC/z0vgYXK1RQ9BNDt6w7qGtH+tLC+K4LSnRT3kWqwkHLmTZ0vBszb5awpiKFbuXcM0S/rmNR3KuU7b5x8w4aPbgUgdaeFJDQx8P/jGnBpWjvMwtqM+6F5KlS6/guhS6LT49fjmZD/R7xLC09XvukyJADJ/JTeCqgvG6u0Srs6wIChRFNt045tSd7BTNnEGqULgSed 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)(346002)(39860400002)(366004)(136003)(376002)(396003)(451199021)(2906002)(83380400001)(36756003)(26005)(6512007)(6506007)(478600001)(54906003)(110136005)(107886003)(6486002)(6666004)(8936002)(7416002)(7406005)(5660300002)(2616005)(41300700001)(66946007)(66556008)(4326008)(66476007)(8676002)(186003)(316002)(38100700002)(921005)(86362001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UQDLPQ5GLbyN15x8e9YSsqYLMK4IsURS4f4x7TJpuRM/xosMwurF2o2SwYwz+299SPiTmp51/m6qCy3FPA5GgphUTzz+l4Pr0OzEBc84jgbHescoLtNuV8PRMpvlC0IOJDkWbNdxiwcmCHGt7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PGVovEoilIPIjt7kfuEIuwNnhI+4CbaW73DPOwFH5IMoaAKY9kWSV28QN0lLsphpImpdMPYlto9PE/4mmud5dNUrbuZ8+d7NGA48VUJjFSgCP+Sz3AnfRPk3kcIyeo07lfEeOhIvXeNO7w5OSQqoTkTq3kQKWADkwGbK8+NQl4j5YHKIf8OyQB755Y+7txXb2X4kaWgcjZFdIw46F+NJqLzoh/C7/XsGrDk4A7iP1XaPkEm0oVuasGHty07aKzlsXl6GejxJZ5lexhdhzd40FoS+IEu1bV2bkCe6SJTa4FSBYWzdxKrqrg5+XzkLFOAbXWz32tZT9OdFkj+8B6wfGWUrOe9ACFlxygycZYXs4krS/j X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2d642ef5-1a52-49e4-e529-08db692397eb X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2023 19:56:19.8574 (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: u530dqdTyF9Vx21F9xSFVxtWsfL3EXm+j3/AhNMcWL92R+lEIfoPUtEgWOlQDgVx X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5264 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230609_125636_702880_E8241A06 X-CRM114-Status: GOOD ( 14.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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[] = {