From patchwork Fri Jan 26 18:15:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13533247 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 69EB6C47422 for ; Fri, 26 Jan 2024 19:20:19 +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=37tXa9KZBySv8xOWrR5uW2+vxqL5gQN/roxNjaeyMBE=; b=wnUNKrQZJLMeJW TPHqudwxCTqlQOkCQ1XtaZldv3w4X0BZczN/TEB/HSpthcX/o4V71JjmLKGP3dIGoCOeH5dIJMBIJ 5EnuWNAqifg4f7Z08O7KIRGUEyokzYhXX3hlwiz55mms/Dt8LZtBQgrXtSKzEgdxd38aR+Ck9yJfD R3yYpV5XfKht9g0qU3+M6Fdm4yHe1GrEdX/LVDYcHzkIplTCfy9YiMHG1qnT+Az8X4A1xGPB/Vd1Q R7pCTDDblT4lyJdOdWapk29fMB1Vw8n34b1EeCGytpIlRlO8+pZIL2eJwonBP4DNoofw+Jk5o5lqN d/EWR4bIjZg3nd+F3YJw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTRkE-00000005C3k-2VHL; Fri, 26 Jan 2024 19:20:06 +0000 Received: from mail-dm6nam12on20600.outbound.protection.outlook.com ([2a01:111:f403:2417::600] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTQkE-000000051Ud-3VWO for linux-arm-kernel@lists.infradead.org; Fri, 26 Jan 2024 18:16:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T9n3mBRWxtn+QMD2GVALBJxusn85IgeH7Re8cRB4rK1/iKqF7ZUZE8rQZnprMYgT+AGKUL7jKKKXGHGc14cuPCglC0b5oYeH0BEcgR0nBCB1folTdEL5+hvPN0UvkiD1IjrNoqHnqVnoESG44eaPppHkLpxcjt7a/r9pJH+A1ZNvW4+ma6eGIjpLsOH87+Zlzfd1RBZ5Y8pfw9prFKrkfzVmm7F0k0W7RpYpmQ+OgkHBHhVyt6G/IK66ZxrA1KBjMC7SX0Cky8jCHl9HYgZJvObcjEmM/amgg58OEVfbyxGoF2Y1D4ByMAKSKU0xlV/UkPn0mXdZ7e47/f/R/RLdEg== 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=roQg2tDJboKURfA9TrqNkPNL7aeVUAVLO8hVw983YzU=; b=VplN/6FDrKdnkZupiYs22O9nKEkeX7sIyIGsrHaKcq+pxeNjSI/IqFqrAyBaxnlWs3uL/Z5AXLKB4F73kiTceUrzzBNMcUDH/0E92aEzbTf25H9BmAK+6Hd2ZxRSkKgr2tJVtP/ia5aFg7n9p03Kxar+NAOdI4Y83tQypwB0twDGia1OKTdITs9mhrlSOs4WXwfunH15xjitd5gQsX496d1qZDcs+j1Cpau0QyvsdwyqiGNzxZRfqIgztvwjnriWPN8z7EDmgdGJrIpU5piVssDnWM/optmAsNTiGHsa9vjNwU276EK43922jVcVKG11s419zngN4j4lHsl4BLKbMg== 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=roQg2tDJboKURfA9TrqNkPNL7aeVUAVLO8hVw983YzU=; b=QEpwZ/CEhqYNzRakMH22cUW+parab5zXSVckyQESDDiJ5neMt1qeW2O1oAOuKACGBdT4FBGkWEI4mmJeKaEgMS6sk3QOsfXRdVOVOTaKiCjOMFG66//EdsODYweDJ3fjjSuTG+SqcZ8ud832ql+FXnYgi/XayZfEP5tzdDwKDdnFmiYiNwItaISGg0asa3F2ZAdFi/J/X0VnollhoZK3vsQFJJeaSIRxkKI/mdcuht01gjX3ce5gF9PqyrOAIUXKL5B6Bhq+ziO1LjD9rFroRMW+NunJThg1U01u7EwMS+aCc0ZsxRLyNwLAFFe2zYAtPkEnC6Vptn3jLie0hyJPzg== 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 IA1PR12MB8079.namprd12.prod.outlook.com (2603:10b6:208:3fb::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Fri, 26 Jan 2024 18:15:34 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7228.022; Fri, 26 Jan 2024 18:15:33 +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 v4 18/27] iommu/arm-smmu-v3: Make SVA allocate a normal arm_smmu_domain Date: Fri, 26 Jan 2024 14:15:20 -0400 Message-ID: <18-v4-e7091cdd9e8d+43b1-smmuv3_newapi_p2_jgg@nvidia.com> In-Reply-To: <0-v4-e7091cdd9e8d+43b1-smmuv3_newapi_p2_jgg@nvidia.com> References: X-ClientProxiedBy: SN6PR16CA0070.namprd16.prod.outlook.com (2603:10b6:805:ca::47) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB8079:EE_ X-MS-Office365-Filtering-Correlation-Id: c4d97cda-2e6e-4947-ce02-08dc1e9ac858 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zH+cpbs5IjbPCWtnEbJ2g0mDZCj197s4JJu0duRq/cMuW5AniU8G/0nCYuMWACE+A2HRaelWfh3TuXzos3FA/AiH4xMKWSVaKqke5YpDAnDYaUXaVtZKLZwwZoNQTfFKxUUahuqMUplbyBVJekvRi3uSLtpXnNrBGA/XXlDUDA1y/kMtFizq/4fsa2xRMk3pqblzrL04W6CSv1ddFzRd62gBlH+iCElRU0z5nsCELxPiy6fJHZ85IghxCLSOw3YQgtzrrSqKNfhL8OXPRNoJDdIDVmj4qFhexxAXz3OlyzbTl/M3ZcrKbfgLdgpxqsgLt2zNvnxPTjEJGJ+pepBTQ7aZ0BYcjRcj4+eQk46hZ95jsPsZ19if7atlS+gYthZ4fqyC8e6zfm3AF2XS424D9UN6xw2ffKTVAygqhu6T7ytgj1rKVFggoM+iIXGiShHlS2KgLl4YFF73x4VnohPY/YuLU/5zsX4hcLrTwG+7sqHjry4ZxTM4AMWS0D/xhOH1BVrRj89SMXqR+WctQGpbqMIH12CNoCRCOoX4Zk7B8wyiOYVmuXoEmWW/tnIhr5t3 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:(13230031)(346002)(136003)(39860400002)(376002)(396003)(366004)(230922051799003)(1800799012)(451199024)(64100799003)(186009)(83380400001)(6486002)(6512007)(38100700002)(54906003)(2616005)(5660300002)(8936002)(478600001)(2906002)(8676002)(4326008)(7416002)(110136005)(6666004)(6506007)(316002)(66476007)(66556008)(66946007)(36756003)(26005)(86362001)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qGfCGRWjmzg3wF64MtY+QaS2HBNuyMabLS6VqVCFxiQn8WazYEYC74YmoP9KrTTRD792x3MaC+Si02YSk7+WXiSOD+FdO7XyNb+/G4s7UApGChjwxuNajwjTQAfiCJxxbXjYeRNK9VLMkmmkXWtuwmGdKIBDc6yvgSmNtR/jT1Ufx0fvTXjDd9ZGQGce1qDKiPC2g/0a74aSeHs3bEs47r+TNy9rokQyuUV5rQ6xVY/t60OcN/2tmxYZgPiP8b4km0TbxO1t1hWODPS1r8o0MnP3/tlxFAYFA5/QQx+1m+zLb6+d6YfiomTxxSBwFFiJ0IEq+TdEFfMZrC0o33xjxyjMO1aytwiElfpKQOw+D2/rdzfn2I0J03oD9CKAW/YaPi7AqGwAaXC4EtKojBVVGZgApumq6yJHt4yCR4U+X7LkdN9yaYUwxOHVOVEMJpd/OK0DhN5znF8J+NWuJRzuS2lHpdbzgIeYekEtZcOWj3RWS5hbIAGYqDW9n6yK6+/R47svJezSeTgdzK7AhsVIpLV1rJ5GLOW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g: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c4d97cda-2e6e-4947-ce02-08dc1e9ac858 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 18:15:31.5814 (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: qmYPq2tmaeguVovHl5fd5kqm0daEDWqn5iMFnN8/gGHv31YRvnmNE9JOkt8sLMEQ X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8079 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240126_101603_018744_E1A1A10E X-CRM114-Status: GOOD ( 15.72 ) 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. Signed-off-by: Jason Gunthorpe --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 17 ++++++---- 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, 32 insertions(+), 23 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 6d54a6105ceadd..1163c7d70359f4 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 @@ -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 21b0ab9c2ba763..a8e9276990b006 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2280,23 +2280,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); @@ -2306,6 +2293,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; @@ -3278,7 +3282,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 69351386dc1441..cb08b9305e0208 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, int 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 */