From nobody Thu Nov 14 07:05:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1684269363; cv=none; d=zohomail.com; s=zohoarc; b=TBUE4Eq2mCzsNrMeaOhVUX7I5Nlxvw0nh9/Q/HmB+aohGfyIqc8Q1uLJkU1FT7S6vM/vxFAZqnwhzul0VrdoCHxkC+eoa4BTUyH6HlhavCVbSIByj+Oee3HAaoBL1reZlAuBUGvRMekGGIp2n+jcbpsr0CLYi2Wj+KiG5j2khYE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684269363; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OQ2D9EHEdJzHVZOExkFVKMD+djzRyiuPzFS6Inmm1QM=; b=QxiUG9AbDUy2TVWX1n414YD+ZMTpOT5k0X0J5EMa2WgkWzY4S7TymhTQYgvdEI1I0QlXkJMeji7NFzx/s0QMnsi4YLJh5QvjqvO5trNtGQzIUTff4z8h/PDqbgtXS8ZyX+fVpNpXURWhVfnhG/aoBs815vrKHUd4V6QqDupWlSg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684269363814800.2206009387962; Tue, 16 May 2023 13:36:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pz1NE-0006Dz-9P; Tue, 16 May 2023 16:34:20 -0400 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 <3xehjZAgKClAA46ABsxsy66y3w.u648w4C-vwDw3565y5C.69y@flex--smostafa.bounces.google.com>) id 1pz1NC-0006C1-M9 for qemu-devel@nongnu.org; Tue, 16 May 2023 16:34:18 -0400 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3xehjZAgKClAA46ABsxsy66y3w.u648w4C-vwDw3565y5C.69y@flex--smostafa.bounces.google.com>) id 1pz1N9-0006iT-G1 for qemu-devel@nongnu.org; Tue, 16 May 2023 16:34:18 -0400 Received: by mail-wm1-x34a.google.com with SMTP id 5b1f17b1804b1-3f42b226871so83695e9.0 for ; Tue, 16 May 2023 13:34:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684269253; x=1686861253; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=OQ2D9EHEdJzHVZOExkFVKMD+djzRyiuPzFS6Inmm1QM=; b=Jik8YTluH9sQkda4j/34MF9rf8CeqgRVbBS2zt43xt/U+y7aLVct2tsOkT5q+kMphE th6TcwDetiZgu+Z9OO8Qcpnqz2aS80UfNl1xs9HS6I+VoF7W+0+xNyBqM8uk05vXiXP/ I5tfpmjUcvS9X6IWFGeewEihsCVjaag0bETp7GFi5TShl+6xxfLKSgpdTXsl4n+mmBna 4xuj3FOs6eSVLvSzmLG57SDRloWjvaej207akmHZNsZeywySJQlcuYhsm8pcnnrDWGbm +aFaHBMGcDi3V2SuZUYhRZteuqaVPbWn+ksd7IbwLuWuV3lAO4btLnOvqx4Oc6lNeKUG zOUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684269253; x=1686861253; 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=OQ2D9EHEdJzHVZOExkFVKMD+djzRyiuPzFS6Inmm1QM=; b=MgmWGPWl9ZIND7qWj2MyuCdL2CL7oDH6OXLtNKYIy8MwTWZqVnug2c6KWHF0kDk3WZ DeH0qoAVJml16aS1Exp4pYH0Kuj+7E8q3MhvFidtLKgx2VAl+d2Pl71O455kITNcbmeJ lv+0sWcN1W+nzKuWH3Tus986GXFBoGc8huDankweTXN+on0/3wXz+fTQfLD6387zFV1y npkA/X3RT87i+K8zpRsSMLfO1eBDWV3hmMNDMej0x9FrhgPLSijtoOriQh9U6VupLb2d LzIYZU1PXTxn8nw5camIB1fQuYmBqAcEo1Y5xoph44CXFgTp1WW44tX0lL72DLQJbh1T 4OOA== X-Gm-Message-State: AC+VfDwFyx+ikKH357k5vhJco/yzTdhp5ebMU2tqcsxL9AyNkcR7oKR6 duqmgnvNbShxRAzZ0TeZ70oOUU/I6jUvFtHZNZnXaxlwUZjcxvnXozD7HAphO4oqEpzroSOcxfo jUSQfO+Ff1ysDxN0YTPSrYBAia8y1kK8ifd5FlrkFBbnsHieRhtpnriNwQK9gOeYE+w== X-Google-Smtp-Source: ACHHUZ7c+t661mAg5Ou4PIuaPf7ex29s/pdeQVFkh743yb1FR7gbNuOwG/JfzXphL17xD7wnXpJ7PnlDKVgDSw== X-Received: from mostafa.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:333c]) (user=smostafa job=sendgmr) by 2002:a05:600c:22d6:b0:3f4:f0c2:11e with SMTP id 22-20020a05600c22d600b003f4f0c2011emr3051988wmg.2.1684269253261; Tue, 16 May 2023 13:34:13 -0700 (PDT) Date: Tue, 16 May 2023 20:33:16 +0000 In-Reply-To: <20230516203327.2051088-1-smostafa@google.com> Mime-Version: 1.0 References: <20230516203327.2051088-1-smostafa@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Message-ID: <20230516203327.2051088-10-smostafa@google.com> Subject: [PATCH v4 09/10] hw/arm/smmuv3: Add stage-2 support in iova notifier 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, richard.henderson@linaro.org, Mostafa Saleh Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::34a; envelope-from=3xehjZAgKClAA46ABsxsy66y3w.u648w4C-vwDw3565y5C.69y@flex--smostafa.bounces.google.com; helo=mail-wm1-x34a.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, T_SCC_BODY_TEXT_LINE=-0.01, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1684269364308100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In smmuv3_notify_iova, read the granule based on translation stage and use VMID if valid value is sent. Signed-off-by: Mostafa Saleh Reviewed-by: Eric Auger --- Changes in v3: - Collected Reviewed-by tag. --- hw/arm/smmuv3.c | 39 ++++++++++++++++++++++++++------------- hw/arm/trace-events | 2 +- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 3643befc9e..17e1359be4 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -999,18 +999,21 @@ epilogue: * @mr: IOMMU mr region handle * @n: notifier to be called * @asid: address space ID or negative value if we don't care + * @vmid: virtual machine ID or negative value if we don't care * @iova: iova * @tg: translation granule (if communicated through range invalidation) * @num_pages: number of @granule sized pages (if tg !=3D 0), otherwise 1 */ static void smmuv3_notify_iova(IOMMUMemoryRegion *mr, IOMMUNotifier *n, - int asid, dma_addr_t iova, - uint8_t tg, uint64_t num_pages) + int asid, int vmid, + dma_addr_t iova, uint8_t tg, + uint64_t num_pages) { SMMUDevice *sdev =3D container_of(mr, SMMUDevice, iommu); IOMMUTLBEvent event; uint8_t granule; + SMMUv3State *s =3D sdev->smmu; =20 if (!tg) { SMMUEventInfo event =3D {.inval_ste_allowed =3D true}; @@ -1025,11 +1028,20 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *m= r, return; } =20 - tt =3D select_tt(cfg, iova); - if (!tt) { + if (vmid >=3D 0 && cfg->s2cfg.vmid !=3D vmid) { return; } - granule =3D tt->granule_sz; + + if (STAGE1_SUPPORTED(s)) { + tt =3D select_tt(cfg, iova); + if (!tt) { + return; + } + granule =3D tt->granule_sz; + } else { + granule =3D cfg->s2cfg.granule_sz; + } + } else { granule =3D tg * 2 + 10; } @@ -1043,9 +1055,10 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *mr, memory_region_notify_iommu_one(n, &event); } =20 -/* invalidate an asid/iova range tuple in all mr's */ -static void smmuv3_inv_notifiers_iova(SMMUState *s, int asid, dma_addr_t i= ova, - uint8_t tg, uint64_t num_pages) +/* invalidate an asid/vmid/iova range tuple in all mr's */ +static void smmuv3_inv_notifiers_iova(SMMUState *s, int asid, int vmid, + dma_addr_t iova, uint8_t tg, + uint64_t num_pages) { SMMUDevice *sdev; =20 @@ -1053,11 +1066,11 @@ static void smmuv3_inv_notifiers_iova(SMMUState *s,= int asid, dma_addr_t iova, IOMMUMemoryRegion *mr =3D &sdev->iommu; IOMMUNotifier *n; =20 - trace_smmuv3_inv_notifiers_iova(mr->parent_obj.name, asid, iova, - tg, num_pages); + trace_smmuv3_inv_notifiers_iova(mr->parent_obj.name, asid, vmid, + iova, tg, num_pages); =20 IOMMU_NOTIFIER_FOREACH(n, mr) { - smmuv3_notify_iova(mr, n, asid, iova, tg, num_pages); + smmuv3_notify_iova(mr, n, asid, vmid, iova, tg, num_pages); } } } @@ -1088,7 +1101,7 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cmd) =20 if (!tg) { trace_smmuv3_range_inval(vmid, asid, addr, tg, 1, ttl, leaf); - smmuv3_inv_notifiers_iova(s, asid, addr, tg, 1); + smmuv3_inv_notifiers_iova(s, asid, vmid, addr, tg, 1); smmu_iotlb_inv_iova(s, asid, vmid, addr, tg, 1, ttl); return; } @@ -1106,7 +1119,7 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cmd) =20 num_pages =3D (mask + 1) >> granule; trace_smmuv3_range_inval(vmid, asid, addr, tg, num_pages, ttl, lea= f); - smmuv3_inv_notifiers_iova(s, asid, addr, tg, num_pages); + smmuv3_inv_notifiers_iova(s, asid, vmid, addr, tg, num_pages); smmu_iotlb_inv_iova(s, asid, vmid, addr, tg, num_pages, ttl); addr +=3D mask + 1; } diff --git a/hw/arm/trace-events b/hw/arm/trace-events index f8fdf1ca9f..cdc1ea06a8 100644 --- a/hw/arm/trace-events +++ b/hw/arm/trace-events @@ -53,5 +53,5 @@ smmuv3_cmdq_tlbi_s12_vmid(uint16_t vmid) "vmid=3D%d" smmuv3_config_cache_inv(uint32_t sid) "Config cache INV for sid=3D0x%x" smmuv3_notify_flag_add(const char *iommu) "ADD SMMUNotifier node for iommu= mr=3D%s" smmuv3_notify_flag_del(const char *iommu) "DEL SMMUNotifier node for iommu= mr=3D%s" -smmuv3_inv_notifiers_iova(const char *name, uint16_t asid, uint64_t iova, = uint8_t tg, uint64_t num_pages) "iommu mr=3D%s asid=3D%d iova=3D0x%"PRIx64"= tg=3D%d num_pages=3D0x%"PRIx64 +smmuv3_inv_notifiers_iova(const char *name, uint16_t asid, uint16_t vmid, = uint64_t iova, uint8_t tg, uint64_t num_pages) "iommu mr=3D%s asid=3D%d vmi= d=3D%d iova=3D0x%"PRIx64" tg=3D%d num_pages=3D0x%"PRIx64 =20 --=20 2.40.1.606.ga4b1b128d6-goog