Received: by 2002:a19:c345:0:0:0:0:0 with SMTP id t66csp666499lff; Wed, 4 Dec 2019 05:56:53 -0800 (PST) X-Google-Smtp-Source: APXvYqxTm4ZeDYgS8BTo4iupUOt9xGCmJ7zO/FEE2C/+cM2bcl+QWHm/KQdzOTdh+H3DTUn3EayI X-Received: by 2002:a50:ac06:: with SMTP id v6mr4170320edc.4.1575467812966; Wed, 04 Dec 2019 05:56:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575467812; cv=none; d=google.com; s=arc-20160816; b=NzGmlm0HtMoDmwZIt6OU4VJT1OGL5tqjPzhP1iJTTGJNovw2MfQLwCnTT+8Wq7hCro la1IgacBUPy1UVlWPvc6Dn0E6t9EevbE5VCf7OHfJmKW0PK2Lo12PEEbGhi6dNxrZp2P dmhXMhClyMJOkWDMCsy8H1UY6fIBL8L5bOZmy6HMyj9D/fN8SIU9bgkKhSFuZ8iGQfCT rim2RLmZf4MKKDZZUCsxmifqd7x7FgA7jQL2X5doXB5Ic2RcKYSrq51AQVWCxVvN0jvP 3wzRrUtr+Yt/xOT5fXQ+soKzJj3uYrf0NO7wk7JLAJcVUOTklrSi9EeCPq6LDf5H7njr L/0A== 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:references:in-reply-to :message-id:date:subject:cc:to:from:ironport-sdr:dkim-signature; bh=903Oin9iiuc+khCz3xboU318uHpQzskDGrltjVjcCSM=; b=GN4ghwFLpuftkmHZdhmwVkQAKc3khdPzWNrAxLhAkC2dSaFBBo4k3i7mr5dhFjU3E3 BtMnVCeKO609AbglZwomPSy/2xvndNl+ekAqvTZXKHUOn2QDyUjaor+imY3hoATwZtzs X1pij66MB015qEdG+VjhZWRwSnU8/dZk601POjJcoSm6b2/wNKui3mIaVlGtnH/89Mu8 1Gt4lh6CPF4RMYlV1clOgA0uF+Y0mnKEpkyDXc6+76pKW06Dzxl+8vEttypZfWfFTtP6 Et60GlCBF6SrpVz3Uix1CWp/EUTseh3AUOhsGDgLd27vQ++7vAR1cXS3HbFK1WxyKZXb xLIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=FfLvHL4r; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z7si4463929edr.301.2019.12.04.05.56.52 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Dec 2019 05:56:52 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-arm-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=@amazon.de header.s=amazon201209 header.b=FfLvHL4r; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: from localhost ([::1]:39268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1icV99-0005Tb-DI for alex.bennee@linaro.org; Wed, 04 Dec 2019 08:56:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38439) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1icV8l-00059X-5Y for qemu-arm@nongnu.org; Wed, 04 Dec 2019 08:56:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1icV8j-0005Hh-Th for qemu-arm@nongnu.org; Wed, 04 Dec 2019 08:56:27 -0500 Received: from smtp-fw-6001.amazon.com ([52.95.48.154]:42197) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1icV8j-00058h-Pi; Wed, 04 Dec 2019 08:56:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1575467786; x=1607003786; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=903Oin9iiuc+khCz3xboU318uHpQzskDGrltjVjcCSM=; b=FfLvHL4rlHS3OTiics/U3hMmZjFuBmt6+Mx/jDoVpOWeE04uCSpgsZvU 4TqaJ0Uu0kt19Z0o2DVqQqvFn8tYIiEDySqUi/HUckopc0cInm3/OF9ds 4dvnk4WFnk2nyJ0Y2lkf3I3b8OyHhdnwWAaUAysi1P+ryZK936629hjUt Q=; IronPort-SDR: 14zrM5qDK+M1wIRKinaJl1On6utbiyQqfM9hpWiDqLLMvFtDYSLempEbZ898yszACoWOIFSjRH onZAOInhjG7w== X-IronPort-AV: E=Sophos;i="5.69,277,1571702400"; d="scan'208";a="7621894" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-6f38efd9.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 04 Dec 2019 13:56:25 +0000 Received: from sveith-desktop.aka.corp.amazon.com (pdx2-ws-svc-lb17-vlan2.amazon.com [10.247.140.66]) by email-inbound-relay-2c-6f38efd9.us-west-2.amazon.com (Postfix) with ESMTPS id 292F1A1FA7; Wed, 4 Dec 2019 13:56:23 +0000 (UTC) Received: from sveith-desktop.aka.corp.amazon.com (localhost [127.0.0.1]) by sveith-desktop.aka.corp.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id xB4DuMZO029396; Wed, 4 Dec 2019 14:56:22 +0100 Received: (from sveith@localhost) by sveith-desktop.aka.corp.amazon.com (8.15.2/8.15.2/Submit) id xB4DuMcV029395; Wed, 4 Dec 2019 14:56:22 +0100 From: Simon Veith To: qemu-devel@nongnu.org, qemu-arm@nongnu.org Cc: Simon Veith , Eric Auger Subject: [PATCH 3/5] hw/arm/smmuv3: Align stream table base address to table size Date: Wed, 4 Dec 2019 14:55:46 +0100 Message-Id: <1575467748-28898-4-git-send-email-sveith@amazon.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1575467748-28898-1-git-send-email-sveith@amazon.de> References: <1575467748-28898-1-git-send-email-sveith@amazon.de> Precedence: Bulk X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 52.95.48.154 X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: Lg42T1NX6I8Z Per the specification, and as observed in hardware, the SMMUv3 aligns the SMMU_STRTAB_BASE address to the size of the table by masking out the respective least significant bits in the ADDR field. Apply this masking logic to our smmu_find_ste() lookup function per the specification. ref. ARM IHI 0070C, section 6.3.23. Signed-off-by: Simon Veith Cc: Eric Auger Cc: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org --- hw/arm/smmuv3.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index aad4639..2d6c275 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -376,8 +376,9 @@ bad_ste: static int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *ste, SMMUEventInfo *event) { - dma_addr_t addr; + dma_addr_t addr, strtab_base; uint32_t log2size; + int strtab_size_shift; int ret; trace_smmuv3_find_ste(sid, s->features, s->sid_split); @@ -391,10 +392,23 @@ static int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *ste, } if (s->features & SMMU_FEATURE_2LVL_STE) { int l1_ste_offset, l2_ste_offset, max_l2_ste, span; - dma_addr_t strtab_base, l1ptr, l2ptr; + dma_addr_t l1ptr, l2ptr; STEDesc l1std; - strtab_base = s->strtab_base & SMMU_BASE_ADDR_MASK; + /* + * Align strtab base address to table size. For this purpose, assume it + * is not bounded by SMMU_IDR1_SIDSIZE. + */ + strtab_size_shift = log2size - s->sid_split - 1 + 3; + if (strtab_size_shift < DMA_ADDR_BITS) { + if (strtab_size_shift < 5) { + strtab_size_shift = 5; + } + strtab_base = s->strtab_base & SMMU_BASE_ADDR_MASK & + ~((1ULL << strtab_size_shift) - 1); + } else { + strtab_base = 0; + } l1_ste_offset = sid >> s->sid_split; l2_ste_offset = sid & ((1 << s->sid_split) - 1); l1ptr = (dma_addr_t)(strtab_base + l1_ste_offset * sizeof(l1std)); @@ -433,7 +447,14 @@ static int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *ste, } addr = l2ptr + l2_ste_offset * sizeof(*ste); } else { - addr = (s->strtab_base & SMMU_BASE_ADDR_MASK) + sid * sizeof(*ste); + strtab_size_shift = log2size + 5; + if (strtab_size_shift < DMA_ADDR_BITS) { + strtab_base = s->strtab_base & SMMU_BASE_ADDR_MASK & + ~((1ULL << strtab_size_shift) - 1); + } else { + strtab_base = 0; + } + addr = strtab_base + sid * sizeof(*ste); } if (smmu_get_ste(s, addr, ste, event)) { -- 2.7.4