Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2883386rdh; Mon, 27 Nov 2023 00:57:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IEOu6125GXAj5sC6JVZUF0ILGGsCEAbYO/qlLFuuH72mswhNpy3WXVI6U6J/bkkWLfnzVMd X-Received: by 2002:a05:6a20:d396:b0:189:a6b3:ef7b with SMTP id iq22-20020a056a20d39600b00189a6b3ef7bmr15771026pzb.20.1701075428141; Mon, 27 Nov 2023 00:57:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701075428; cv=none; d=google.com; s=arc-20160816; b=q24e8UJ5SK581sDx0KU5ghXcdnDyDih7zPKNeXrVrNe8XPZIncMYKqWF1T4Z9e6hC6 u+jGv4bPMJukMzlHl8i2fbjZuGJFoApvyeXfyeXk5wh6tQC6EzRydMwuZ+s6KN5ytBHf BMx/BN3yVZVR/4aXsrUAkfCLjlsbfjVjJrzdPYk89U9t7MYW0iaDqZJu/vFF049CgaRj SHncFXtENq9HjFXTmfmttO+i0KIhFNzPb09j85hUyS1khCqBy1TmtCtXV7324rPcVvv5 748C0MWacjerss78GKBg3FFK8cQeKxKuv9Wl1Cdzb4pw7fmoGeDWZV5u7xQV5H3N6Gie ZNyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=S4j+WUhsI6HLaQhNpMAvxRSBO5fBvP0PmC3kAAmj31Q=; fh=w+7+mR2rRjEwl4dtPqosuEXzJvqCFxFhgnVG2zwtESs=; b=Gvya8YUBRWnseiJrOs/toXGS0xdJNK5Auid3EPXYNR8+BmcAoDfdR/ICk4UsTtXtwG c0wTxS7OMvq2PI3AXHdU+2hT/CJKZhSxtRTKa5uT3Y6SRksX3VsRCW4uj4shQOvgpfVH xprNh6OvvgDnlX7e0J+hw49hW5hCJRgRuUMWDi5p6Q5Pxa4BLq1aRGJM+yJ2ufDvWSTu 5+OHQ0Rt0bDDafU/3JbGdXGS6AYPaj4rjwuzM4RGE/I6rmNjnoHounRCWv8xsoTMVjhU Ww6jW1ksntVsttGpOg/OHfBapEBphfdY+K5ECX3RmyvnkKw2FKHVvnT92zEox6gxK5X3 gxYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dl4wWGOn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id fd1-20020a056a002e8100b006cbdff8f01csi9687306pfb.68.2023.11.27.00.57.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 00:57:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dl4wWGOn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id DC193809849C; Mon, 27 Nov 2023 00:57:06 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231160AbjK0I4y (ORCPT + 99 others); Mon, 27 Nov 2023 03:56:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230149AbjK0I4x (ORCPT ); Mon, 27 Nov 2023 03:56:53 -0500 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73DFD111 for ; Mon, 27 Nov 2023 00:56:59 -0800 (PST) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2c87acba73bso52093261fa.1 for ; Mon, 27 Nov 2023 00:56:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701075418; x=1701680218; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=S4j+WUhsI6HLaQhNpMAvxRSBO5fBvP0PmC3kAAmj31Q=; b=dl4wWGOn6kykg48ZcRUMkhyRM5QYvpXh3/nidOx03B674JnRlGNCBOnLuLU4Pyx5rt QY+Ki3zae0/U8VuKfjYDh80WrTxWby2sWapoxRkWuC2zk4iY5YYPsY3ABCfRcymyGtX7 CJt8HXopWnxweOO34BjtaWfrm9q9YcnAZhMOWPOKPfew2EBTNkiwVTknK8Z2AWiZICqz MflOgPcpTWZeBrYtY2c4NdzKDasQsjY4uyJWOFnqj8YWDUe12yPiRIz5IMHHEU1FazR5 rXCMC9iDjcKaF2QmUeDLOLGxbfz3//3Yv0sWilNZnt27ebR8YITxzJkFLP0cWjEvHxfs BNIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701075418; x=1701680218; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S4j+WUhsI6HLaQhNpMAvxRSBO5fBvP0PmC3kAAmj31Q=; b=Ih6g2eOpIuXr1F1BLtF53t2z99eM8E0NEH49GrDv3iXVvC4OJvTKqWEmciR4/MSEWc sYaO/CxXwxKfPcLUbQiL+QwpdAXf0MmismsAHGdx4UOo9Zejoj02/84VSU2p7ToOmDKJ 0f72MKc6TYox1eLo0Kp4F7ov/FP9+mRpTwiYhTxasc0r4Aukz7nPEchiSiWDegxZ4lEw vQ7APkP8ox2gJgzW0kz7jcfWYySVOgVrC+6ee3U5b2ZYLE8y5r8XEyz3GbXLtEhuvY4E 43V83CEAErplNoCnkdPT7coXVJPYAMZaDKuIC5T1iHy5bI9+Frtntk73H3zvp4UDP7V8 euFg== X-Gm-Message-State: AOJu0YxyenfN9Rc5O4hVScc1PWtkmM11AQrYcvl+FDKEPky2XDIpyN8y 4t/idIXMOtLd1QIojNSscg9prdWpBfkI7sPQtLY= X-Received: by 2002:a05:651c:317:b0:2c9:9ce3:dfd3 with SMTP id a23-20020a05651c031700b002c99ce3dfd3mr2179971ljp.0.1701075417464; Mon, 27 Nov 2023 00:56:57 -0800 (PST) MIME-Version: 1.0 References: <20231127030930.1074374-1-zhaoyang.huang@unisoc.com> <20231127071430.GA28214@lst.de> In-Reply-To: <20231127071430.GA28214@lst.de> From: Zhaoyang Huang Date: Mon, 27 Nov 2023 16:56:45 +0800 Message-ID: Subject: Re: [PATCH] kernel: dma: let dma use vmalloc area To: Christoph Hellwig Cc: "zhaoyang.huang" , Marek Szyprowski , Robin Murphy , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, steve.kang@unisoc.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 27 Nov 2023 00:57:07 -0800 (PST) On Mon, Nov 27, 2023 at 3:14=E2=80=AFPM Christoph Hellwig wrot= e: > > 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_resourc= es, > > 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 =3D 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 th= e > > 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. static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *pt= r, size_t size, enum dma_data_direction dir, unsigned long att= rs) { /* 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; >