Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp9737501rwd; Wed, 21 Jun 2023 11:07:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ735lOV+5mj6W7cZpt7zK6XZ675bGtGNBGnChW7FZbEgATiGPMu/DaSgiR4D5o49I2YDYm1 X-Received: by 2002:a17:90b:3684:b0:260:b83e:89d4 with SMTP id mj4-20020a17090b368400b00260b83e89d4mr9410583pjb.15.1687370851359; Wed, 21 Jun 2023 11:07:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687370851; cv=none; d=google.com; s=arc-20160816; b=Q3VIq//SUIL6VjgntEsTcj5TaeDBbqAa2EJAKjKKqbTIgLYu39cK0H52D/31tGgGOP cQnOZ61VFZiBvkgIXCNyIp+niTPDGBqcQ0dnAq5pU5D9XIXaAdyr8x/McWWP/7rSXLlU LlDRykns9c0BYEHcMVqxDQBUnhNVYfWmwtk4wmCXyT+WVbLyghrY4MUvc+w0BeYIRmKt T/JBxVkBqRkkCRBBx6mZETYxWVPLlD4FsMZA4JUY9+HEGEs5N6NeMz7ikKsL5hxIVT0G 7WsZBVwtJ8qeXuzxJcV0Wjjq1ClnHRdaq2T3EfXgLwe1iC3TA/8cZrnDAdEMid/rJI24 HNmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id; bh=I9rcrGsMDfub2AfXSK6HgEr3R3n94f26SwNYv1UvO1E=; b=D+qTb68DMg8c5du4lT28Ebok009l2W1xJQ99yc9azAx7wCeFzn9vVCAxN9pNG/YFOD dkivC4Sjt1UG82/6qF6+1x+HNj/Qigmhj0Bi3tcuw85zNAXFJAoSCvNwkXPp/+V9ZKyG snnNoz8Gg2544epDZNE8FLiDtkba173EDybDW4IqMCSdYxawu05Aa0DAxY6wdomBj9kV 2jj39gPSyzHo7igUqXv37J9Hfbu44MVQ7N1C2SKE2/l3KNXJa1BGLM8iztgkO2uLfNJO pPQuNk6R8zy2ijLCul16ydu7pydMF9W4bgOMNideeR24HsFQFF5iGvbGaKUswIHvi4wi 06Aw== 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 na18-20020a17090b4c1200b002597ed3cc4fsi5374560pjb.189.2023.06.21.11.07.19; Wed, 21 Jun 2023 11:07:31 -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 S230444AbjFURqT convert rfc822-to-8bit (ORCPT + 99 others); Wed, 21 Jun 2023 13:46:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229973AbjFURqP (ORCPT ); Wed, 21 Jun 2023 13:46:15 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EAF5B4 for ; Wed, 21 Jun 2023 10:46:11 -0700 (PDT) Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=[IPv6:::1]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qC1u6-0002mG-9H; Wed, 21 Jun 2023 19:46:02 +0200 Message-ID: <62bf84f19318c54c50f154e1eb64a179fb2389ce.camel@pengutronix.de> Subject: Re: [PATCH v10 07/11] drm/etnaviv: Add support for the dma coherent device From: Lucas Stach To: Sui Jingfeng , 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 Date: Wed, 21 Jun 2023 19:45:57 +0200 In-Reply-To: References: <20230620094716.2231414-1-18949883232@163.com> <20230620094716.2231414-8-18949883232@163.com> <8f74f0962c8bab6c832919a5340667c54e1a7ddc.camel@pengutronix.de> <66fc74ae-299c-a5de-9cfb-07ae24fb3f07@loongson.cn> <8212078bd56c54ce508205eae0ed0b69e78d4c38.camel@pengutronix.de> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.46.4 (3.46.4-1.fc37) MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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 Am Donnerstag, dem 22.06.2023 um 01:21 +0800 schrieb Sui Jingfeng: > Hi, > > On 2023/6/21 23:58, Lucas Stach wrote: > > Am Mittwoch, dem 21.06.2023 um 23:30 +0800 schrieb Sui Jingfeng: > > > Hi, > > > > > > On 2023/6/21 18:00, Lucas Stach wrote: > > > > > dma_sync_sgtable_for_cpu(dev->dev, etnaviv_obj->sgt, > > > > > etnaviv_op_to_dma_dir(op)); > > > > > etnaviv_obj->last_cpu_prep_op = op; > > > > > @@ -408,8 +421,9 @@ 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 (etnaviv_obj->flags & ETNA_BO_CACHED) { > > > > > + 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, > > > > > diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c > > > > > index 3524b5811682..754126992264 100644 > > > > > --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c > > > > > +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c > > > > > @@ -112,11 +112,16 @@ static const struct etnaviv_gem_ops etnaviv_gem_prime_ops = { > > > > > struct drm_gem_object *etnaviv_gem_prime_import_sg_table(struct drm_device *dev, > > > > > struct dma_buf_attachment *attach, struct sg_table *sgt) > > > > > { > > > > > + struct etnaviv_drm_private *priv = dev->dev_private; > > > > > struct etnaviv_gem_object *etnaviv_obj; > > > > > size_t size = PAGE_ALIGN(attach->dmabuf->size); > > > > > + u32 cache_flags = ETNA_BO_WC; > > > > > int ret, npages; > > > > > > > > > > - ret = etnaviv_gem_new_private(dev, size, ETNA_BO_WC, > > > > > + if (priv->dma_coherent) > > > > > + cache_flags = ETNA_BO_CACHED; > > > > > + > > > > Drop this change. Instead etnaviv_gem_new_impl() should do the upgrade > > > > from WC to CACHED as necessary by adding something like this: > > > I understand you are a profession person in vivante GPU driver domain. > > > > > > I respect you reviews and instruction. > > > > > > But, I'm really reluctant to agree with this, is there any space to > > > negotiate? > > > > > > > /* > > > > * Upgrade WC to CACHED when the device is hardware coherent and the > > > > * platform doesn't allow mixing cached and writecombined mappings to > > > > * the same memory area. > > > > */ > > > > if ((flags & ETNA_BO_CACHE_MASK) == ETNA_BO_WC && > > > > dev_is_dma_coherent(dev) && !drm_arch_can_wc_memory()) > > > > flags = (flags & ~ETNA_BO_CACHE_MASK) & ETNA_BO_CACHED; > > > This is policy, not a mechanism. > > > > > > Using what cache property is a user-space program's choice. > > > > > > While you are override the WC with CACHED mapping. This is not correct > > > in the concept! > > > > > Please explain why you think that this isn't correct. > > Again, > > this is user-space things! > > this is user-space things! > > this is user-space things! > > I have explained several times. > > made the decision for the user-space program is wrong. > This mode of communication isn't helpful. Please stop it. As I tried to explain to you multiple times: if userspace can break coherency by selecting the wrong mapping type then this is something the kernel should prevent. > > > It allows > > userspace to use WC mappings that would potentially cause loss of > > coherency between CPU and GPU, which isn't acceptable. > > Before made the WC works correctly,  you need the developing environment. > > userspace program can tune the BO cache mapping easily. > > Either environment or supply a conf file. > > > While with your implement, we don't have the opportunity to do debugging > and the development. You can always add a patch to your local kernel to re-allow WC mappings while you work on making them behave as expected on your platform. With the mainline kernel there is no way that the kernel driver will allow broken coherency. And as I also mentioned before, there is a clear upgrade path here: once WC mappings work as expected on your platform we can easily drop the upgrading from the kernel driver again. The userspace driver can already be changed to use CACHED BOs where beneficial on your platform in the meantime. Regards, Lucas