From patchwork Mon Mar 4 23:44:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13581398 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 950EEC48BF6 for ; Tue, 5 Mar 2024 00:51: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=RGhcMxZO7auO4f+slnJLupivoFqCu0htndV0dE4xuCc=; b=fJHWCiKMFYVVcK RIcU1U2y0VTlfiySarLjB332kHFBa3MzHdQF9UKfji5knapnTJGXJ63WkBbyq6hmNhC1oX0Ua0Fz0 ajxfej/2qyRygabhD18VERfqAb454/VLKa3EgNCcxvvECkKiXER/eEud9tlUHOW78kX8ejbRNY1EA Gfuiw9+KTmNbLfLYH5ffqk0Vc5hoWKngDWU4BZMyfraufYKCWn9CDpIKI/EU6lN0Ed+1+dHd7JvA3 WbV9wGx0SgJlFAPhIiRL3TFCBANvRrcWeKN4dY457yMKvNlunEcvxP1AfDzVbkd4x6t7XKxX6pTHq /3SMWou3rakST5xN2QhA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rhJ1E-0000000BHYW-1zaN; Tue, 05 Mar 2024 00:50:56 +0000 Received: from mail-bn8nam11on20601.outbound.protection.outlook.com ([2a01:111:f403:2414::601] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rhHzG-0000000B7Kx-0TK6 for linux-arm-kernel@lists.infradead.org; Mon, 04 Mar 2024 23:45:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P129rT1tsOI2S1xX0e/o4FIa5QEavFutLVIYG5VNeRP0dl4hMMU+OVUb7iXnW2pxNZl1KYiIG79Acm9N8mUDJChm62X3zvWm3+gVZ8aoa4xKD5hGE+VCEmV5eIlXav+lgXUVXnQHPnHC9SBGj3PXWiWnhNH4g0ICEdY/k7FnCIzyg6tkIs0DN40l1tWd5i0R4auEPmrg5nVehMSFszj9KeCT0Au74pg1b1O1PZLrhk7BholjggEXqQOwbLAIsMi3Aw/p7bGfN+pNF480v4A+SeVX+LvGTvFPby2pi8xZni45jc2+GoX5eIoyi1XaFAhTv30W1SGkRi1AXTcHNDKQuA== 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=cOo5/ZtnB4k9EoUv3CZhd0c+iW3BoAwAPvBhbX299gA=; b=mOrrqn3yhfyscGbTWnX1MaUxy9Cn17zQCpR3Ivj8ZW/3jxRljYoMtEegaw/JqptGZn5mgtOPUhL0rwevtmIKOhL2/XLqgwAxiFnkTdFP19B0HX9Ry4yr4Pb+HCKhmtPIcqyPZReVNcaZTZtIisSqgNqbcjI7UB4RtQHIlwMdQ6XUHSQZUsE0CaZ3zjQucPzy/t4xbeSg1kDHPNA6FnayhITJ1FpsXiwKMn/6udFa07iYP/dNkIAOxNiFJ3t2plP1rZjv5AY0oa5Rv2EH7KZanIYdJVmJz9RvuczFMHyDwMvpOyW6fnQNC84Cnz1fIqBvpDCa5O18eF7G6VcaC5Hbeg== 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=cOo5/ZtnB4k9EoUv3CZhd0c+iW3BoAwAPvBhbX299gA=; b=q/vftsRtJeLQDG31aG+FBhaoow+Ng+P1Is41SjI8AfgGrv7Ob9hCDM2PJAAPKM7c2176IZqUhd4v8Ig3lxqWZ6okp+6NIMYQXv67//h/AOOe4jCBpDoTr7s7InvSFU6oORc98Fj9iRRJsbEYV+PmPf/lCDKgxdPoRGfbwldQNumL9bTvasRNDy4Src3tvoDJ4PNxU/lf6Gqex62IW55BwlJmnrhnYwWl4h27m5eJvb6fq/OxRZBix+7sivtBSQP6hG8hTdJFXG9Wm1DbadZu4Z88eu6HJMUl3GAChTkZz2C2syickX9c1WS3QLZysRvMpISOuGYZvPpGmlw+mrs3xg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by DS0PR12MB6584.namprd12.prod.outlook.com (2603:10b6:8:d0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.39; Mon, 4 Mar 2024 23:44:25 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c33c:18db:c570:33b3]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c33c:18db:c570:33b3%5]) with mapi id 15.20.7339.035; Mon, 4 Mar 2024 23:44:25 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Eric Auger , Jean-Philippe Brucker , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi Subject: [PATCH v5 18/27] iommu/arm-smmu-v3: Make SVA allocate a normal arm_smmu_domain Date: Mon, 4 Mar 2024 19:44:06 -0400 Message-ID: <18-v5-9a37e0c884ce+31e3-smmuv3_newapi_p2_jgg@nvidia.com> In-Reply-To: <0-v5-9a37e0c884ce+31e3-smmuv3_newapi_p2_jgg@nvidia.com> References: X-ClientProxiedBy: BL6PEPF00013E0D.NAMP222.PROD.OUTLOOK.COM (2603:10b6:22e:400:0:1001:0:11) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|DS0PR12MB6584:EE_ X-MS-Office365-Filtering-Correlation-Id: 68ecf098-385f-4bd3-1ce5-08dc3ca501fa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: st0ItxhNopp7Mx4eqFxuHLOl0oq81sjtoQRsIkGACxwsGqHKfdIoiHMxMrbernonNUzJIndZgUw07gbuCgDNyC/lrMdcTZ5J34XF7X7Kk9JeuYtGDApTmsvqajnYnPBdoTHggrbFrbKuWc2GzNYhuqLV63qhPwhbRolvwA0QY7R0tOHegM/BFNBwcwTWCeSrd2UVCGWhhYQz47fDZrISxLeBbHIu+LzgMvkbuLHkWUmFNP5llZVsl8PBMM8plyvDi3W5JbcK6z8j3jFB2CdWsIGLfTY1YVw8tKHK/3aYK7B1gw555umxwQgDySIGNshP8PsRp3AwU2uEsBRvANVEjt3wfspRO3SaOhhhwpAKuTGLNve3omBAffxM/M5EmwyT0oNUMS9WX4SEMxgjEaKGpTfIe+huBCTrYHhXA/Rh8fhaMlNF3BkyLppXqqIu1cLAx9ICsccN1zARDPQbUyoyqZRi4ELmQK/B2S0E0eYgYu4Gevim3kumL67UMxTeCEGm9OHckTAY0S1mU1M2YcFVKErYoj6ZL0UQ5joEB2u27G0Q2vLTexJs/ubt41CSm0oKul08FxA7IlpYu9C1BcIMBFLB4IqSdTNPGJW7vt1IQYIvrwhrerXx1BfY2y+ySqgnCDkk/17NZsNRYtmRm7p1r0ZeosWnbf5DISIjvjRjllE= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bTwoEiEaDZBabmGRQE2yW5k5vmLbP1T0Fl3wC0vMhF4kKKiQuDMUXZva2tzikZ+5NA73e2Y1J85hRMvQqp2cYCTQV8/+Wwya+AFkmVNHv+TJHd14D7uC/8cfY4ZkDOiyb8DfAijIyGSwmaAEHcQ9RZMwp+NKd3UGehEK2ROkzX8MOVAGph31/FgCUlxV/yqpr3k3mXdfHaR83CqFvmoL2kJF2PNrHSc9F1T+KPEbdosohzwka5VFuLxO4ysPMr2rsSX+aahXBB5GkvdUOqi3l0V/dAczKR/RVM70iHqiXtv7n6QGFtQw/FRszds7OsScTRpE+PMFwbef7XN1BWbgmuLOxA4TIAWoUjRxIO0jV7Aj6biKgtc4xQsCzgJmPpNQImu16ACNa4QJh+YPIX8kmcW0A3TK8PSVylrjac3GWWjZ94nsA8H/2caMWfyAyb6YatiV/TWpqJYKGvNjuw5UAgwXWaIYzxaRkUvMuAmz50N6dyX4NBRbuY6oOtV7Z67Dx7FiI4JhxSajEcKVTIWHDctg+eJKYiOv3+bMlbD7a3MD2wscvOQLfQcoiyyiGnpom2ei7E438Ge2iXmE79ftT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Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2024 23:44:18.0983 (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: 8vKmzzJmay7KaxNSaKjh70c036cHicym/ScqfQKEo+BgASOU3wKV4Td/Quyqjs6u X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6584 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240304_154450_631717_9695FF9E X-CRM114-Status: GOOD ( 16.43 ) 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 Currently the SVA domain is a naked struct iommu_domain, allocate a struct arm_smmu_domain instead. This is necessary to be able to use the struct arm_master_domain mechanism. Tested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe Reviewed-by: Michael Shavit --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 19 ++++++----- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 34 +++++++++++-------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 4 ++- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index 82b9c4d4061c3d..d633316f2e45bc 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -654,7 +654,7 @@ static int arm_smmu_sva_set_dev_pasid(struct iommu_domain *domain, static void arm_smmu_sva_domain_free(struct iommu_domain *domain) { - kfree(domain); + kfree(to_smmu_domain(domain)); } static const struct iommu_domain_ops arm_smmu_sva_domain_ops = { @@ -662,14 +662,17 @@ static const struct iommu_domain_ops arm_smmu_sva_domain_ops = { .free = arm_smmu_sva_domain_free }; -struct iommu_domain *arm_smmu_sva_domain_alloc(void) +struct iommu_domain *arm_smmu_sva_domain_alloc(unsigned type) { - struct iommu_domain *domain; + struct arm_smmu_domain *smmu_domain; - domain = kzalloc(sizeof(*domain), GFP_KERNEL); - if (!domain) - return NULL; - domain->ops = &arm_smmu_sva_domain_ops; + if (type != IOMMU_DOMAIN_SVA) + return ERR_PTR(-EOPNOTSUPP); - return domain; + smmu_domain = arm_smmu_domain_alloc(); + if (IS_ERR(smmu_domain)) + return ERR_CAST(smmu_domain); + smmu_domain->domain.ops = &arm_smmu_sva_domain_ops; + + return &smmu_domain->domain; } diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index dd7f841cd19b3c..2db2b822292a87 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2291,23 +2291,10 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap) } } -static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) -{ - - if (type == IOMMU_DOMAIN_SVA) - return arm_smmu_sva_domain_alloc(); - return ERR_PTR(-EOPNOTSUPP); -} - -static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) +struct arm_smmu_domain *arm_smmu_domain_alloc(void) { struct arm_smmu_domain *smmu_domain; - /* - * Allocate the domain and initialise some of its data structures. - * We can't really do anything meaningful until we've added a - * master. - */ smmu_domain = kzalloc(sizeof(*smmu_domain), GFP_KERNEL); if (!smmu_domain) return ERR_PTR(-ENOMEM); @@ -2317,6 +2304,23 @@ static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) spin_lock_init(&smmu_domain->devices_lock); INIT_LIST_HEAD(&smmu_domain->mmu_notifiers); + return smmu_domain; +} + +static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) +{ + struct arm_smmu_domain *smmu_domain; + + smmu_domain = arm_smmu_domain_alloc(); + if (IS_ERR(smmu_domain)) + return ERR_CAST(smmu_domain); + + /* + * Allocate the domain and initialise some of its data structures. + * We can't really do anything meaningful until we've added a + * master. + */ + if (dev) { struct arm_smmu_master *master = dev_iommu_priv_get(dev); int ret; @@ -3288,7 +3292,7 @@ static struct iommu_ops arm_smmu_ops = { .identity_domain = &arm_smmu_identity_domain, .blocked_domain = &arm_smmu_blocked_domain, .capable = arm_smmu_capable, - .domain_alloc = arm_smmu_domain_alloc, + .domain_alloc = arm_smmu_sva_domain_alloc, .domain_alloc_paging = arm_smmu_domain_alloc_paging, .probe_device = arm_smmu_probe_device, .release_device = arm_smmu_release_device, diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 7e1f6af4ce4e79..c47e07d695bef2 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -759,6 +759,8 @@ static inline struct arm_smmu_domain *to_smmu_domain(struct iommu_domain *dom) extern struct xarray arm_smmu_asid_xa; extern struct mutex arm_smmu_asid_lock; +struct arm_smmu_domain *arm_smmu_domain_alloc(void); + void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid); struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid); @@ -791,7 +793,7 @@ int arm_smmu_master_enable_sva(struct arm_smmu_master *master); int arm_smmu_master_disable_sva(struct arm_smmu_master *master); bool arm_smmu_master_iopf_supported(struct arm_smmu_master *master); void arm_smmu_sva_notifier_synchronize(void); -struct iommu_domain *arm_smmu_sva_domain_alloc(void); +struct iommu_domain *arm_smmu_sva_domain_alloc(unsigned int type); void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain, struct device *dev, ioasid_t id); #else /* CONFIG_ARM_SMMU_V3_SVA */