Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp106979yba; Fri, 5 Apr 2019 03:03:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqyxSp2yzWuOXzqhbA4YEwGTK0HJQDpaxao5Q8GIo9JSrcVmPEmwOGDlgUcHq+Ozd5aFlMfe X-Received: by 2002:a63:530e:: with SMTP id h14mr11055477pgb.136.1554458623920; Fri, 05 Apr 2019 03:03:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554458623; cv=none; d=google.com; s=arc-20160816; b=XejJlwEDl3g1B1s3TdhLIIYiJ4p+2/sVG2MKu8QuZzw38lgdTQKISBxS1UTYPxtBEi wFwM1ZNAAmyQCNLbEMOqTAtPUlAApZvuP+SVmQU9tDDHKJPs37nIvWSKxHJWzwXnP7Be hsUD3auIG0yjSZVtvE+AVpivdKqK/KwAZ5UeQcEAhELqRQ8CIsVmNrpfUG7b2ybuqjnb /AeUNGeUDh5bQdL5sv4hFoFDkGxxAcfy2m5wLR/0KBEpCtLiogRjRtHP96tpDjM7Ylse 3EjYsOK+TDYcm7kyHvH8LJoVXAKkGKNpduvIEMvO6I4i/Vj3eZtuei8UgTqX8YiP/DiO 2lPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject; bh=ikWw+F8HWtUdYgMx6YEgxXAfRxiz4agSLg/kxD+/2So=; b=NhkQjpt1wAq9QDacwgXCxb3AeLgcv7XbJo3TRLF2++O0yX7TLSxU8xFc25oOjycQ2u Ws931jCTqmI1Rp40yCjLxCBmFrdCfp/rb2WtNRZZzPuViaF1WvSDtssQJG5V7L8poZ0s kOMan0we1bkmBd+IVZrDPtlXaZ6T00sp73zVMP6sOAAoLDj9IlJ6HYjOSgYxqhQnI6OD JnqYBlemt4FOjFqXFp2mqQesi9mZakgwvxMyMzmJj23BY65hp2z1o45lsSdpPondX0UV XSZMQSObxenvJv3s5WN39XdVemGFsRMlZ5pmuYBCpB+bYpkfXjiIzT5vYV8F7YGvkVN4 0rUA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j15si18734243pfi.8.2019.04.05.03.03.28; Fri, 05 Apr 2019 03:03:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730609AbfDEKCg (ORCPT + 99 others); Fri, 5 Apr 2019 06:02:36 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:45072 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729820AbfDEKCg (ORCPT ); Fri, 5 Apr 2019 06:02:36 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 10303168F; Fri, 5 Apr 2019 03:02:35 -0700 (PDT) Received: from [10.1.196.75] (e110467-lin.cambridge.arm.com [10.1.196.75]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A4DEE3F721; Fri, 5 Apr 2019 03:02:32 -0700 (PDT) Subject: Re: [PATCH v3 1/3] iommu: io-pgtable: Add ARM Mali midgard MMU page table format From: Robin Murphy To: Rob Herring , dri-devel@lists.freedesktop.org Cc: Lyude Paul , Eric Anholt , Maxime Ripard , Will Deacon , Neil Armstrong , Maarten Lankhorst , linux-kernel@vger.kernel.org, David Airlie , iommu@lists.linux-foundation.org, Alyssa Rosenzweig , Daniel Vetter , Sean Paul , linux-arm-kernel@lists.infradead.org References: <20190401074730.12241-1-robh@kernel.org> <20190401074730.12241-2-robh@kernel.org> <8d091874-11b0-e348-c4f1-dd1bcfa4bf97@arm.com> Message-ID: <85471882-3044-eba7-8351-fb01330004d8@arm.com> Date: Fri, 5 Apr 2019 11:02:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <8d091874-11b0-e348-c4f1-dd1bcfa4bf97@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/04/2019 20:11, Robin Murphy wrote: > On 01/04/2019 08:47, Rob Herring wrote: >> ARM Mali midgard GPU is similar to standard 64-bit stage 1 page >> tables, but >> have a few differences. Add a new format type to represent the format. >> The >> input address size is 48-bits and the output address size is 40-bits (and >> possibly less?). Note that the later bifrost GPUs follow the standard >> 64-bit stage 1 format. >> >> The differences in the format compared to 64-bit stage 1 format are: >> >> The 3rd level page entry bits are 0x1 instead of 0x3 for page entries. >> >> The access flags are not read-only and unprivileged, but read and write. >> This is similar to stage 2 entries, but the memory attributes field >> matches >> stage 1 being an index. >> >> The nG bit is not set by the vendor driver. This one didn't seem to >> matter, >> but we'll keep it aligned to the vendor driver. >> >> Cc: Will Deacon >> Cc: Robin Murphy >> Cc: Joerg Roedel >> Cc: linux-arm-kernel@lists.infradead.org >> Cc: iommu@lists.linux-foundation.org >> Signed-off-by: Rob Herring >> --- >> Please ack this as I need to apply it to the drm-misc tree. Or we need a >> stable branch with this patch. > > With the diff below squashed in to address my outstanding style nits, > > Acked-by: Robin Murphy > > I don't foresee any conflicting io-pgtable changes to prevent this going > via DRM, but I'll leave the final say up to Joerg. Urgh, sorry, turns out I flipped one condition too many there. On reflection I may also forget my clever trick in future and inadvertently break it, so it probably warrants a comment. Please supersede my previous request with the (actually tested) diff below :) Thanks, Robin. ----->8----- diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index 98551d0cff59..4f7be5a3e19b 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -197,12 +197,13 @@ struct arm_lpae_io_pgtable { typedef u64 arm_lpae_iopte; -static inline bool iopte_leaf(arm_lpae_iopte pte, int l, enum io_pgtable_fmt fmt) +static inline bool iopte_leaf(arm_lpae_iopte pte, int lvl, + enum io_pgtable_fmt fmt) { - if ((l == (ARM_LPAE_MAX_LEVELS - 1)) && (fmt != ARM_MALI_LPAE)) - return iopte_type(pte,l) == ARM_LPAE_PTE_TYPE_PAGE; + if (lvl == (ARM_LPAE_MAX_LEVELS - 1) && fmt != ARM_MALI_LPAE) + return iopte_type(pte, lvl) == ARM_LPAE_PTE_TYPE_PAGE; - return iopte_type(pte,l) == ARM_LPAE_PTE_TYPE_BLOCK; + return iopte_type(pte, lvl) == ARM_LPAE_PTE_TYPE_BLOCK; } static arm_lpae_iopte paddr_to_iopte(phys_addr_t paddr, @@ -310,12 +311,9 @@ static void __arm_lpae_init_pte(struct arm_lpae_io_pgtable *data, if (data->iop.cfg.quirks & IO_PGTABLE_QUIRK_ARM_NS) pte |= ARM_LPAE_PTE_NS; - if (lvl == ARM_LPAE_MAX_LEVELS - 1) { - if (data->iop.fmt == ARM_MALI_LPAE) - pte |= ARM_LPAE_PTE_TYPE_BLOCK; - else - pte |= ARM_LPAE_PTE_TYPE_PAGE; - } else + if (data->iop.fmt != ARM_MALI_LPAE && lvl == ARM_LPAE_MAX_LEVELS - 1) + pte |= ARM_LPAE_PTE_TYPE_PAGE; + else pte |= ARM_LPAE_PTE_TYPE_BLOCK; if (data->iop.fmt != ARM_MALI_LPAE) @@ -452,7 +450,10 @@ static arm_lpae_iopte arm_lpae_prot_to_pte(struct arm_lpae_io_pgtable *data, if (prot & IOMMU_WRITE) pte |= ARM_LPAE_PTE_HAP_WRITE; } - + /* + * Note that this logic is structured to accommodate Mali LPAE + * having stage-1-like attributes but stage-2-like permissions. + */ if (data->iop.fmt == ARM_64_LPAE_S2 || data->iop.fmt == ARM_32_LPAE_S2) { if (prot & IOMMU_MMIO)