Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp5619770iog; Thu, 23 Jun 2022 01:44:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vuOut8TH0jH8nXvDPFzSm/JEjWhe3nKN0onJtr1szP5lbl0CPzKan6LPnwqCOVIQU1z7tV X-Received: by 2002:a17:907:30cb:b0:722:e898:c9c8 with SMTP id vl11-20020a17090730cb00b00722e898c9c8mr6932977ejb.465.1655973865900; Thu, 23 Jun 2022 01:44:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655973865; cv=none; d=google.com; s=arc-20160816; b=KtWyAXa28GLlD7dj0hxrwWuT64RI9mKi3HggWXaqA5qKqbBMJcKiQnbLg12q9J9CXV 4SJ4tQ+u9IDXBTfIZqGX+9dcn6FchtuQ/qN1gJXMss6AA9sd5nIE8C1A93Qs2mZ93CcH 7DYL8gI0+6ofSjj+kSF0XXo/MjSoSLbeKKoSCWwjpryzv4RGuRa0Jtn7nseZKQc0alUW laRMfkwoQlzUeBS1SeHujEhMYoxG7eWDlN0JZdjmPmRIkS4+AQn4Q13FwpVrWOyW7Apo x0RVaFaXhYl0Naui06XWkhqeSKNuRCv4MbZGWwHQymrIt7H9YfKpRJmu+CymTtuh/WSo ofxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=UlV8O4i6QxVgFN3gmPo5wT94WhgidKRhSjDe6s3jf1Q=; b=ziV+2coLdX9uVnWYIwdCd4vIIzuXn1+iRGYRJisx4toMx9tkhjVfMyoSFoU8NmrrE3 lyuX0CwwOk8PNbU55Y/0CTfgsBnlCSYC7fOTJN3i5f52bgrYPQNa0VwvoxXNzg1VXFjF +E/uK/XvE7FpvJdKHPzsulbQ9xrjeDGOK23HQGOCsmh39gkOlY8biBNmuPTpTXgJtCBw VCdPjPSDw6V8InUGMyOsz3DabBMFfsFDz0bL9Lw0F1F7lXlRj2/DahzJY7gpsj2fheDL NYoudsTtsrO9M4XI/yKqyfF/MUMkIeGq4Gp7deIBveNgWaKmlmAtyo8Om1IfyMYNYgc3 erLQ== 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 22-20020a170906021600b00711fa454fb3si918230ejd.889.2022.06.23.01.44.01; Thu, 23 Jun 2022 01:44:25 -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 S231193AbiFWIFC (ORCPT + 99 others); Thu, 23 Jun 2022 04:05:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231150AbiFWIE4 (ORCPT ); Thu, 23 Jun 2022 04:04:56 -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 99B9043ED8 for ; Thu, 23 Jun 2022 01:04:55 -0700 (PDT) Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] 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 1o4Hpc-00035t-7h; Thu, 23 Jun 2022 10:04:52 +0200 Message-ID: <4b69f9f542d6efde2190b73c87096e87fa24d8ef.camel@pengutronix.de> Subject: Re: DMA-buf and uncached system memory From: Lucas Stach To: Christian =?ISO-8859-1?Q?K=F6nig?= , Pekka Paalanen Cc: "Sharma, Shashank" , lkml , dri-devel , Nicolas Dufresne , linaro-mm-sig@lists.linaro.org, Sumit Semwal , linux-media Date: Thu, 23 Jun 2022 10:04:49 +0200 In-Reply-To: <954d0a9b-29ef-52ef-f6ca-22d7e6aa3f4d@amd.com> References: <91ff0bbb-ea3a-2663-3453-dea96ccd6dd8@amd.com> <9178e19f5c0e141772b61b759abaa0d176f902b6.camel@ndufresne.ca> <20220623101326.18beeab3@eldfell> <954d0a9b-29ef-52ef-f6ca-22d7e6aa3f4d@amd.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-1.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb 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 23.06.2022 um 09:26 +0200 schrieb Christian König: > Am 23.06.22 um 09:13 schrieb Pekka Paalanen: > > On Thu, 23 Jun 2022 08:59:41 +0200 > > Christian König wrote: > > > > > The exporter isn't doing anything wrong here. DMA-buf are supposed to be > > > CPU cached and can also be cache hot. > > Hi, > > > > what is that statement based on? > > On the design documentation of DMA-buf and the actual driver > implementations. > > Coherency and snooping of the CPU cache is mandatory for devices and > root complexes in the PCI specification. Incoherent access is just an > extension. > > We inherited that by basing DMA-buf on the Linux kernel DMA-API which in > turn is largely based on the PCI specification. > > > Were the (mandatory for CPU access) cpu_access_begin/end functions & > > ioctls not supposed to ensure that CPU cache is up-to-date / CPU cache > > is fully flushed out? > > No, those functions are to inform the exporter that the importer has > started and finished accessing the buffer using the CPU. > > There is no signaling in the other direction. In other words the > exporter doesn't inform the importer about CPU accesses because it is > the owner of the buffer. > > It's the responsibility of the importer to make sure that it can > actually access the data in the buffer. If it can't guarantee that the > importer shouldn't import the buffer in the first place. This is not really correct. DMA-buf inherited the the map/unmap part from the DMA API, which on cache coherent architecture is mostly a no- op or ties into the IOMMU implementation to set up the pagetables for the translation. On non cache coherent architectures this is the point where any any necessary cache maintenance happens. DRM breaks this model by caching the DMA-buf mapping for performance reasons. In the DMA API keeping things mapped is also a valid use-case, but then you need to do explicit domain transfers via the dma_sync_* family, which DMA-buf has not inherited. Again those sync are no-ops on cache coherent architectures, but do any necessary cache maintenance on non coherent arches. Regards, Lucas