Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp155208iog; Fri, 24 Jun 2022 01:03:08 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uaPI7TC6gIS9ImQKOenbrbfgrGhaVUX8quCfIkrE8PYOKWI1Iq4LzrDFub6LqlBtVoDvlX X-Received: by 2002:a17:902:ecd2:b0:16a:4028:8a92 with SMTP id a18-20020a170902ecd200b0016a40288a92mr15066138plh.97.1656057788186; Fri, 24 Jun 2022 01:03:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656057788; cv=none; d=google.com; s=arc-20160816; b=YuoNfsP0BQ01JvgxPxDV4bR36kroyDgTadulfezpprv2PXRZJ0v27JacUJzlL4wXpE mWbsCAZrjodtY5EAwZtUW3VHq5SaYMb6mSUfKf/2Y3GjZq1TZ6FN56+U15voH3aZqjbl 39O+9WoP+TMbE191lUM0XOF+DLii1Ut0z9SKDlpL/o5vR6wqDfx0fiuRxGxDG/GB2MMl fDyghSRzjBWR38BuewEw3XaRUh7S11W/Lv6HiLK5F3EIbkyD3WssX3LAiyZkPT5eZgSA Qi0VBNG/kiWmFJYg3FZlvruC+IGA8dSy2e4Lt2kr97P+M3fV/You6jwwuIBeTB5SLzMs fUGA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ri4S21Gvc1KBRohVBfM7Bt3KDocoWNPo0WSpLPNNlOk=; b=YZyz/A3EhJhz6MV33LmBd9VUgV3pRY/wFjtB54PBNjddP0aJPihEE7icjKLDPEOtJt muHmCImFweJq6W1pgsRORm6INpZT2v9A5hgSlbFSlc24vgv9jE5ALLujzMUpMVeRRmZS pIBQ+frhp50wQU+K5Xjl9cQD6mbHuY9ZGUC2BoAAfznaeS81lcLeyBmNAxlHXlUU3lL8 P70tKRxE/HRBvbGmwneIqeZZ8nxv0nnH8luHZ1DI3ScAz0bFfmaO5/AyDWLgI0R+nW/t b8Y4aLkYPuDJc1SjCiDc/3njgMmJzR6mBZDuSJuqdznJFVezLxTXDgy0cyVUlKpjCdbl TwAg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sntech.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e12-20020a17090301cc00b00163a84f75b2si2665111plh.519.2022.06.24.01.02.56; Fri, 24 Jun 2022 01:03:08 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sntech.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229872AbiFXHt2 (ORCPT + 99 others); Fri, 24 Jun 2022 03:49:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbiFXHt1 (ORCPT ); Fri, 24 Jun 2022 03:49:27 -0400 Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1E40522D0; Fri, 24 Jun 2022 00:49:24 -0700 (PDT) Received: from p508fdadf.dip0.t-ipconnect.de ([80.143.218.223] helo=phil.localnet) by gloria.sntech.de with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1o4e3z-0007Di-1E; Fri, 24 Jun 2022 09:49:11 +0200 From: Heiko Stuebner To: Christoph Hellwig Cc: palmer@dabbelt.com, paul.walmsley@sifive.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, wefu@redhat.com, guoren@kernel.org, cmuellner@linux.com, philipp.tomsich@vrull.eu, hch@lst.de, samuel@sholland.org, atishp@atishpatra.org, anup@brainfault.org, mick@ics.forth.gr, robh+dt@kernel.org, krzk+dt@kernel.org, devicetree@vger.kernel.org, drew@beagleboard.org, rdunlap@infradead.org, Atish Patra Subject: Re: [PATCH 3/4] riscv: Implement Zicbom-based cache management operations Date: Fri, 24 Jun 2022 09:49:09 +0200 Message-ID: <4357313.8hb0ThOEGa@phil> In-Reply-To: <20220620061607.GB10485@lst.de> References: <20220619203212.3604485-1-heiko@sntech.de> <20220619203212.3604485-4-heiko@sntech.de> <20220620061607.GB10485@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS, T_SCC_BODY_TEXT_LINE,T_SPF_HELO_TEMPERROR 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 Christoph, Am Montag, 20. Juni 2022, 08:16:07 CEST schrieb Christoph Hellwig: > On Sun, Jun 19, 2022 at 10:32:11PM +0200, Heiko Stuebner wrote: > > +#ifdef CONFIG_RISCV_DMA_NONCOHERENT > > +#define ARCH_DMA_MINALIGN L1_CACHE_BYTES > > +#endif > > This needs to be greater or equal to riscv_cbom_block_size, but the > core code requires a compile time constant here. So we'll need a big > fat comment here, and panic if riscv_cbom_block_size is > > L1_CACHE_BYTES/ARCH_DMA_MINALIGN in the code that queries > riscv_cbom_block_size. ARM people also had this nice WARN_TAINT to warn when the similar case happens on ARM64 and the ARCH_DMA_MINALIGN is smaller than the register value so I've added a similar mechanism. I've read numerous mails from Torvalds over time that panic-ing should only ever be the very very last resort, so that WARN_TAINT looks like a less drastic option while still generating that big warning to users. > Note that the arm64 folks are looking into making this variable or > killing it off in this current form, so things might be getting better > soon. > > > +void arch_sync_dma_for_device(phys_addr_t paddr, size_t size, > > + enum dma_data_direction dir) > > +{ > > + void *vaddr = phys_to_virt(paddr); > > + > > + switch (dir) { > > + case DMA_TO_DEVICE: > > + ALT_CMO_OP(clean, vaddr, size, riscv_cbom_block_size); > > + break; > > + case DMA_FROM_DEVICE: > > + ALT_CMO_OP(inval, vaddr, size, riscv_cbom_block_size); > > + break; > > For this also see: > > https://lore.kernel.org/all/20220606152150.GA31568@willie-the-truck/ > > and > > https://lore.kernel.org/linux-arm-kernel/20220610151228.4562-1-will@kernel.org/T/ so from that discussion, it looks like a "clean" should happen here to prevent stale bytes (not written to by the dma transfer itself) in the buffer area I guess. I'll give that a spin :-) > > +void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, > > + const struct iommu_ops *iommu, bool coherent) > > +{ > > + dev->dma_coherent = coherent; > > +} > > This probably wants a sanity check warn if coherent if false without > any support for cache flushing as that will cause data corruption. I've added a riscv_noncoherent_supported() call that will track that "somebody" implemented non-coherence functionality from their setup function (zicbom_probe, thead_errata-probe) and a matching second WARN_TAINT in arch_setup_dma_ops() when coherent value and availability of non-coherence handling is not matched. Heiko