From patchwork Thu Jan 27 19:55:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 12727231 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 0EF67C433FE for ; Thu, 27 Jan 2022 19:56:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.261720.453390 (Exim 4.92) (envelope-from ) id 1nDAsg-00026G-S3; Thu, 27 Jan 2022 19:56:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 261720.453390; Thu, 27 Jan 2022 19:56:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nDAsg-000269-PB; Thu, 27 Jan 2022 19:56:30 +0000 Received: by outflank-mailman (input) for mailman id 261720; Thu, 27 Jan 2022 19:56:29 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nDAsf-0001qT-84 for xen-devel@lists.xenproject.org; Thu, 27 Jan 2022 19:56:29 +0000 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [2a00:1450:4864:20::22b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 36c40072-7fab-11ec-8f75-fffcc8bd4f1a; Thu, 27 Jan 2022 20:56:27 +0100 (CET) Received: by mail-lj1-x22b.google.com with SMTP id c7so5392215ljr.13 for ; Thu, 27 Jan 2022 11:56:28 -0800 (PST) Received: from otyshchenko.router ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id j18sm897631lja.26.2022.01.27.11.56.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Jan 2022 11:56:27 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 36c40072-7fab-11ec-8f75-fffcc8bd4f1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=eo+OIjpWTXwwmP6Pj09KcPNoGuASdj6ZBH9bhBu2VCw=; b=iDUfuS+F3RXhOl1S+NtxvwmywXVfdpg/1suc17SJauTt31SRjVBqOSPkY8HPRZ3yht V5rDuJcBddF2xl3DbceoNuYAQUUSF5qiU0E52+J/aACS257yTq1T6Nn+iPxdZdaE9kDL hf2T1BPiO/T3Sa86kIZztllTb4j+uouEzdxgh0tu6ZzNjiEgvtVjlw7zn91CzZZFcjz7 Sc3dQrctP6ihBiQKEFE7e8XdNr9NhI0fceClfyLTbSsdSxuC0UT5saRMxGnNvELm1Jad QjtHBIJJlYfR5e8F03PVzrDbj4OQvKjuaXZsyB+YTvqlJ8GtE0X8NwZyY5ixxO3wH5XY E68g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=eo+OIjpWTXwwmP6Pj09KcPNoGuASdj6ZBH9bhBu2VCw=; b=LTtVdKlzLSCs+4OXazw/x2pcIVG3MmA420q+U6x3tvugG2ngkekTTnD4kwigxvaFxA 6kVGCJb5FlUEJnuRYcp8HHnxxtB9WCckOj3G/e3fsDV+uZti8WjHLg8YSZGC19jYy5eI LK2/nYBeAK+O1K1SECCDDlrkQd3L+M3CnW6pB7OaPQzlJUZHMqnHXh4/+OPmgxtADkwl UsrTobqukwEiN9lAO4ujOXwNgP2T9JBpAye7sOc7M4hEIEBhM6gm/vC7VpU+/eYTNpN7 DSjycmtkPiZJba6CKTv+eWpR5AzutOXaP3mj2D7WnYPvmGAvyK9tZjPT3pktMbDzVIdX 1HXw== X-Gm-Message-State: AOAM532KGCYVmToaa67mwl3PT/bK82mP+yh9oqbeqyz/4rBuWNKRBKnP lxhT7eqixU7o7bLS2r0K2WA1ARnN9Vk= X-Google-Smtp-Source: ABdhPJyd1lR2ZBeKpiYRAK/LysWfxNy0vopwBbbkjjazDv5ZCPLS4hfEdTurAUDwwUCv2rBBBlQH1Q== X-Received: by 2002:a2e:a786:: with SMTP id c6mr3545836ljf.385.1643313387620; Thu, 27 Jan 2022 11:56:27 -0800 (PST) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Cc: Oleksandr Tyshchenko , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Yoshihiro Shimoda , Oleksandr Andrushchenko Subject: [PATCH V3 1/2] iommu/ipmmu-vmsa: Use refcount for the micro-TLBs Date: Thu, 27 Jan 2022 21:55:51 +0200 Message-Id: <1643313352-29940-2-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1643313352-29940-1-git-send-email-olekstysh@gmail.com> References: <1643313352-29940-1-git-send-email-olekstysh@gmail.com> From: Oleksandr Tyshchenko Reference-count the micro-TLBs as several bus masters can be connected to the same micro-TLB (and drop TODO comment). This wasn't an issue so far, since the platform devices (this driver deals with) get assigned/deassigned together during domain creation/destruction. But, in order to support PCI devices (which are hot-pluggable) in the near future we will need to take care of. Signed-off-by: Oleksandr Tyshchenko Reviewed-by: Yoshihiro Shimoda --- Changes V1 -> V2: - add R-b - add ASSERT() in ipmmu_utlb_disable() Changes V2 -> V3: - add comment to the code --- xen/drivers/passthrough/arm/ipmmu-vmsa.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/xen/drivers/passthrough/arm/ipmmu-vmsa.c b/xen/drivers/passthrough/arm/ipmmu-vmsa.c index 649b9f6..c912120 100644 --- a/xen/drivers/passthrough/arm/ipmmu-vmsa.c +++ b/xen/drivers/passthrough/arm/ipmmu-vmsa.c @@ -127,6 +127,7 @@ struct ipmmu_vmsa_device { spinlock_t lock; /* Protects ctx and domains[] */ DECLARE_BITMAP(ctx, IPMMU_CTX_MAX); struct ipmmu_vmsa_domain *domains[IPMMU_CTX_MAX]; + unsigned int utlb_refcount[IPMMU_UTLB_MAX]; const struct ipmmu_features *features; }; @@ -468,12 +469,17 @@ static int ipmmu_utlb_enable(struct ipmmu_vmsa_domain *domain, } /* - * TODO: Reference-count the micro-TLB as several bus masters can be - * connected to the same micro-TLB. + * Reference-count the micro-TLBs as several bus masters can be connected + * to the same micro-TLB. The platform devices get assigned/deassigned + * together during domain creation/destruction. The PCI devices which use + * the same micro-TLB must also be hot-(un)plugged together. */ - ipmmu_imuasid_write(mmu, utlb, 0); - ipmmu_imuctr_write(mmu, utlb, imuctr | - IMUCTR_TTSEL_MMU(domain->context_id) | IMUCTR_MMUEN); + if ( mmu->utlb_refcount[utlb]++ == 0 ) + { + ipmmu_imuasid_write(mmu, utlb, 0); + ipmmu_imuctr_write(mmu, utlb, imuctr | + IMUCTR_TTSEL_MMU(domain->context_id) | IMUCTR_MMUEN); + } return 0; } @@ -484,7 +490,10 @@ static void ipmmu_utlb_disable(struct ipmmu_vmsa_domain *domain, { struct ipmmu_vmsa_device *mmu = domain->mmu; - ipmmu_imuctr_write(mmu, utlb, 0); + ASSERT(mmu->utlb_refcount[utlb] > 0); + + if ( --mmu->utlb_refcount[utlb] == 0 ) + ipmmu_imuctr_write(mmu, utlb, 0); } /* Domain/Context Management */ From patchwork Thu Jan 27 19:55:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 12727229 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 8DF65C433F5 for ; Thu, 27 Jan 2022 19:56:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.261721.453401 (Exim 4.92) (envelope-from ) id 1nDAsi-0002M5-57; Thu, 27 Jan 2022 19:56:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 261721.453401; Thu, 27 Jan 2022 19:56:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nDAsi-0002Lu-1d; Thu, 27 Jan 2022 19:56:32 +0000 Received: by outflank-mailman (input) for mailman id 261721; Thu, 27 Jan 2022 19:56:30 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nDAsf-0001qN-Tx for xen-devel@lists.xenproject.org; Thu, 27 Jan 2022 19:56:30 +0000 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [2a00:1450:4864:20::133]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 379aabe7-7fab-11ec-8eb8-a37418f5ba1a; Thu, 27 Jan 2022 20:56:29 +0100 (CET) Received: by mail-lf1-x133.google.com with SMTP id u6so7420582lfm.10 for ; Thu, 27 Jan 2022 11:56:29 -0800 (PST) Received: from otyshchenko.router ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id j18sm897631lja.26.2022.01.27.11.56.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Jan 2022 11:56:28 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 379aabe7-7fab-11ec-8eb8-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9x3Unk7KT3XMe8edi/04ny0Op6Yqm01LPkdhOdEqFH8=; b=nItGuj/k8uxRgN8VTCw9s0qR1Fbpu7B1F7RuxhrBsjHIryfVgsBTWu9hCspadqILtT 3N+ijPeqKmSLiZqJVIMVOPU2Ut9cgG8fQZ9PG5ZW7bUkHtc6P86L1IJOKEPOMdxBzdbH R9VxIEFSdFnuhzEoYw8A49N1qOwYp7hYEj+vGwXMNEOW1S3qxfQ+gQj5GNVECYGhWYfb E7koa63MAAG3EOs5moEoV8afkX1IQTpReZQSyhuX8gWfPI2LnwrGXnikvceUUFRZnliI IL+F06aCyzk19Ko0PkvEEZZYL2xsAsGDf5eZf5W54hnhQZtHSxz+2c0Szr4GY0iS1f/5 Eh/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9x3Unk7KT3XMe8edi/04ny0Op6Yqm01LPkdhOdEqFH8=; b=WXre7v3PHXCGSh15G9QtjdZoKjoUAzXd93lherOmPZQWN2U3ixVkdyfYnxwefryKsE 95c+ycePP+5xSx0waH8R+PpW2KnOkWySnOiq1h/DsPbdHwQdjYtT1lSjpDkv/OlFIJlJ ivuFE7jJupPreZVI4uU5h0yHnj9H/sNIqN3OdApNFY+p1FMw3xXNot7TMxGhpAgyUbjB BEZWcl1diShWmwwBIP2jOS4vC+SuNJUw2YDaYX9Q7flaxQBw5YlHrkWSsQCESfGt+Eym bYn/rV/qtDI4TGHv4H+pqhRsN404/DL8wdTWHj+aospZTSx6QpWc1tWgKi1cIAl838mt YYjQ== X-Gm-Message-State: AOAM532dshYAbIVJeB6nn9U0DgNN0wiDDUJe63mB0jL044to9mcrCVXJ 1vO8BCLjqmmeTHeVHBtb8fwFpDw1SKw= X-Google-Smtp-Source: ABdhPJwvCtFrFAerya6ye4MW9mbvSwPBeHBGZp6QwFtTmX3fBdWqDyVFbVqQNr6c+go6DbE3Ik1ffA== X-Received: by 2002:a19:4f4a:: with SMTP id a10mr3726025lfk.397.1643313388555; Thu, 27 Jan 2022 11:56:28 -0800 (PST) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Cc: Oleksandr Tyshchenko , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Rahul Singh , Yoshihiro Shimoda , Oleksandr Andrushchenko Subject: [PATCH V3 2/2] iommu/arm: Remove code duplication in all IOMMU drivers Date: Thu, 27 Jan 2022 21:55:52 +0200 Message-Id: <1643313352-29940-3-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1643313352-29940-1-git-send-email-olekstysh@gmail.com> References: <1643313352-29940-1-git-send-email-olekstysh@gmail.com> From: Oleksandr Tyshchenko All IOMMU drivers on Arm perform almost the same generic actions in hwdom_init callback. Move this code to common arch_iommu_hwdom_init() in order to get rid of code duplication. Signed-off-by: Oleksandr Tyshchenko Reviewed-by: Volodymyr Babchuk Reviewed-by: Yoshihiro Shimoda Acked-by:: Rahul Singh Reviewed-by: Volodymyr Babchuk --- Changes V1 -> V2: - add R-b Changes V2 -> V3: - drop platform specific *_iommu_hwdom_init(), make .hwdom_init to directly point to the common arch_iommu_hwdom_init() --- xen/drivers/passthrough/arm/iommu.c | 7 +++++++ xen/drivers/passthrough/arm/ipmmu-vmsa.c | 15 +-------------- xen/drivers/passthrough/arm/smmu-v3.c | 17 +---------------- xen/drivers/passthrough/arm/smmu.c | 17 +---------------- 4 files changed, 10 insertions(+), 46 deletions(-) diff --git a/xen/drivers/passthrough/arm/iommu.c b/xen/drivers/passthrough/arm/iommu.c index ee653a9..fc45318 100644 --- a/xen/drivers/passthrough/arm/iommu.c +++ b/xen/drivers/passthrough/arm/iommu.c @@ -134,6 +134,13 @@ void arch_iommu_domain_destroy(struct domain *d) void __hwdom_init arch_iommu_hwdom_init(struct domain *d) { + /* Set to false options not supported on ARM. */ + if ( iommu_hwdom_inclusive ) + printk(XENLOG_WARNING "map-inclusive dom0-iommu option is not supported on ARM\n"); + iommu_hwdom_inclusive = false; + if ( iommu_hwdom_reserved == 1 ) + printk(XENLOG_WARNING "map-reserved dom0-iommu option is not supported on ARM\n"); + iommu_hwdom_reserved = 0; } /* diff --git a/xen/drivers/passthrough/arm/ipmmu-vmsa.c b/xen/drivers/passthrough/arm/ipmmu-vmsa.c index c912120..d2572bc 100644 --- a/xen/drivers/passthrough/arm/ipmmu-vmsa.c +++ b/xen/drivers/passthrough/arm/ipmmu-vmsa.c @@ -1329,19 +1329,6 @@ static int ipmmu_iommu_domain_init(struct domain *d) return 0; } -static void __hwdom_init ipmmu_iommu_hwdom_init(struct domain *d) -{ - /* Set to false options not supported on ARM. */ - if ( iommu_hwdom_inclusive ) - printk(XENLOG_WARNING "ipmmu: map-inclusive dom0-iommu option is not supported on ARM\n"); - iommu_hwdom_inclusive = false; - if ( iommu_hwdom_reserved == 1 ) - printk(XENLOG_WARNING "ipmmu: map-reserved dom0-iommu option is not supported on ARM\n"); - iommu_hwdom_reserved = 0; - - arch_iommu_hwdom_init(d); -} - static void ipmmu_iommu_domain_teardown(struct domain *d) { struct ipmmu_vmsa_xen_domain *xen_domain = dom_iommu(d)->arch.priv; @@ -1369,7 +1356,7 @@ static void ipmmu_iommu_domain_teardown(struct domain *d) static const struct iommu_ops ipmmu_iommu_ops = { .init = ipmmu_iommu_domain_init, - .hwdom_init = ipmmu_iommu_hwdom_init, + .hwdom_init = arch_iommu_hwdom_init, .teardown = ipmmu_iommu_domain_teardown, .iotlb_flush = ipmmu_iotlb_flush, .iotlb_flush_all = ipmmu_iotlb_flush_all, diff --git a/xen/drivers/passthrough/arm/smmu-v3.c b/xen/drivers/passthrough/arm/smmu-v3.c index d115df7..71b022f 100644 --- a/xen/drivers/passthrough/arm/smmu-v3.c +++ b/xen/drivers/passthrough/arm/smmu-v3.c @@ -3402,21 +3402,6 @@ static int arm_smmu_iommu_xen_domain_init(struct domain *d) } -static void __hwdom_init arm_smmu_iommu_hwdom_init(struct domain *d) -{ - /* Set to false options not supported on ARM. */ - if (iommu_hwdom_inclusive) - printk(XENLOG_WARNING - "map-inclusive dom0-iommu option is not supported on ARM\n"); - iommu_hwdom_inclusive = false; - if (iommu_hwdom_reserved == 1) - printk(XENLOG_WARNING - "map-reserved dom0-iommu option is not supported on ARM\n"); - iommu_hwdom_reserved = 0; - - arch_iommu_hwdom_init(d); -} - static void arm_smmu_iommu_xen_domain_teardown(struct domain *d) { struct arm_smmu_xen_domain *xen_domain = dom_iommu(d)->arch.priv; @@ -3427,7 +3412,7 @@ static void arm_smmu_iommu_xen_domain_teardown(struct domain *d) static const struct iommu_ops arm_smmu_iommu_ops = { .init = arm_smmu_iommu_xen_domain_init, - .hwdom_init = arm_smmu_iommu_hwdom_init, + .hwdom_init = arch_iommu_hwdom_init, .teardown = arm_smmu_iommu_xen_domain_teardown, .iotlb_flush = arm_smmu_iotlb_flush, .iotlb_flush_all = arm_smmu_iotlb_flush_all, diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c index c9dfc4c..b186c28 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -2849,21 +2849,6 @@ static int arm_smmu_iommu_domain_init(struct domain *d) return 0; } -static void __hwdom_init arm_smmu_iommu_hwdom_init(struct domain *d) -{ - /* Set to false options not supported on ARM. */ - if ( iommu_hwdom_inclusive ) - printk(XENLOG_WARNING - "map-inclusive dom0-iommu option is not supported on ARM\n"); - iommu_hwdom_inclusive = false; - if ( iommu_hwdom_reserved == 1 ) - printk(XENLOG_WARNING - "map-reserved dom0-iommu option is not supported on ARM\n"); - iommu_hwdom_reserved = 0; - - arch_iommu_hwdom_init(d); -} - static void arm_smmu_iommu_domain_teardown(struct domain *d) { struct arm_smmu_xen_domain *xen_domain = dom_iommu(d)->arch.priv; @@ -2874,7 +2859,7 @@ static void arm_smmu_iommu_domain_teardown(struct domain *d) static const struct iommu_ops arm_smmu_iommu_ops = { .init = arm_smmu_iommu_domain_init, - .hwdom_init = arm_smmu_iommu_hwdom_init, + .hwdom_init = arch_iommu_hwdom_init, .add_device = arm_smmu_dt_add_device_generic, .teardown = arm_smmu_iommu_domain_teardown, .iotlb_flush = arm_smmu_iotlb_flush,