From patchwork Mon Dec 20 21:15:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 12688625 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 41760C433FE for ; Mon, 20 Dec 2021 21:16:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.250001.430567 (Exim 4.92) (envelope-from ) id 1mzQ1B-0007KU-R4; Mon, 20 Dec 2021 21:16:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 250001.430567; Mon, 20 Dec 2021 21:16:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mzQ1B-0007Gz-FG; Mon, 20 Dec 2021 21:16:25 +0000 Received: by outflank-mailman (input) for mailman id 250001; Mon, 20 Dec 2021 21:16:23 +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 1mzQ18-0005IB-Ra for xen-devel@lists.xenproject.org; Mon, 20 Dec 2021 21:16:22 +0000 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [2a00:1450:4864:20::232]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 14a0a55c-61da-11ec-85d3-df6b77346a89; Mon, 20 Dec 2021 22:16:22 +0100 (CET) Received: by mail-lj1-x232.google.com with SMTP id u22so18047883lju.7 for ; Mon, 20 Dec 2021 13:16:22 -0800 (PST) Received: from otyshchenko.router ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id b35sm635132lfv.209.2021.12.20.13.16.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Dec 2021 13:16:21 -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: 14a0a55c-61da-11ec-85d3-df6b77346a89 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=ruH/ZtUTmX8iN6zofPsz6r1KAf8lKOAgjKOqJDL6kwU=; b=CDMSfqEUyrVBM25MEGIzHLeoHcUFlBF7AVUEDESUE2sPkWXL1Pj7uRg78VNv5JoKuc 54fvBdonm1Nq4ZFPMqV5wAT0Burub2MDNaPv3jjEddM4NEa4TLhHI/nQIAGNranFaIv3 +JXNyPkx9D5HBA/g/4ar7r/RDoZ3Z9N8I6JA/QgJNtlJRziKacOOxL/xiKvpeibC6htM JnUDFzpcJqsHwPYmUrz2IxA+MQSteMNkPsvdiRFcYB9H28gvILoJVOoqN6Cl3MK0ajI3 CfgvX7UrBZdqSEGs4wwbU/zALJm1rUmGQOGszcuDxqlTITemRI+rvjGe9AsDNfT+0ccm HwnQ== 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=ruH/ZtUTmX8iN6zofPsz6r1KAf8lKOAgjKOqJDL6kwU=; b=zhjPMWyp+8AOBFtbc+e+Z2nfiME/orkJ5Yx2V/kfJ79Rj/M5THNnsDJWidNJ7y+MgO VfqEAujqKsDYqDEBlAWxjsDECF9KvWmFWbpYPx3L/vWWkYWurJ0c8A8DhtHRmkw5nEKg Ahdm62dSqQ7iuDhrylDTJOuBBHi7yAc+jCdzL+SN8QRa4A8xj+Td3lgGill1DZ5ZqvgC 06uWkULJiZ5Ab3m9dABvcfzovdKDe7hLt7XC0AhOQpq2GyiTthGYAI5uMBMeHdhf4Ke3 LvUMZWXlWGWnqNuLvEEykF9Gt1YSRNb13a0tJ97mh9cSgA6FIMnylKAioBbZBEFc9/9V 5RMg== X-Gm-Message-State: AOAM5318VfgoU2m2ST7N8KYvOdK4spF3QC1W4sch8EWFkAx9jtn8QLg8 tJUQtC+6XQDB4crs9pLVetr7Tuf2MvY= X-Google-Smtp-Source: ABdhPJygzn941uf9Tjg3K5YR8Nj0KXaAS2tnW+3lvktFAgQUqXlC3Yrmbyf+ZosfHupnIONO+S2H8g== X-Received: by 2002:a2e:3c17:: with SMTP id j23mr16332638lja.391.1640034981391; Mon, 20 Dec 2021 13:16:21 -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 V2 09/10] iommu/ipmmu-vmsa: Use refcount for the micro-TLBs Date: Mon, 20 Dec 2021 23:15:56 +0200 Message-Id: <1640034957-19764-10-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1640034957-19764-1-git-send-email-olekstysh@gmail.com> References: <1640034957-19764-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() --- xen/drivers/passthrough/arm/ipmmu-vmsa.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/xen/drivers/passthrough/arm/ipmmu-vmsa.c b/xen/drivers/passthrough/arm/ipmmu-vmsa.c index 649b9f6..1224ea4 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; }; @@ -467,13 +468,12 @@ 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. - */ - 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 +484,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 */