From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA4E9C54FD0 for ; Fri, 24 Apr 2020 15:29:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B1EE220700 for ; Fri, 24 Apr 2020 15:29:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B1EE220700 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 590078E0005; Fri, 24 Apr 2020 11:29:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5416A8E0003; Fri, 24 Apr 2020 11:29:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 47CB58E0005; Fri, 24 Apr 2020 11:29:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0155.hostedemail.com [216.40.44.155]) by kanga.kvack.org (Postfix) with ESMTP id 2D4FA8E0003 for ; Fri, 24 Apr 2020 11:29:58 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D9C51824556B for ; Fri, 24 Apr 2020 15:29:57 +0000 (UTC) X-FDA: 76743134034.06.crack96_1cba26f6c2a1f X-HE-Tag: crack96_1cba26f6c2a1f X-Filterd-Recvd-Size: 4048 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Apr 2020 15:29:57 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4A84131B; Fri, 24 Apr 2020 08:29:56 -0700 (PDT) Received: from [10.57.33.170] (unknown [10.57.33.170]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B82223F68F; Fri, 24 Apr 2020 08:29:53 -0700 (PDT) Subject: Re: IOVA allocation dependency between firmware buffer and remaining buffers To: Ajay kumar , iommu@lists.linux-foundation.org, linux-mm@kvack.org, joro@8bytes.org, Marek Szyprowski , Rob Clark , Thierry Reding , jean-philippe@linaro.org, will@kernel.org, hch@lst.de, baolu.lu@linux.intel.com Cc: shaik.ameer@samsung.com, shaik.samsung@gmail.com References: From: Robin Murphy Message-ID: <59cda41f-170c-a1ad-a345-bc38b9ed4d73@arm.com> Date: Fri, 24 Apr 2020 16:29:53 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2020-04-24 4:04 pm, Ajay kumar wrote: > Can someone check this? > > On Mon, Apr 20, 2020 at 9:24 PM Ajay kumar wrote: >> >> Hi All, >> >> I have an IOMMU master which has limitations as mentioned below: >> 1) The IOMMU master internally executes a firmware, and the firmware memory >> is allocated by the same master driver. >> The firmware buffer address should be of the lowest range than other address >> allocated by the device, or in other words, all the remaining buffer addresses >> should always be in a higher range than the firmware address. >> 2) None of the buffer addresses should go beyond 0xC000_0000 That particular constraint could (and perhaps should) be expressed as a DMA mask/limit for the device, but if you have specific requirements to place buffers at particular addresses then you might be better off managing your own IOMMU domain like some other (mostly DRM) drivers do. The DMA APIs don't offer any guarantees about what addresses you'll get other than that they won't exceed the appropriate mask. >> example: >> If firmware buffer address is buf_fw = 0x8000_5000; >> All other addresses given to the device should be greater than >> (0x8000_5000 + firmware size) and less than 0xC000_0000 Out of curiosity, how do you control that in the no-IOMMU or IOMMU passthrough cases? Robin. >> Currently, this is being handled with one of the below hacks: >> 1) By keeping dma_mask in lower range while allocating firmware buffer, >> and then increasing the dma_mask to higher range for other buffers. >> 2) By reserving IOVA for firmware at the lowest range and creating direct mappings for the same. >> >> I want to know if there is a better way this can be handled with current framework, >> or if anybody is facing similar problems with their devices, >> please share how it is taken care. >> >> I also think there should be some way the masters can specify the IOVA >> range they want to limit to for current allocation. >> Something like a new iommu_ops callback like below: >> limit_iova_alloc_range(dev, iova_start, iova_end) >> >> And, in my driver, the sequence will be: >> limit_iova_alloc_range(dev, 0x0000_0000, 0x1000_0000); /* via helpers */ >> alloc( ) firmware buffer using DMA API >> limit_iova_alloc_range(dev, 0x1000_0000, 0xC000_0000); /* via helpers */ >> alloc( ) other buffers using DMA API >> >> Thanks, >> Ajay Kumar