Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp14475955rwd; Sat, 24 Jun 2023 21:16:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5WrPpezT1RS8Z+jpImm59vX1Nq6SUWMOL4TFLv55hf5v+nzw0ln3Fmc+lLxJNg/5hqVU/7 X-Received: by 2002:a17:903:41d0:b0:1b5:31f8:2450 with SMTP id u16-20020a17090341d000b001b531f82450mr4705096ple.51.1687666602521; Sat, 24 Jun 2023 21:16:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687666602; cv=none; d=google.com; s=arc-20160816; b=TL+fA+z/Di96tP5JdNle6+/xD5i3YDGxyrkHDeWEsUuOgQDbxszz0AuazwbwhZcFWN LlFhp1IO6uofr+bYzutHvtNO/M9aUjJC2b7HD175cAElxSzjm7umheR5Bhb/U7Y8bO2K Nqj/zoqjD6/RrbRBDKMhqa/MWynKNGNgMsZ7Odha2hgEHAIAvAmpTmRZm03X1U/jo+rL OW15DuRhGrqQYq4yqWRQNRGDTrGCVFpAIwec5U+plpBXx4RQ9RGx86rm5uY8ZJ/mZoAD LCzHOAdowVbnLiA1iAiBUIvQi4e8mycJZw7BJ1dT+Y/VV2KK1QjXwZfHO0Hr1t5f7Coe jIHg== 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 :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id; bh=IjvDPYagUDYxlCzXGhocroNZAVJcIk2yvHloAmfOEjc=; fh=eGAlqWa0KxmK7qUB1/NkuuO6ILvTzhH9q5so71Sn8Lc=; b=ZHkr/gRk8RTvo4vqM1z31LtDuw0Tj8DneLEuI24X0lD6hRzA0AOlBR+86yXiwtR6Ax OuweI87x2KVJZ/DrAnBMxQb+ybsa9Exic+6qD9L0rqmuU2uaq32EwaIk7dyRKUs6ZMFs coxDBZPseSVfD6l+KPE44dIwqFvu+fz1uVE/13nI+4jlLj3HyjOXrQSWGGEu+rROJ18n 9XBuFpoj8jd7HJMQN5VMmBCtAKc/ZFqgxcPzypxtBJFDzSRxpT4SqV0BWThOjuziOQ9F YO4Bh9X9m1Z9iBg8vfG/Txu7RHjurZDZbNljHkP9bXLquWSud7t7DHms+vLYhIUUqjQw mYIA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b15-20020a170902d88f00b001b01276a0bcsi2383417plz.51.2023.06.24.21.16.31; Sat, 24 Jun 2023 21:16:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231665AbjFYEEX (ORCPT + 99 others); Sun, 25 Jun 2023 00:04:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230307AbjFYEEV (ORCPT ); Sun, 25 Jun 2023 00:04:21 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 55BAD118 for ; Sat, 24 Jun 2023 21:04:19 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8BxmMXBvJdkz2sBAA--.2234S3; Sun, 25 Jun 2023 12:04:17 +0800 (CST) Received: from [10.20.42.43] (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxzM69vJdkuDcGAA--.30336S3; Sun, 25 Jun 2023 12:04:13 +0800 (CST) Message-ID: Date: Sun, 25 Jun 2023 12:04:13 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH v10 07/11] drm/etnaviv: Add support for the dma coherent device Content-Language: en-US To: Lucas Stach , Sui Jingfeng <18949883232@163.com>, Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, etnaviv@lists.freedesktop.org, Philipp Zabel , Bjorn Helgaas References: <20230620094716.2231414-1-18949883232@163.com> <20230620094716.2231414-8-18949883232@163.com> <8f74f0962c8bab6c832919a5340667c54e1a7ddc.camel@pengutronix.de> <2249b895-84b9-adea-531b-bf190e9c866f@loongson.cn> <030d44e2753b9b2eea0107cdee6c20e2bc2d3efe.camel@pengutronix.de> <3911d448-5613-23a8-cfcb-5ae418677338@loongson.cn> <87deb46db35b028da74c94f5496b721e14db4745.camel@pengutronix.de> <02c16e9b-0eca-caf4-b80c-53f1c7eab4e9@loongson.cn> From: Sui Jingfeng Organization: Loongson In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8DxzM69vJdkuDcGAA--.30336S3 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBj93XoWxWrWUtryfAFyxXrWxAF4kZrc_yoW5Kr4xpF sYkFyayrZ5uryvqwnFqw45Zry3tr4fJay5AFn8Ja4Y9ws0vr1SgF409r4j9F1UWws3Zr1j q3yqvwnxZFn8AFXCm3ZEXasCq-sJn29KB7ZKAUJUUUU7529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUPIb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1ln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12 xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q 6rW5McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IY64vIr4 1lc7I2V7IY0VAS07AlzVAYIcxG8wCY1x0262kKe7AKxVWUAVWUtwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVWUtVW8ZwC20s026c02F40E14 v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkG c2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4U MIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07j22NtUUU UU= X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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 Hi, On 2023/6/22 01:53, Lucas Stach wrote: > Am Donnerstag, dem 22.06.2023 um 01:31 +0800 schrieb Sui Jingfeng: >> Hi, >> >> On 2023/6/22 00:07, Lucas Stach wrote: >>> And as the HW guarantees it on your platform, your platform >>> implementation makes this function effectively a no-op. Skipping the >>> call to this function is breaking the DMA API abstraction, as now the >>> driver is second guessing the DMA API implementation. I really see no >>> reason to do this. >> It is the same reason you chose the word 'effectively', not 'difinitely'. >> >> We don't want waste the CPU's time, >> >> >>  to running the dma_sync_sg_for_cpu funcion() function >> >> >> ``` >> >> void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, >>             int nelems, enum dma_data_direction dir) >> { >>     const struct dma_map_ops *ops = get_dma_ops(dev); >> >>     BUG_ON(!valid_dma_direction(dir)); >>     if (dma_map_direct(dev, ops)) >>         dma_direct_sync_sg_for_cpu(dev, sg, nelems, dir); >>     else if (ops->sync_sg_for_cpu) >>         ops->sync_sg_for_cpu(dev, sg, nelems, dir); >>     debug_dma_sync_sg_for_cpu(dev, sg, nelems, dir); >> } >> >> ``` >> >> >>  to running the this: >> >> >> ``` >> >> int etnaviv_gem_cpu_fini(struct drm_gem_object *obj) >> { >>     struct drm_device *dev = obj->dev; >>     struct etnaviv_gem_object *etnaviv_obj = to_etnaviv_bo(obj); >>     struct etnaviv_drm_private *priv = dev->dev_private; >> >>     if (!priv->dma_coherent && etnaviv_obj->flags & ETNA_BO_CACHED) { >>         /* fini without a prep is almost certainly a userspace error */ >>         WARN_ON(etnaviv_obj->last_cpu_prep_op == 0); >>         dma_sync_sgtable_for_device(dev->dev, etnaviv_obj->sgt, >> etnaviv_op_to_dma_dir(etnaviv_obj->last_cpu_prep_op)); >>         etnaviv_obj->last_cpu_prep_op = 0; >>     } >> >>     return 0; >> } >> >> ``` >> > My judgment as the maintainer of this driver is that the small CPU > overhead of calling this function is very well worth it, if the > alternative is breaking the DMA API abstractions. > >> But, this is acceptable, because we can kill the GEM_CPU_PREP and >> GEM_CPU_FINI ioctl entirely >> >> at userspace for cached buffer, as this is totally not needed for cached >> mapping on our platform. >> > And that statement isn't true either. Yes, you are right here. I admit. Because I have suffered such problem in the past when developing xf86-video-loongson. The root cause, I think,  is the CPU don't know when the GPU have finished the rendering. Or there still some data reside in the GPU's cache. We have to call etna_bo_cpu_prep(etna_bo, DRM_ETNA_PREP_READ) function to make sure the  data fetch by CPU is the latest. I realized this knowledge(issue) five month ago in this year, see [1] for reference. I  just forget this thing when doing the debate with you. [1] https://gitlab.freedesktop.org/longxin2019/xf86-video-loongson/-/commit/95f9596eb19223c3109ea1f32c3e086fd1d43bd8 || > The CPU_PREP/FINI ioctls also > provide fence synchronization between CPU and GPU. You are correct here. > There are a few very > specific cases where skipping those ioctls is acceptable (mostly when > the userspace driver explicitly wants unsynchronized access), but in > most cases they are required for correctness. OK, you are extremely correct. > Regards, > Lucas -- Jingfeng