Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2957291rdh; Mon, 27 Nov 2023 03:25:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLO7eavDwx6nqu7xh/hPI5ecKTBgTmyfFJ0j0blLEhfekX4Nhv3g83vL7P9gW/fPn++bL/ X-Received: by 2002:a05:6a00:39a9:b0:6cb:bc06:b085 with SMTP id fi41-20020a056a0039a900b006cbbc06b085mr10004204pfb.34.1701084336773; Mon, 27 Nov 2023 03:25:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701084336; cv=none; d=google.com; s=arc-20160816; b=EGYQulM74/ew83mZpKcVqGUobJ4j7hhOEMcvD+iFf9ONQ/bwKvnZ74KLqAYTwxKugh jzwWVjW9GbQ9UWMAkPfd+7MspsAWA5uISeGh9GvbrnyaXLVlB73S8aPqAYnMyVq0KVBm QUnFi9PGeHuux+OHLYRzPROGqikiIp/O78sXxieW/EtA56d0bw8LA+ujdVgQ1xglFFEO FurQMErbKxz1lz2ni+5s75uMZuqp+efSkZOnEwIuJTtaP0Uubutoh97GXUaaq8h5uQP7 XLr1pnuCiRK6iY1VLZAL3NyjSTFb/uQ/NZbnW+w9cCtFuTzzF7YJlfndDirLDiaZy1SN YCzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=fASo682Yw/SS1gdoDCMc7yGezwWlRHRlHbzEi0mena4=; fh=bd8O47fwVc1u1IwD39CBhdYKfL84ayW/EMAjwTVhoUI=; b=MDfZ2VrlDVuQzEBoTb80vxiO6p8+9aQMd/3Lz7WqbWW9xtxGINIDb5cczueCXeyNLg cDtNvNsElJpjjGk+Dr7kgetV3uD2LxH9LyCYUcV9QGl3ZZVx3NPLyWkTLWKDKs0PreX1 JuUdDrpW3JHpzQFUCy1IkSNPUjW0MxQxNv2rBK2zuN66vviNxnRUXilciWL3GfZrsgxy R0naTKJBpljUYjz8SImqZg2V1POO0D+XpRRs0jOLpoEzTGvTzw95z0STj/NQPk6v9l0J u3zh5te48m6/e/mQ0FQLfROAxgyXjiZsBXxefIxXwDI6CghN85O7jcrQ8vmpz/LoTZLO vv3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id bz3-20020a056a02060300b005be09a118d3si10606917pgb.143.2023.11.27.03.25.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 03:25:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 07CA880A97C9; Mon, 27 Nov 2023 03:25:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233186AbjK0LYw (ORCPT + 99 others); Mon, 27 Nov 2023 06:24:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233182AbjK0LYq (ORCPT ); Mon, 27 Nov 2023 06:24:46 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BB69E18A for ; Mon, 27 Nov 2023 03:24:37 -0800 (PST) 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 D8C672F4; Mon, 27 Nov 2023 03:25:24 -0800 (PST) Received: from [10.57.73.142] (unknown [10.57.73.142]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 21BC93F73F; Mon, 27 Nov 2023 03:24:35 -0800 (PST) Message-ID: <6415df67-8d5f-44e5-8ca6-57007adf9aae@arm.com> Date: Mon, 27 Nov 2023 11:24:33 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] kernel: dma: let dma use vmalloc area Content-Language: en-GB To: Zhaoyang Huang , Christoph Hellwig Cc: "zhaoyang.huang" , Marek Szyprowski , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, steve.kang@unisoc.com References: <20231127030930.1074374-1-zhaoyang.huang@unisoc.com> <20231127071430.GA28214@lst.de> From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 27 Nov 2023 03:25:34 -0800 (PST) On 2023-11-27 8:56 am, Zhaoyang Huang wrote: > On Mon, Nov 27, 2023 at 3:14 PM Christoph Hellwig wrote: >> >> On Mon, Nov 27, 2023 at 11:09:30AM +0800, zhaoyang.huang wrote: >>> From: Zhaoyang Huang >>> >>> memremap within dma_init_coherent_memory will map the given phys_addr >>> into vmalloc area if the pa is not found during iterating iomem_resources, >>> which conflict the rejection of vmalloc area in dma_map_single_attrs. >> >> I can't parse this sentence. > Sorry for the confusion, please find below codes for more information. > dma_init_coherent_memory > memremap > addr = ioremap_wt(offset, size); > What I mean is addr is a vmalloc address, which is implicitly mapped > by dma's framework and not be aware of to the driver. >> >>> IMO, it is find to let all valid virtual address be valid for DMA as the >>> user will keep corresponding RAM safe for transfer. >> >> No, vmalloc address can't be passed to map_single. You need to pass >> the page to dma_map_page, and explicitly mange cache consistency >> using the invalidate_kernel_vmap_range and flush_kernel_vmap_range >> helpers. > Please correct me if I am wrong. According to my understanding, cache > consistency could be solved inside dma_map_page via either > dma_direct_map_page(swio/arch_sync_dma_for_device) or ops->map_page. > The original thought of rejecting vmalloc is that this pa is not safe > as this mapping could go in any time. What I am suggesting is to let > this kind of va be enrolled. No, the point is that dma_map_single() uses virt_to_page(), and virt_to_page() is definitely not valid for vmalloc addresses. At worst it may blow up in itself with an out-of-bounds dereference; at best it's going to return a completely bogus page pointer which may then make dma_map_page() fall over. Thanks, Robin. > > static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr, > size_t size, enum dma_data_direction dir, unsigned long attrs) > { > /* DMA must never operate on areas that might be remapped. */ > if (dev_WARN_ONCE(dev, is_vmalloc_addr(ptr), > "rejecting DMA map of vmalloc memory\n")) > return DMA_MAPPING_ERROR; > >> >