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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 97EF7C43334 for ; Thu, 21 Jul 2022 07:08:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vazfeOCQfByYu/e89eeEpsjfRlnzb8TpW0d2CGvPams=; b=l3Dhfwk0zRwhVO J2+HAFqqOLuFSytAgrAQGttJx1YDCWUiQS+RzvtXe+VCaOzdpBhO5YIqxAK0416dQjEQF2lHPB/H7 vxt/QvL7jlPBrUcuiL/z3a6n2pYFD5vx2QVVPia+qzEWJqsJwD3QQFOLRyd6Wi+ELX/RTgt2AUkG8 lbu9zMpjXjD/Wdy62wT1frSRasFmM7pypf0uSIGmMAs7CWAtz07BdMAc0MweOBu/XL+UxGpss321N rNwGXtfgGAOj8SYFHi29dhVuAqiZyzcuCkWPkaxooUiVpXnoV9KgClpdSBIUJNCcmUEeAA+cRZV7y h5h4m7RCrCGbKtXUU08g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oEQHS-001Se1-U4; Thu, 21 Jul 2022 07:07:31 +0000 Received: from mout.kundenserver.de ([217.72.192.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oEQHP-001SQQ-Hc for linux-arm-kernel@lists.infradead.org; Thu, 21 Jul 2022 07:07:29 +0000 Received: from mail-oi1-f174.google.com ([209.85.167.174]) by mrelayeu.kundenserver.de (mreue106 [213.165.67.113]) with ESMTPSA (Nemesis) id 1MwxRN-1nHcKd0ow7-00yS8r for ; Thu, 21 Jul 2022 09:07:16 +0200 Received: by mail-oi1-f174.google.com with SMTP id p132so875476oif.9 for ; Thu, 21 Jul 2022 00:07:15 -0700 (PDT) X-Gm-Message-State: AJIora/ABNiRitM04eZgrhq8D2Ay+3Bz6VVu1RLMJ2Y6Az4nQ2bsRaPA Ro2WBWTh2A3I2685V3mHGNKERg+nDQh6tN0PQ2I= X-Google-Smtp-Source: AGRyM1tAF2tGf8E9jSTS+64jubiiNnSDK7wLyvl9Di6SrWUjCMVnEm/ZB1PSw9SdUFhLNlrbD0GymSC5JoIxoyM6dX4= X-Received: by 2002:a05:6808:23cb:b0:339:f8b4:ecae with SMTP id bq11-20020a05680823cb00b00339f8b4ecaemr3935179oib.188.1658387234915; Thu, 21 Jul 2022 00:07:14 -0700 (PDT) MIME-Version: 1.0 References: <1821ecc9da6.1058f84302773949.334602897681819490@linux.beauty> In-Reply-To: <1821ecc9da6.1058f84302773949.334602897681819490@linux.beauty> From: Arnd Bergmann Date: Thu, 21 Jul 2022 09:06:57 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Why dma_alloc_coherent don't return direct mapped vaddr? To: Li Chen Cc: Arnd Bergmann , linux-arm-kernel X-Provags-ID: V03:K1:Ev1gkbJVJJbTI+qNIbG1Osfu9NyZ6xtI39MEDAAMMZCFlX7Oray jsRqVBdcH7+Mt2M2yqOPiLTy/yoKyvzMBZZ65F5aPJknY05L5eUyWE+7sG6IjkiUUHBfDI4 Ke3DV+ZIidACrEN6mhyZBxZSQyLJi74c5cdjYE2VEabayEVQuUxxjHY4m0gKuIZrk2nHlQB KwJBCoAkqsK1vH0iD9aPg== X-UI-Out-Filterresults: notjunk:1;V03:K0:BUZB4yAsyrs=:YQH+dbYX1+j1BvZ32jjAPu NYsiZXIyEhhnS89J8nDNRQX861QoGo5yNDpq5zQzwFRjjsDgEyGH0ODnH7c7Lz3VlCrkMbUQq /HNDk3EEu3JZ29YBBwwqdEtV9UXn7bOHQmiJirutxQ9WP+2GrUbO/3gJAb4m+ZWUtpI7aslLm l/UW5qskJuCPN8UXRrZ/Tl7lq/G5ua9bTWGJn0yTbUJ3m0JBtwdsSOviOEv4RVGQDEEPIcIzH oyV1bs0FJsC3baZd00NXnZ/CpgpspSUd6YoqeGYWmq37t8kv7m508BedbqVMRUDBJ9A6ipw9r ty/d1TAhBhQiGkLrwQ569YaAoTzUdeRpYVqEObIoil5mui/OoBklED9Uk4SI+3rAsGtDdnHG1 O7rw/IxtOSrBczqB9fWHCWKvwRqNalBw7IEwYHcN1G9Y1PeasnV1TXv6k8icpsIAD6lXlm3N+ Kp7PbtOBmnclAT9gUPhTckhZzcgGx0+/7M6q0TmNxpvl4MoTuAefYwlMO0dUx3Gy6czeV25Me ndPayPVLbAqL8vwPPvrFsyPLy5TjbWVf+MG3UVWPVoMVWbAR2iJz4jeS1uiWLixEyBIhxXAgl 2GrvCr2TNUBCXf7k1WuAH+lO2aHJHx+hIoLpa59QINI8rhfAc65QdwNS4Y6QfFI8p52rcn9y4 zEYh2w4N7YIM9utbkfJWHkVhyExx7N9u+eVufeLYZahO4AZBxmlk3Cj9uVuJ/Eit4Geqa4joq mdB7KTus2x/xh3+O5xKfwZTdFrp6rf91qxjQTw== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220721_000727_897538_DD93B1C4 X-CRM114-Status: GOOD ( 17.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Jul 21, 2022 at 5:28 AM Li Chen wrote: > > Hi Arnd, > > dma_alloc_coherent two addr: > 1. vaddr. > 2. dma_addr > > I noticed vaddr is not simply linear/direct mapped to dma_addr, which means I cannot use virt_to_phys/virt_to_page to get > paddr/page. Instead, I should use dma_addr as paddr and phys_to_page(dma_addr) to get struct page. > > My question is why dma_alloc_coherent not simply return phys_to_virt(dma_addr)? IOW, why vaddr is > not directly mapped to dma_addr? dma_alloc_coherent() tries to allocate memory that is the correct type for the device you pass. If the device is not itself marked as cache coherent in the DT, then it has to use an uncached mapping. The normal linear map of all memory into the kernel address space is cacheable, so this device can't use it, and you instead get a new mapping into kernel space at a different virtual address. Note that you should never need a 'struct page' in this case, as the device needs a physical ddress and access from kernel space just needs a pointer. Calling phys_to_page() on a dma_addr_t is not portable because a lot of devices have DMA addresses that are not the same number as the physical address as seen by the CPU, or there may be an IOMMU inbetween. Arnd _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel