Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3540308ybl; Mon, 27 Jan 2020 06:01:25 -0800 (PST) X-Google-Smtp-Source: APXvYqxECktt3fHL8pTC4zBr1ctXZLl3yYg/PKVXThw4QDbKZ6X7BGD6Hn2Yzh6BTvJxfKYEOQlF X-Received: by 2002:a9d:831:: with SMTP id 46mr782457oty.295.1580133685589; Mon, 27 Jan 2020 06:01:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580133685; cv=none; d=google.com; s=arc-20160816; b=KfdnmpiI6dYv3ly9VXQJ/h8eqT6my3VbUNkjwvYwE253/+bByBmO8qf6rKdMMo93ub NwShTt0XF8u/CgRIiCXEF6aiD4DQvKWRyet9aJT1PWMFYbSrGYgSrheM7Bw/moa3Gdoz HwUsEwR+awS+2pK/byBI6AJM9akBcGNQj9RKizth2HVGBF/Uw5fAn8Z8Te9CPi+AzNPY A/9Kj5wBUOS1CKI/apEWRTL4s0mxPmzTrup13nspc9Etyy8BsZ9BCH/T7EVa32HFXetS 7yHmvfzRgktFGbelOn2s6yOHK1xlx2feWA5UgNIhAxIx9xNVdGvlkF6w0ddZV3i3kzFF KGng== 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:from:references:cc:to:subject:dkim-signature; bh=13B9b908UVUbvOyxiJ58ECaxp0yhYxfCuSddmMPdXQo=; b=eWDsCoSsQ18FGrH4rWu4C77RG74B+gg4LNa2nx9RQvSiw4O06d7hySWM1lksk9Lbew NE7Pka8mLdS7SvejHL4ClpO5ffgSICpX3ac5n1YUKiWwy7uxcvxJFBz2fSbgkukBnnjC DKfUvAueOoF4D9/gx051PpSMC9CzKQoyiR3Mj38c+Xgj+5CcOt6Z7T6jH5shT+qpu0Wh CSa1Zdd+5HHS+vMvmUWg/al/+fF82DW2LYfSbPslMlIVXW+QtpNEkWd5bdJRtoNjmkMm T6uVk/DSylDsJ+MgJaWKfvdZDrzP/GeasragZ8n9VGKcreX1L8DvgdkEX7x4olh9E9ut 5jAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=byMYjQ5a; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n21si3655404oic.0.2020.01.27.06.01.12; Mon, 27 Jan 2020 06:01:25 -0800 (PST) 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; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=byMYjQ5a; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728604AbgA0OAQ (ORCPT + 99 others); Mon, 27 Jan 2020 09:00:16 -0500 Received: from lelv0142.ext.ti.com ([198.47.23.249]:47656 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726303AbgA0OAQ (ORCPT ); Mon, 27 Jan 2020 09:00:16 -0500 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 00RDxlYL057095; Mon, 27 Jan 2020 07:59:47 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1580133587; bh=13B9b908UVUbvOyxiJ58ECaxp0yhYxfCuSddmMPdXQo=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=byMYjQ5axRrtxupLYKROYKVt8+IuRrCfDAxUd1qyo+R+/6pCmypBcK3Igp/v/iw/A lRKu+H7M/KnacRahNE8QWJXwKsK03GsCVj1lwDBQLGK/+wAwfHrS30u9cIeGGOFk6R rIW5OnTYhpCBAscc2yC6dyHMxsAYJ3Bp1PuJ+60g= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id 00RDxlA0046759; Mon, 27 Jan 2020 07:59:47 -0600 Received: from DFLE107.ent.ti.com (10.64.6.28) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Mon, 27 Jan 2020 07:59:46 -0600 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE107.ent.ti.com (10.64.6.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Mon, 27 Jan 2020 07:59:46 -0600 Received: from [192.168.2.6] (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 00RDxiK6043723; Mon, 27 Jan 2020 07:59:44 -0600 Subject: Re: [PoC] arm: dma-mapping: direct: Apply dma_pfn_offset only when it is valid To: Robin Murphy , CC: , , , , , , , References: <8eb68140-97b2-62ce-3e06-3761984aa5b1@ti.com> <20200114164332.3164-1-peter.ujfalusi@ti.com> <28ee3395-baed-8d59-8546-ab7765829cc8@ti.com> <4f0e307f-29a9-44cd-eeaa-3b999e03871c@arm.com> From: Peter Ujfalusi Message-ID: <75843c71-1718-8d61-5e3d-edba6e1b10bd@ti.com> Date: Mon, 27 Jan 2020 16:00:30 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <4f0e307f-29a9-44cd-eeaa-3b999e03871c@arm.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16/01/2020 21.13, Robin Murphy wrote: > On 15/01/2020 11:50 am, Peter Ujfalusi wrote: >> >> >> On 14/01/2020 20.19, Robin Murphy wrote: >>> On 14/01/2020 4:43 pm, Peter Ujfalusi wrote: >>>> The dma_pfn_offset should only be applied to an address which is >>>> within the >>>> dma-ranges range. Any address outside should have offset as 0. >>> >>> No, that's wrong. If a non-empty dma-ranges is present, then addresses >>> which do not fall within any specified range are invalid altogether. >> >> It is not explicitly stated by the specification, but can be interpreted >> like that and from a pow it does make sense to treat things like that. > > Yes, DTspec doesn't explicitly say so, but it does follow fairly > logically from the definition of "ranges"/"dma-ranges" as a translation > between address spaces that an address not matching any range cannot > pass between those address spaces at all. Case in point being that an > absent "ranges" property means "no translation at all" (sadly the ship > sailed too long ago to treat "dma-ranges" similarly strictly, so we're > stuck with the assumption that absent = empty in that direction) Agree. > >>> The current long-term plan is indeed to try to move to some sort of >>> internal "DMA range descriptor" in order to properly cope with the kind >>> of esoteric integrations which have multiple disjoint windows, >>> potentially even with different offsets, but as you point out there are >>> still many hurdles between now and that becoming reality. So although >>> this patch does represent the "right" thing, it's for entirely the wrong >>> reason. AFAICT for your case it basically just works out as a very >>> baroque way to hack dma_direct_supported() again - we shouldn't need a >>> special case to map a bogus physical address to valid DMA address, we >>> should be fixing the source of the bogus PA in the first place. >> >> DMA_BIT_MASK(32) is pretty clear: The DMA can handle addresses within >> 32bit space. DMA_BIT_MASK(24) is also clear: The DMA can handle >> addresses within 24bit space. > > Careful there - DMA *masks* are about how wide an address the device may > generate Which is in a simplified view is what address range the DMA can address. The DMA can not generate address beyond the mask. > but it's not necessarily true that the interconnect beyond > will actually accept every possible address that that many bits can > encode True. > (see the aforementioned case of PCI host bridge windows, or the > recent change of bus_dma_mask to a not-necessarily-power-of-two > bus_dma_limit)... I see. >> dma-ranges does not change that. The DMA can still address the same >> space. > > ...thus that assumption is incorrect. Hrm, why it is not correct? The DMA can generate addresses up to 32 bits. Anything beyond that is not accessible by DMA. The interconnect makes part of a higher (not addressable memory space) available within the 32 bits range, thus the DMA can address that. We tell this via the dma-ranges. I agree that for a correct dma-ranges for k2g should be: dma-ranges = <0x0 0x0 0x0 0x80000000>, <0x80000000 0x8 0x00000000 0x80000000>; > However it's not particularly > important to the immediate problem at hand. > >> What dma-ranges will tell is that a physical address range 'X' >> can be accessed on the bus under range 'Y'. >> For the DMA within the bus the physical address within 'X' does not >> matter. What matters is the matching address within 'Y' >> >> We should do dma_pfn_offset conversion _only_ for the range it applies >> to. Outside of it is not valid to apply it. > > That much is agreed. For a physical address A in Y, phys_to_dma(A) > should return the corresponding DMA address A' in X. What you're > proposing is that for address B not in Y, phys_to_dma(B) should just > return B, but my point is that even doing that is wrong, because there > is no possible DMA address corresponding to B, so there is no valid > value to return at all. I agree on the phys_to_dma(). It should fail for addresses which does not fall into any of the ranges. It is just a that we in Linux don't have the concept atm for ranges, we have only _one_ range which applies to every memory address. I guess what I'm proposing is to _not_ apply the phys_to_dma() to the DMA mask itself? Or reverse check the dma-ranges against the dma_mask? 0x0 - 0x8000 0000 : direct mapped w/o pfn_offset 0x8000 0000 - 0xFFFF FFFF : mapped from 0x8 0000 0000 w/ pfn_offset and this is the whole address range the DMA can address. > Nobody's disputing that the current dma_direct_supported() > implementation is broken for the case where ZONE_DMA itself is offset > from PA 0; the more pressing question is why Christoph's diff, which was > trying to take that into account, still didn't work. I understand that this is a bit more complex than I interpret it, but the k2g is broken and currently the simplest way to make it work is to use the arm dma_ops in case the pfn_offset is not 0. It will be easy to test dma-direct changes trying to address the issue in hand, but will allow k2g to be usable at the same time. A patch like I first proposed in: https://lore.kernel.org/lkml/8eb68140-97b2-62ce-3e06-3761984aa5b1@ti.com/ - Péter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki