Received: by 2002:a19:c345:0:0:0:0:0 with SMTP id t66csp1845264lff; Thu, 5 Dec 2019 02:40:29 -0800 (PST) X-Google-Smtp-Source: APXvYqyOYC7GNsAbOz1OHwQYSDJZQBgv/R3qL948FW/vpJ93CC8WzYMFs+fAQ3Oouw/2rIgdfR6k X-Received: by 2002:ac8:6ce:: with SMTP id j14mr6955023qth.231.1575542428576; Thu, 05 Dec 2019 02:40:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575542428; cv=none; d=google.com; s=arc-20160816; b=WgvvkUlYmoz+78OTRim04wloGS96ZwH4d2MYLjOBHguWvuLh5dtFvwMONJ5El65Pj0 D8X0eoGET2XrRNKfOIKd7f9T4SIIPqBunufu0HfR8FNmMXMyRpMzii5ZAbLkcbo44PE1 eAUcigFQAPmj3IHtDSys//ac9wJIBbU0OP9mSjYAwbAuZ6FzxdRZla7utMEoCGWAOMZW Yyu/cfhmSPunQhJduqV28TTy7Nn3v6HSeuymaIjjjtN6Whj22RXlURYcHf4AFyvNkM9C wJzqSbbMeu8REYR5YEk47psnfqyvpA0/oP64VrVABM2pDZ5RLpRvAbdhPOTH+NXksnzR BRAw== 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:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:dkim-signature; bh=FWPcJ3ALPwUSQ0HyCh09oGg4lLyEV91wWtHkL2sGBRc=; b=JjAFhEDS/MzEL+/TC+6zoFPVy+mNIhGCcA53BX8HU+1bBxkYetCElK9QZpBuBpi+l1 lKxsHmoUWFFjVuE2bUyzye9JVMz/YHm+QVctzMyfkdRskGrHocB9JY/IkqiyxLes9y70 wEij50LRXiB0ZrxSMD49GhRrJq8dNMMHVnOz6VEY8UTqhnqH8hb3vldRUs2E/P113Dpt BhRkupYM00Ps2uL9kJkycWdCqPocGqY52246AuDmKNiafcipvn3uzh1abkZUQG9m5YE6 vVrzhi1rXIcAXSRsF6V6edOih8jyce1Tx0mIEObJJToYq5vdbH9xAhIvrAtz6Pk9zus3 GLWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iQfoSjwO; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b15si4265354qkg.157.2019.12.05.02.40.28 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 05 Dec 2019 02:40:28 -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=@redhat.com header.s=mimecast20190719 header.b=iQfoSjwO; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:52780 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1icoYe-0003i0-14 for alex.bennee@linaro.org; Thu, 05 Dec 2019 05:40:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57066) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1icoYH-0003f9-2H for qemu-arm@nongnu.org; Thu, 05 Dec 2019 05:40:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1icoYF-0000ms-BQ for qemu-arm@nongnu.org; Thu, 05 Dec 2019 05:40:04 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:28292 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1icoYF-0000kj-1W for qemu-arm@nongnu.org; Thu, 05 Dec 2019 05:40:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575542402; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FWPcJ3ALPwUSQ0HyCh09oGg4lLyEV91wWtHkL2sGBRc=; b=iQfoSjwOjMYgJF6+D0xMfLem7jpfemZhzGZOkf5DyajCDfBgrFBtw4ER01aDQdU83j9EJc cbyw7ALQo8UFSQ8lsZDxSXlAIJo+2lSGlNOlW7a5/LSTKGjYJ0t4KS+ZQ39y2IR5/gt2Kx LCnm3YG+XP/4KyqRuSgnwfOMHn48SCA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-322-ZNbHaoY1OZuFyVuHb8N5Mw-1; Thu, 05 Dec 2019 05:39:59 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1D76018543A3; Thu, 5 Dec 2019 10:39:58 +0000 (UTC) Received: from [10.36.116.117] (ovpn-116-117.ams2.redhat.com [10.36.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 04814600F0; Thu, 5 Dec 2019 10:39:56 +0000 (UTC) Subject: Re: [PATCH 3/5] hw/arm/smmuv3: Align stream table base address to table size To: Simon Veith , qemu-devel@nongnu.org, qemu-arm@nongnu.org References: <1575467748-28898-1-git-send-email-sveith@amazon.de> <1575467748-28898-4-git-send-email-sveith@amazon.de> From: Auger Eric Message-ID: Date: Thu, 5 Dec 2019 11:39:55 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <1575467748-28898-4-git-send-email-sveith@amazon.de> Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: ZNbHaoY1OZuFyVuHb8N5Mw-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list 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: tUJLQB2LGRY6 Hi Simon, On 12/4/19 2:55 PM, Simon Veith wrote: > 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; Maybe just as the spec use MAX(5, (LOG2SIZE-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); nit: you may use ~MAKE_64BIT_MASK(0, strtab_size_shift) > + } else { see below > + 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 { Can it happen? I understand LOG2SIZE <= SMMU_S_IDR_5.SIDSIZE and SIDSIZE is max 32. Same above? > + strtab_base = 0; > + } > + addr = strtab_base + sid * sizeof(*ste); > } > > if (smmu_get_ste(s, addr, ste, event)) { > Thank you for those series fixes. Best Regards Eric