From nobody Fri Nov 29 14:39:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1638035559; cv=none; d=zohomail.com; s=zohoarc; b=awt9HEBBRMMXoOq7k0N3gC5aRGEV1NGFWVdhigUH/dgCNVWEtS9x83MEscHSTNmjviLnbuSI13TR6gCtIPX7cGOADTIUpe6MjG39eOLMsXw3QLaoaewq4qQTsA8ZcYROOHpD3HCIy1D0TOe8X2Pks4NA1QVphCPqWx1GTWGP61I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638035559; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=2J9/qwJjzL1vy0hvabGaR4en8taUbQNdDtr6iBACZRU=; b=T+zQC4/mst5kYu/DSkSLwUwvf1WQsKzxyIzjeQ6/54/zfan3KaTXJ+m2QjLOUP8W5aI+INuo02G9qvNThnbHpPqisTshrk97FvzT6Q4E/2kB7uXvs0LqbgbHuASFTf41X7AcDA2RSTXo7QHnQ93Yev8ODDpl+4c5sQjnjuavvtU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1638035559562630.5836939578901; Sat, 27 Nov 2021 09:52:39 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.234025.406249 (Exim 4.92) (envelope-from ) id 1mr1rn-0005zi-4P; Sat, 27 Nov 2021 17:52:03 +0000 Received: by outflank-mailman (output) from mailman id 234025.406249; Sat, 27 Nov 2021 17:52:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mr1rm-0005vN-O4; Sat, 27 Nov 2021 17:52:02 +0000 Received: by outflank-mailman (input) for mailman id 234025; Sat, 27 Nov 2021 17:52:00 +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 1mr1rj-0004Ig-OI for xen-devel@lists.xenproject.org; Sat, 27 Nov 2021 17:51:59 +0000 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [2a00:1450:4864:20::12f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b7db9b79-4faa-11ec-b941-1df2895da90e; Sat, 27 Nov 2021 18:51:59 +0100 (CET) Received: by mail-lf1-x12f.google.com with SMTP id l22so32523574lfg.7 for ; Sat, 27 Nov 2021 09:51:59 -0800 (PST) Received: from otyshchenko.router ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id f18sm827075ljc.104.2021.11.27.09.51.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Nov 2021 09:51:58 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: b7db9b79-4faa-11ec-b941-1df2895da90e 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=2J9/qwJjzL1vy0hvabGaR4en8taUbQNdDtr6iBACZRU=; b=BtBsFq74Y6vVV5z3EGw5Q8X/k/ZggHQUkBWk3YD2BpquPPvebfxJ7V2SodyTff6/ad nxbAG+IPeEB8DhtvtHNcDI0tDtjLDafxSokUPzfemqzDBRXPMdBtVJCsfor09UYIMgZ9 a39ejS2BlunDOIIGofTcxjhwb9kUfpIurujLkJVGfgENP3xvV/4W4hCSnNVnVkJ9M/7P oRuP092PAvNZJEKcd/pyKlyzil1rzsOzonrkPjM+Q4A04tWs3wLJFHzyz8X4AfoPB0Jt G2m8GbPBrJf6+fbl6L6Rc1waGSMJ957VSRo1lPVyM1q6E8meJYHzo63Bpn0pFEeto1O8 XLcg== 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=2J9/qwJjzL1vy0hvabGaR4en8taUbQNdDtr6iBACZRU=; b=jwQ9nSbT9AboHeJp6AzmRAfZVfmbcHdisY/302VhJdczjyjgyBZ54URl4WvmBu0XrD SFRgVDqjd27fLFRQGSFPeQ4Yw5C8FolC7Rnv7lrYp+gdmgWMKyc+LLWJN91QkXy+916n r0LOCZpTTyfttGELjv1LBdiktl71UgtXSvGKZ7VxM3SczsKMKr290ljUToZb79LSuiUF LQtj0cYCPNWbg9SkltoakZ7Zm3xNTtkrGvoFGDTgfnnE2TVAlyCR4Z1M1TtrKYLc2efI xERl+0VsO6ojIXo5fPiozVKsECaHyOxgPXb5agy0SPhxJgPBHPUwch/OenVh8QHPDZHY iOYQ== X-Gm-Message-State: AOAM530oxSJD0xQH9j7D3CwWottf2KEhyBkr3UlpZVORcjZDJLRlyA4B F+NF4tAYOoMGZ3EvwaacQgn5O/Sy44s= X-Google-Smtp-Source: ABdhPJzRAgmVvEZRPEQsyvpTeU07E/9l7RI9tG/ffWq//vqNRNWFQk9exo+DCDQM70ASOm68dF3Q5g== X-Received: by 2002:a05:6512:2255:: with SMTP id i21mr37246692lfu.438.1638035518550; Sat, 27 Nov 2021 09:51:58 -0800 (PST) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Cc: Oleksandr Tyshchenko , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Yoshihiro Shimoda Subject: [PATCH 09/10] iommu/ipmmu-vmsa: Use refcount for the micro-TLBs Date: Sat, 27 Nov 2021 19:51:44 +0200 Message-Id: <1638035505-16931-10-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1638035505-16931-1-git-send-email-olekstysh@gmail.com> References: <1638035505-16931-1-git-send-email-olekstysh@gmail.com> X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1638035560630100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- xen/drivers/passthrough/arm/ipmmu-vmsa.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/xen/drivers/passthrough/arm/ipmmu-vmsa.c b/xen/drivers/passthr= ough/arm/ipmmu-vmsa.c index 22dd84e..32609f8 100644 --- a/xen/drivers/passthrough/arm/ipmmu-vmsa.c +++ b/xen/drivers/passthrough/arm/ipmmu-vmsa.c @@ -134,6 +134,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; }; =20 @@ -477,13 +478,12 @@ static int ipmmu_utlb_enable(struct ipmmu_vmsa_domain= *domain, } } =20 - /* - * 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]++ =3D=3D 0 ) + { + ipmmu_imuasid_write(mmu, utlb, 0); + ipmmu_imuctr_write(mmu, utlb, imuctr | + IMUCTR_TTSEL_MMU(domain->context_id) | IMUCTR_M= MUEN); + } =20 return 0; } @@ -494,7 +494,8 @@ static void ipmmu_utlb_disable(struct ipmmu_vmsa_domain= *domain, { struct ipmmu_vmsa_device *mmu =3D domain->mmu; =20 - ipmmu_imuctr_write(mmu, utlb, 0); + if ( --mmu->utlb_refcount[utlb] =3D=3D 0 ) + ipmmu_imuctr_write(mmu, utlb, 0); } =20 /* Domain/Context Management */ --=20 2.7.4