From patchwork Thu Aug 17 18:16:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Shavit X-Patchwork-Id: 13356867 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 42185C2FC0F for ; Thu, 17 Aug 2023 18:22:13 +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:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=2qQus3iUciiovzSjeBrbJkQi0o79uJEby6uu11blU/Y=; b=XBveftSyzMR4EMfGfVfqyikuUu 3ga8uzS81gOpzjjf/zDGH/FPfGkooytjKGWS9dJI/pjWckBnV0909jE/Fv0mdBovC3SpQGzLpJFtg bDuntKfyGFLxHD2adJU72b2gImNBJk1VPj9LSXq9i5DqLm2XsjRLv67+tgi/k/IY1+Ciw3IW3SPPS 15HaGFO9bF6iPMxHePExJeE09qLUEv9nZDNcSHgcmXe1KoIwVnWppCr9K4vhrD/IhVeCCz7g1GbDZ 1Gxkdlx+MuJtH0T6ME9jOWGxkVkUAEenWIp0dSu6xa+oBTtaqV3EDP56d/DUbCQYwjbnwPQ8RGagC yerIJbVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qWhcy-006xXz-2n; Thu, 17 Aug 2023 18:21:48 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qWhcn-006xT3-2Q for linux-arm-kernel@lists.infradead.org; Thu, 17 Aug 2023 18:21:39 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-58cf42a3313so1483817b3.0 for ; Thu, 17 Aug 2023 11:21:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692296496; x=1692901296; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=KUbNCncRdoFX1+f2g3pRLFzwoP3ZTCWn6yNRKIIgaR8=; b=szQhiT9g55SNiHgWkEz0kzx/pdJeQMPRZT87WkTbJfU5llAAIBmjRjgiQpTzpF5YN9 jnHWSW4RBGrl6wHgCm0b7DGDja4uzbX3KiaPHrY+tRwAS5ROOmoBpwFcWEuGquvUQoW3 pe7iA4pHhX5sYBiHgb5CEJaRdVTc5M7PLGuWkpCjPNbYCwOvg0u3nXy5uC5Ylbnl5joJ FwUTm8R7v07kv/Kwe1FErP0xhPfqlzOjNSztxiwntrbqdWE6FD0+E7joEgqK2swPc/xu kWoNfbm78S8JqLwataTwW78ctZTGc6ehN2UYe/Tguy+OLMeSudr8wa4I8hVdXC/5tmSE yZFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692296496; x=1692901296; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KUbNCncRdoFX1+f2g3pRLFzwoP3ZTCWn6yNRKIIgaR8=; b=duiWNoBjMcDHyB4kFiETT+xq90WIjrYJ1/FfApg99YDpLcuD61x3ch0CGpnJYOcROe urEiziHNLAkiHlvy9D5bkv030c3X1itx7R2kHcSHu0x87EgpeMqCMVq72d/s/l0n/OpA dPEf8N2ISDXNeuubVq1enN42NU345c2CfNRAPXNtSB20bReafL5Ztli7TVlBQv/dcSLK oOiBpxKWqUAxO1b7PHYxbcXRnd9/WK2Sbb1fiB1RqN1texO17CmaVn7Va36JlTiNJBO1 86TmshKarKDNWNOdVE8HpFA1UfDY3upHlXBrUiYrMa7HpKnqiR/yS+wXeUN43q2Ec4+l SfUw== X-Gm-Message-State: AOJu0Yy2Hd16QXtIpES7lnIsmIIEqhWiAk2OfgM40Nespx+X91EAOl4d u1DzStz64QmK9jxmsikWvl8k+/xq8Y7a X-Google-Smtp-Source: AGHT+IEu0J32esLhZqyNCqxShUB/3M3HqZKWXXA5yaIU1uOsU/89OPq9VhM26WkG7OBEwWdWhp4PpsKGG9U1 X-Received: from mshavit.ntc.corp.google.com ([2401:fa00:95:20c:4a77:fd20:7069:bdf9]) (user=mshavit job=sendgmr) by 2002:a81:ae53:0:b0:58c:b5a4:8e14 with SMTP id g19-20020a81ae53000000b0058cb5a48e14mr2800ywk.2.1692296496312; Thu, 17 Aug 2023 11:21:36 -0700 (PDT) Date: Fri, 18 Aug 2023 02:16:28 +0800 In-Reply-To: <20230817182055.1770180-1-mshavit@google.com> Mime-Version: 1.0 References: <20230817182055.1770180-1-mshavit@google.com> X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog Message-ID: <20230818021629.RFC.v1.6.I65dd382de382428dcb3cf61342b35405903ac768@changeid> Subject: [RFC PATCH v1 6/8] iommu/arm-smmu-v3: Free VMID when uninstalling domain from SMMU From: Michael Shavit To: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: will@kernel.org, jgg@nvidia.com, nicolinc@nvidia.com, tina.zhang@intel.com, jean-philippe@linaro.org, robin.murphy@arm.com, Michael Shavit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230817_112137_817485_89FE70AD X-CRM114-Status: GOOD ( 12.50 ) 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 This will allow installing a domain onto multiple smmu devices. Signed-off-by: Michael Shavit --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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 208fec5fba462..7f88b2b19cbe5 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2112,7 +2112,6 @@ static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) static void arm_smmu_domain_free(struct iommu_domain *domain) { struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); - struct arm_smmu_device *smmu = smmu_domain->smmu; free_io_pgtable_ops(smmu_domain->pgtbl_ops); @@ -2122,10 +2121,6 @@ static void arm_smmu_domain_free(struct iommu_domain *domain) mutex_lock(&arm_smmu_asid_lock); arm_smmu_free_asid(&smmu_domain->cd); mutex_unlock(&arm_smmu_asid_lock); - } else { - struct arm_smmu_s2_cfg *cfg = &smmu_domain->s2_cfg; - if (cfg->vmid) - ida_free(&smmu->vmid_map, cfg->vmid); } kfree(smmu_domain); @@ -2484,6 +2479,14 @@ static void arm_smmu_installed_smmus_remove_device( continue; list_del(&master->list); if (list_empty(&installed_smmu->devices)) { + if (smmu_domain->stage == ARM_SMMU_DOMAIN_S2) { + struct arm_smmu_s2_cfg *cfg = + &smmu_domain->s2_cfg; + + if (cfg->vmid) + ida_free(&smmu->vmid_map, + cfg->vmid); + } list_del(&installed_smmu->list); kfree(installed_smmu); }