From patchwork Wed Aug 23 16:47: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: 13362829 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 5AD11C3DA6F for ; Wed, 23 Aug 2023 16:49:26 +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=rmW6X3eIifAXZJl2zeShDz7tgy942gpMGJUAlDUhcV4=; b=vNyV37ICvQGaRe g3o5dX82KtMNLhJidyH0sYJ18fodnBcPH+C0cvrSUUmKGxfZ6jiBy8/CJObsrYh75VncAVE9vaOIx yiICgvBhGPhEBBlK1rk4RF5Gl/AnDzBQf7EnVigYjKmWKK/Om9qUVdkCOp8yIeA5NiFcOYOHwqaSw JnROqkLdBSerNjOJRZf+nR6fJ2WP+XXHeD5bVFI14k/+Dg5QLcyU/m5bKaLTmmGIcfzPRmdIrF/wB aZKzCWBVy58XeMmc5EbGuCfxv547Ucjp7Lw3tjwfg3qhrEV+rFYTGgOMxVZl34W6RYd4A5qK2VkbT B2gzy4bowmWCsCdleXGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYr2l-0017T6-2b; Wed, 23 Aug 2023 16:49:19 +0000 Received: from mail-bn8nam12on2061b.outbound.protection.outlook.com ([2a01:111:f400:fe5b::61b] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qYr1V-001692-39; Wed, 23 Aug 2023 16:48:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PJrfoqtpy+XWYNIh+NkH0L1ORuD8OkmhNBlb7GvaQSbcvxcSMwXmzUSkAsTNRg33ONsu/rCloR2TOpGWtx0qT3u0mzlSdS3ORyOJXDwlSCEIliWJStRpTJVW77l89iV9cTx4fr9wwhjLdsLmDWZoD5ITvisq2Kw9vyIAlM2w8IlbmOk4kJsYPc6dLiWPt4+IjPoqmLUd9fTOoCcvpr31N7EUtM02JHsPvtXizLemtRFM7i8FjCUfe3+bCN9HMWl9WFC0UAn5hPJ/DmI1dtDebDN38uJv/3vgBK4DRgMoO1ARR4pdckyc8GZ0sAYwadm3yOMF5Xk+R3JC326HzNTrUQ== 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=5bQTaN5b+qgoSyEQwOCYPGzeYBlCGBqHAqDsYdB9PPg=; b=MVJH3CVBfFS/WvUToHLMfw1x2NFcAedB+Z6/besK9LFCr7KIRVmJLd2LeGpayOw2td5NM0wi2y/QH1tHCZ9LAn3W5x/kmcBB31DQOygQhGn2394OBt4u5EQPBTbYVf4xsnhaWCbDzPH/wHtVTHqj4Vmh1cw83ensdn1pX91hbhXwbaNiduV/R78EMgJe6RvOAtQc+mE6hh/6Kz5XQecSwMNsf/sbxlD5jutyX9hqW0kHUR9r77oNn2ZiykIdUtyJAKI9Vu4IwzOMHijGM59nv2j2UgEQV8jt2nMbR8kqNLoXGOTVtso/mngt1OALr208eZPXGV+ml2xyx8sWDoLOWA== 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=5bQTaN5b+qgoSyEQwOCYPGzeYBlCGBqHAqDsYdB9PPg=; b=TLtG2C5BC97ZvUjPJEK/YrSbZJjJjn0k6O1FE3k9Tfid/qiErC750s7vICz/nfq61VIbEYUlZOwISSr4dRXG/TiCAIywwibYxOp8KmO7THWoUjDNERFYB46HwYeptuympQ8v+pH9frt0L+u+N9k4a2sl3O4osd7R7gbApJZyoccbAGNmMEpcZi0q6VyyOO7lIhX/qSPoR++kUlFTYbptf+KekCT2bXQH6hk+zCPaLkAYKUeBJMbcUj2N4WA0HqtgybUkB21kJTGTgJpBbKCPqfxNJ2Y0fUENjjGuPKPlpKvOFB/hUZK1bOfBUDaev1fRpZGuVci4nw6a7elrLhqx8A== 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 CY5PR12MB6346.namprd12.prod.outlook.com (2603:10b6:930:21::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.24; Wed, 23 Aug 2023 16:47:50 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6699.020; Wed, 23 Aug 2023 16:47:50 +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 v7 17/24] iommu/ipmmu: Add an IOMMU_IDENTITIY_DOMAIN Date: Wed, 23 Aug 2023 13:47:31 -0300 Message-ID: <17-v7-de04a3217c48+15055-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v7-de04a3217c48+15055-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: CH2PR20CA0005.namprd20.prod.outlook.com (2603:10b6:610:58::15) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CY5PR12MB6346:EE_ X-MS-Office365-Filtering-Correlation-Id: 6ece3239-a17c-4cc7-6634-08dba3f8ab98 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Pc9xJ/IhEaugfqaEPBecSHVIKZWE+Mrzu1NIUexm79tDRUaVjeDqN4rtI7TVV2LoGu234fFC+KcGjckLUTS0Rg3kjpZmtu/j1A/wMMaJJqwXz6UVlFe7oNL94KC+Qv1XRkg0BmxvF9DvNhbaunyk8TPlqIyAsU071sf+rM0dXC0ocd++ZjZi25vKCCSHP+kLadBc89E1RwRqBil6ERSdVwPHeG7HSbPHtEzxQCdIr72EKVdJFjaxpqk5BoZRUF+sH1fE42THBvwCVJcFN7F35MsY2YY8dU1K5GWE05lxshWHejg4d7kS10UkqbIwwuUbyGTSKoX/pdYMJzqBVjgL0+C1VeMMlHrbufr6a5V6GetcJMC2MMTAwOPuMOTQo1/ZufHJn7IdBGcB5zqm9gjinm/Qi1CCFQDVIAPytx4kDIF10YgH2w7DqnWFlf4mAQJrr1fHent7n0+6AMOjaMdDkFeob5fHtLM3TL/y65wDWcAHzrQN+DI/pvpAwX3k6+ChicO2qmJn0YH1pbVeUztAVJpS4RMI4Zp65b7C/dN66nJEnFsQRfCmBCO1gAG/hREtigKQFPZx3iXqm6DaeZUDQyzpSa+pQvbBjl3GZC31YwM= 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)(376002)(396003)(136003)(346002)(366004)(39860400002)(186009)(1800799009)(451199024)(54906003)(66476007)(66946007)(6512007)(316002)(66556008)(110136005)(8676002)(8936002)(107886003)(2616005)(4326008)(36756003)(41300700001)(921005)(478600001)(6666004)(6506007)(38100700002)(6486002)(83380400001)(7416002)(2906002)(7406005)(86362001)(5660300002)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ulibByqR9kfBqGCRoqGqusa4rUuuGFsRwV4yoGDFpFjHUNuwX8rF85q9X4p6bdiA1pX2T3CTXlw1OD9mZaNFP8Ci7zghpuQPzWSOxPne8XnpwectgV8bvmVWfnIa8GQ3iPJcOKWDcI9u5iKaJ5ZL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tDCKpbefWwReJewb3gQ5nc5Lz4LaZhlZ3wGXKqn/5XOkX0oMfQJT37iP8cMIYNeeRiUK3Uhfsel271Z44+whN78x623wXjujq5upKpbBzIqpGyjse6jf4M57QSi6aJnZ5vtoabZ48DYwKFUXLA81OZtYMB8NlN+ep8ON9SfzwDGI9jJe8l+/wSvdd8pL2bHJ7PisQy8//SFpzYxN2jKBl0GwIT4P1vbmg7+VlRvASL72drzTYC2HLonzNSIOn/aCfx3OdlhPPowWMGiZ+CfRfach2zZ0J4IWY2kLPPmcuBBcloS33nNga0rm2s2KG4KrTy1Nn3aXBjY2UDU7KaLfBtPbgmIBBZqWI X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6ece3239-a17c-4cc7-6634-08dba3f8ab98 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2023 16:47:43.2424 (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: E63CjxhqA0km6CBQtVd5ENlexCsuEHgcwRzFDqFPloPRZXgCdJ+dJ8qQHvlKC3Cl X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6346 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230823_094802_029026_9CDA2F54 X-CRM114-Status: GOOD ( 13.34 ) 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()") Reviewed-by: Lu Baolu Signed-off-by: Jason Gunthorpe Reviewed-by: Jerry Snitselaar --- 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 65ff69477c43e4..04830d3931d239 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -295,6 +295,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; @@ -627,6 +639,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) @@ -849,6 +891,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,