Received: by 2002:a17:906:dac7:b0:886:babc:7eeb with SMTP id xi7csp3075391ejb; Sun, 5 Feb 2023 01:48:24 -0800 (PST) X-Google-Smtp-Source: AK7set9SeL0GmRPuG3y3lTIF3Dq79qblsXGa4ZRUHFe7hM3n2RfrmUEo9FVsdAoefyqtr8Qsn8Vh X-Received: by 2002:ac8:5b93:0:b0:3b9:d8fc:3206 with SMTP id a19-20020ac85b93000000b003b9d8fc3206mr15054026qta.56.1675590504700; Sun, 05 Feb 2023 01:48:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675590504; cv=none; d=google.com; s=arc-20160816; b=R7DoX8rq4Xa08IaLJdSvXUhsp1q5dLiyleFkJdV5cvn6sXuxtTr5pxQUzZnJSnWo/g MhC8ITxwBUghTgKsoFm1oTzExwnccZb8yvpGP+echfvMje+9Ywuej9lkU1POtXVN7Vb3 EHxyY98Q4pfNrYLl3DolBlSrFb54MYWNo9H8FtzIRyCrGqW6XQ5AW4ttnFlP2UZtl64O 0/vU7covMdUCjCzIG1d+7lzUBa73/hbk+dwWAlpiizXxwvZ1MhplS+ESxref4us12XCB 887lRbD03kFMETH1QEoziqSBXyh7xfi8KVHcVi8Ma5VzGJ13zeVszR9T0ZKhHYIBW6nL km9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:from:subject:message-id :references:mime-version:in-reply-to:date:dkim-signature; bh=Xe6zuyg8OPbp0DHjuj+CgsNjbU0AuOrw/DyH6HSiOxw=; b=akLg82YTcentoG0qqEIsgiZu+RL6OnV3wCv3S8y7GY7x83ZGKJG852MNWNG+wSsKcn gfWhdML0jx5+fKAG8RplRDrInXr30QecLQAF86MVraIVWXkEfLmDUSgI9UH6/j+x6dbn NFqmQwyLpgKTdGe107AIf5WoxyziDH9kFD+5cG7Umf8KEJBuK3RK2aiWnVRx63jYf8im 6DKcTE15FAgANsnNyQdyDoTS3/VeLdeNQaTIYl9TPZ81k4lbuCV9Y96p7bCbCbm7PAgw VKBjAGnTF9836ChqgcHRgsn4xyxGRxuqoPe2PrhfBB+LneSxScnpK7lZjnrad7T0XUmJ vddQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ToMXzEYK; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v21-20020a05622a131500b003b9ba906cb4si5412502qtk.538.2023.02.05.01.48.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 05 Feb 2023 01:48:24 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ToMXzEYK; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pObb7-0005R9-6C; Sun, 05 Feb 2023 04:46:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3zHrfYwgKCmUVPRVWDIDJRRJOH.FRPTHPX-GHYHOQRQJQX.RUJ@flex--smostafa.bounces.google.com>) id 1pObar-0004vc-FI for qemu-devel@nongnu.org; Sun, 05 Feb 2023 04:45:59 -0500 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3zHrfYwgKCmUVPRVWDIDJRRJOH.FRPTHPX-GHYHOQRQJQX.RUJ@flex--smostafa.bounces.google.com>) id 1pObap-0001Zn-QL for qemu-devel@nongnu.org; Sun, 05 Feb 2023 04:45:53 -0500 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5269bcf4247so48386327b3.17 for ; Sun, 05 Feb 2023 01:45:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Xe6zuyg8OPbp0DHjuj+CgsNjbU0AuOrw/DyH6HSiOxw=; b=ToMXzEYK/4Qnu5eDfPBPr7UFIj4fRVD/Yvdn04kbgjm/u9oM+EmeHlkVUDRZU2zuRV 0OzU4mPVT4ka2jUKku0Pl9avdO3ax1Cqq7fgDa9C0I2a7EprrcIejTdesNpVU/PouaT1 dSxOno2EpmMOutQvn4YXUceEtogPnE6puxLBWXEzH7w8opop56mEII8KSfV/Y2YRG9Go yC+YS7UkB7Zf6Jhk1QHNhXNlVJTIl7X17Kn9GERC9UtC4tQSHy1tEuCDxmE0S7cOToMy j2QD4LkJ2jO4wtPZc4LBgcvSd0QTc/wqLHnlq9VwRWkLeKj9cQL5O9dvfGfEbwbCaIQP WJXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Xe6zuyg8OPbp0DHjuj+CgsNjbU0AuOrw/DyH6HSiOxw=; b=CcNFieOUgaYIF7QLGFjg6rpyccC8grAKPkihaM0r+VVV2QZmYCvnmMSmA98O8/Zx66 VoOUK0XZLqumOM0W//9nZy0JLHWDk3IYG7omfSiiTeSx3joqKopMxLKlPjIHGAFJ8jsC oT5kEjoysQ0tvXCxj4P/pPJaymUgfrps1qAiBuZGfVJxFYk4VKWkj5QgD4VtnUkS78Px ZtR+4BXnhb6xpbxZwnROWKvwgWEmFMWKVOEV3f1hOHVsCiU52k1tPNZkPUYqgmiIiZtN 9lB9ueFAcv7Ld2Jkb3uBw4r61YsgBCXdV7vUa8yeX9vHMtBWh3fsBU3veKdOK0uBsFZS Joag== X-Gm-Message-State: AO0yUKUgNNDud0Sa+ymydwluivIlIHwxlE2vcIc2JVBnCOhm7wvjHI8l P/Q5k+eFZSKh8NsXCdRB4/7e4JGGlPZnzWRjKpq2hJtfovxw234niP5T3rjhKzYf6iKsAWcqePb 50ysAMALx5X/cvHLTOsJ5yim7iaVhoT0izhJTc2z25gzcilWGfKIxoobpcTMfKfJumQ== X-Received: from mostafa.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:333c]) (user=smostafa job=sendgmr) by 2002:a25:3413:0:b0:855:fd7e:b84c with SMTP id b19-20020a253413000000b00855fd7eb84cmr20yba.8.1675590348386; Sun, 05 Feb 2023 01:45:48 -0800 (PST) Date: Sun, 5 Feb 2023 09:44:08 +0000 In-Reply-To: <20230205094411.793816-1-smostafa@google.com> Mime-Version: 1.0 References: <20230205094411.793816-1-smostafa@google.com> X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog Message-ID: <20230205094411.793816-14-smostafa@google.com> Subject: [RFC PATCH 13/16] hw/arm/smmuv3: Add CMDs related to stage 2 From: Mostafa Saleh To: qemu-devel@nongnu.org Cc: jean-philippe@linaro.org, eric.auger@redhat.com, peter.maydell@linaro.org, qemu-arm@nongnu.org, Mostafa Saleh Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2607:f8b0:4864:20::114a; envelope-from=3zHrfYwgKCmUVPRVWDIDJRRJOH.FRPTHPX-GHYHOQRQJQX.RUJ@flex--smostafa.bounces.google.com; helo=mail-yw1-x114a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org Sender: qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: EL5ihkuDCGHB CMD_TLBI_S2_IPA: As S1+S2 is not enabled, for now this can be the same as CMD_TLBI_NH_VAA. CMD_TLBI_S12_VMALL: Added new function to invalidate TLB by VMID. Signed-off-by: Mostafa Saleh --- hw/arm/smmu-common.c | 16 ++++++++++++++++ hw/arm/smmuv3.c | 25 +++++++++++++++++++++++-- hw/arm/trace-events | 2 ++ include/hw/arm/smmu-common.h | 1 + 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index 028a60949a..28089d94a6 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -133,6 +133,16 @@ static gboolean smmu_hash_remove_by_asid(gpointer key, gpointer value, return SMMU_IOTLB_ASID(*iotlb_key) == asid; } + +static gboolean smmu_hash_remove_by_vmid(gpointer key, gpointer value, + gpointer user_data) +{ + uint16_t vmid = *(uint16_t *)user_data; + SMMUIOTLBKey *iotlb_key = (SMMUIOTLBKey *)key; + + return SMMU_IOTLB_VMID(*iotlb_key) == vmid; +} + static gboolean smmu_hash_remove_by_asid_vmid_iova(gpointer key, gpointer value, gpointer user_data) { @@ -185,6 +195,12 @@ void smmu_iotlb_inv_asid(SMMUState *s, uint16_t asid) g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_asid, &asid); } +inline void smmu_iotlb_inv_vmid(SMMUState *s, uint16_t vmid) +{ + trace_smmu_iotlb_inv_vmid(vmid); + g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_vmid, &vmid); +} + /* VMSAv8-64 Translation */ /** diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 8b070f6bb5..2b563a5b1b 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1174,14 +1174,35 @@ static int smmuv3_cmdq_consume(SMMUv3State *s) case SMMU_CMD_TLBI_NH_VA: smmuv3_s1_range_inval(bs, &cmd); break; + case SMMU_CMD_TLBI_S12_VMALL: + uint16_t vmid = CMD_VMID(&cmd); + + if (!STAGE2_SUPPORTED(s->features)) { + cmd_error = SMMU_CERROR_ILL; + break; + } + + trace_smmuv3_cmdq_tlbi_s12_vmid(vmid); + smmu_inv_notifiers_all(&s->smmu_state); + smmu_iotlb_inv_vmid(bs, vmid); + break; + case SMMU_CMD_TLBI_S2_IPA: + if (!STAGE2_SUPPORTED(s->features)) { + cmd_error = SMMU_CERROR_ILL; + break; + } + /* + * As currently only either s1 or s2 are supported + * we can reuse same function for s2. + */ + smmuv3_s1_range_inval(bs, &cmd); + break; case SMMU_CMD_TLBI_EL3_ALL: case SMMU_CMD_TLBI_EL3_VA: case SMMU_CMD_TLBI_EL2_ALL: case SMMU_CMD_TLBI_EL2_ASID: case SMMU_CMD_TLBI_EL2_VA: case SMMU_CMD_TLBI_EL2_VAA: - case SMMU_CMD_TLBI_S12_VMALL: - case SMMU_CMD_TLBI_S2_IPA: case SMMU_CMD_ATC_INV: case SMMU_CMD_PRI_RESP: case SMMU_CMD_RESUME: diff --git a/hw/arm/trace-events b/hw/arm/trace-events index 2dee296c8f..61e2ffade5 100644 --- a/hw/arm/trace-events +++ b/hw/arm/trace-events @@ -12,6 +12,7 @@ smmu_ptw_block_pte(int stage, int level, uint64_t baseaddr, uint64_t pteaddr, ui smmu_get_pte(uint64_t baseaddr, int index, uint64_t pteaddr, uint64_t pte) "baseaddr=0x%"PRIx64" index=0x%x, pteaddr=0x%"PRIx64", pte=0x%"PRIx64 smmu_iotlb_inv_all(void) "IOTLB invalidate all" smmu_iotlb_inv_asid(uint16_t asid) "IOTLB invalidate asid=%d" +smmu_iotlb_inv_vmid(uint16_t vmid) "IOTLB invalidate vmid=%d" smmu_iotlb_inv_iova(uint16_t asid, uint64_t addr) "IOTLB invalidate asid=%d addr=0x%"PRIx64 smmu_inv_notifiers_mr(const char *name) "iommu mr=%s" smmu_iotlb_lookup_hit(uint16_t asid, uint64_t addr, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache HIT asid=%d addr=0x%"PRIx64" hit=%d miss=%d hit rate=%d" @@ -48,6 +49,7 @@ smmuv3_config_cache_miss(uint32_t sid, uint32_t hits, uint32_t misses, uint32_t smmuv3_s1_range_inval(int vmid, int asid, uint64_t addr, uint8_t tg, uint64_t num_pages, uint8_t ttl, bool leaf) "vmid=%d asid=%d addr=0x%"PRIx64" tg=%d num_pages=0x%"PRIx64" ttl=%d leaf=%d" smmuv3_cmdq_tlbi_nh(void) "" smmuv3_cmdq_tlbi_nh_asid(uint16_t asid) "asid=%d" +smmuv3_cmdq_tlbi_s12_vmid(uint16_t vmid) "vmid=%d" smmuv3_config_cache_inv(uint32_t sid) "Config cache INV for sid=0x%x" smmuv3_notify_flag_add(const char *iommu) "ADD SMMUNotifier node for iommu mr=%s" smmuv3_notify_flag_del(const char *iommu) "DEL SMMUNotifier node for iommu mr=%s" diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h index 5cca1c17f5..46ba1f6329 100644 --- a/include/hw/arm/smmu-common.h +++ b/include/hw/arm/smmu-common.h @@ -181,6 +181,7 @@ SMMUIOTLBKey smmu_get_iotlb_key(uint16_t asid, uint16_t vmid, uint64_t iova, uint8_t tg, uint8_t level); void smmu_iotlb_inv_all(SMMUState *s); void smmu_iotlb_inv_asid(SMMUState *s, uint16_t asid); +void smmu_iotlb_inv_vmid(SMMUState *s, uint16_t vmid); void smmu_iotlb_inv_iova(SMMUState *s, int asid, int vmid, dma_addr_t iova, uint8_t tg, uint64_t num_pages, uint8_t ttl); -- 2.39.1.519.gcb327c4b5f-goog