Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1101903pxj; Wed, 2 Jun 2021 21:16:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxirTw6Hc+4DiEy2JsoRoshm6AnK0u6tUlgCNPvuAaM1u6j8So+G90acNBMXIgOlDOUCasY X-Received: by 2002:a17:907:6288:: with SMTP id nd8mr36883145ejc.223.1622693809081; Wed, 02 Jun 2021 21:16:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622693809; cv=none; d=google.com; s=arc-20160816; b=i1kXYD/fahku+9Blb7WiK6LZMhEXxqFG/LnI0CxjEDHKJyDAXh0HIA3n3fnGxFH4IB xfDh35OMfY/3LnSDApfxJ3T1L2nJ4k10pHJuHia0VgwZHF5e6pifRpat6d0qsEJ4KkYE ILSMAme4GkhuYHoQM3rTU76uzlTw6xyENthhe3Tp66efdqq3UoEPA5qBKoOJziCI6d/n qJUHXd6/lhvjyuPO+c1mUYWTf265HEgZ11AuuaXt0K/f5mPCdrvrz6pFtPH/OOXUDJ+r FlQaYe8h2UCGa9zCecd0n/GOiSsV8LYZGOECK6jdRkR9YecmXUzHxN09magI6bacLsH3 B3og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:to:from:cc:in-reply-to:subject:date :dkim-signature; bh=mdQe7rcfBv/z++/4DywE65Kjg4R/h0ApRxAanaCZhPk=; b=VXoXqkdX0gWUb6laPDeQhGlQ3VDo7ogIJOmItd1tTkxgfA+W2H3TDvKhytnJ3WeFDd DfMpYAkm8TscLcgnbewDOC9Ufl1ZgYNm35LGopIBoxYIde8yLlkT6h9/QBgXhAm6UZa8 0o0DUr87Ee0jbLzUbIg6M+ekzVTlMBaLGuX/mSPd0XuNX72i5uJ+2oKm7bmKSKYPZ0gh 7k95IDpSSxMK0ANZY8J3doNS6kN+5uIhZezUi+ULQrM+TZYuCNSn6ZbD026FuK+7Z4Fm WAX+QXZAh2zTUCcFVbb8yLrUPWkSYex0XTaYN8x3uNDyppJDAOLuQ20O3wo0Lq17Cbxs Xmmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dabbelt-com.20150623.gappssmtp.com header.s=20150623 header.b=fd+ibb1A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q19si1569275edv.125.2021.06.02.21.16.26; Wed, 02 Jun 2021 21:16:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@dabbelt-com.20150623.gappssmtp.com header.s=20150623 header.b=fd+ibb1A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229656AbhFCEPa (ORCPT + 99 others); Thu, 3 Jun 2021 00:15:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbhFCEP3 (ORCPT ); Thu, 3 Jun 2021 00:15:29 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89D06C06174A for ; Wed, 2 Jun 2021 21:13:29 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id h16so2892191pjv.2 for ; Wed, 02 Jun 2021 21:13:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20150623.gappssmtp.com; s=20150623; h=date:subject:in-reply-to:cc:from:to:message-id; bh=mdQe7rcfBv/z++/4DywE65Kjg4R/h0ApRxAanaCZhPk=; b=fd+ibb1AZny+F8WluQ/jIE1zbUfUvf9P+Lnr32S0iD+PghCPDh2X2uqJSxvmZ8/1IL n8ROE/oO/fe7kZsF+WyG14vqVqE3FZjp2VMnXhWXkiwq53p5wObdEI9f2GQHH61kr7Ie ax3ZmpAh6zdQhXyVC6/Niw8nCnJowg9RJKGvsXnhE9tpbJpPLwtKHopnBaA5fVrLzRcg WDkUDJclcaCJG2p+mMuvw9hYxL+RpnNlSbJXa0vyEwAiSDyX+tsHniubp2yoQHhv60+F 6xY345bBCAf9+NDh9wSJBGz2MulrXgBdpGs6hkhoO+jKkNw968xbek1hakK9GopdyEsb OCGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id; bh=mdQe7rcfBv/z++/4DywE65Kjg4R/h0ApRxAanaCZhPk=; b=nsTjdaWL3I5QxLY2dOFZmT/FHD43VUSdkgd4YZoHpFK7LOkdJdr3E6MD8bboOA1zmi Kqnb9INCA0cv9XANEuS9Mn3VOdCmhgVqqYhjGg0N2nbxaHrGJvllTfVfT/X1Hv/ZHzsJ nLY0sH54CQQtGmcpu2uANLMiVxGJZsmf7YjbmIOpe0PosA6renw3FwTIoBlTmieBarK/ qg2Gng9l1LGuf7gt8W0UsSb/MdvgncaKzHvuTbbihqME4I6l/BqSpxHrwWZp72W2+qBl qv1s/dUc+Ts4nhDeYxveso1F576oT9NaW3rrDd8W5f4Ie4rVkrmc6XSe0m8HHJapz3hC VE3A== X-Gm-Message-State: AOAM533kWWwraLgYsRanMmzaPb/IAnoOg7ogTA1Fqp7QFlefglVIy+nR dCMs7FX2SXi//Gze43P/nCy0eg== X-Received: by 2002:a17:902:eac1:b029:108:4a7c:ff2d with SMTP id p1-20020a170902eac1b02901084a7cff2dmr11472514pld.62.1622693608838; Wed, 02 Jun 2021 21:13:28 -0700 (PDT) Received: from localhost (76-210-143-223.lightspeed.sntcca.sbcglobal.net. [76.210.143.223]) by smtp.gmail.com with ESMTPSA id q21sm934029pfn.81.2021.06.02.21.13.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 21:13:28 -0700 (PDT) Date: Wed, 02 Jun 2021 21:13:28 -0700 (PDT) X-Google-Original-Date: Wed, 02 Jun 2021 21:11:20 PDT (-0700) Subject: Re: [PATCH RFC 0/3] riscv: Add DMA_COHERENT support In-Reply-To: CC: anup@brainfault.org, drew@beagleboard.org, Christoph Hellwig , Anup Patel , wefu@redhat.com, lazyparser@gmail.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-sunxi@lists.linux.dev, guoren@linux.alibaba.com, Paul Walmsley From: Palmer Dabbelt To: guoren@kernel.org Message-ID: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 29 May 2021 17:30:18 PDT (-0700), Palmer Dabbelt wrote: > On Fri, 21 May 2021 17:36:08 PDT (-0700), guoren@kernel.org wrote: >> On Wed, May 19, 2021 at 3:15 PM Anup Patel wrote: >>> >>> On Wed, May 19, 2021 at 12:24 PM Drew Fustini wrote: >>> > >>> > On Wed, May 19, 2021 at 08:06:17AM +0200, Christoph Hellwig wrote: >>> > > On Wed, May 19, 2021 at 02:05:00PM +0800, Guo Ren wrote: >>> > > > Since the existing RISC-V ISA cannot solve this problem, it is better >>> > > > to provide some configuration for the SOC vendor to customize. >>> > > >>> > > We've been talking about this problem for close to five years. So no, >>> > > if you don't manage to get the feature into the ISA it can't be >>> > > supported. >>> > >>> > Isn't it a good goal for Linux to support the capabilities present in >>> > the SoC that a currently being fab'd? >>> > >>> > I believe the CMO group only started last year [1] so the RV64GC SoCs >>> > that are going into mass production this year would not have had the >>> > opporuntiy of utilizing any RISC-V ISA extension for handling cache >>> > management. >>> >>> The current Linux RISC-V policy is to only accept patches for frozen or >>> ratified ISA specs. >>> (Refer, Documentation/riscv/patch-acceptance.rst) >>> >>> This means even if emulate CMO instructions in OpenSBI, the Linux >>> patches won't be taken by Palmer because CMO specification is >>> still in draft stage. >> Before CMO specification release, could we use a sbi_ecall to solve >> the current problem? This is not against the specification, when CMO >> is ready we could let users choose to use the new CMO in Linux. >> >> From a tech view, CMO trap emulation is the same as sbi_ecall. >> >>> >>> Also, we all know how much time it takes for RISCV international >>> to freeze some spec. Judging by that we are looking at another >>> 3-4 years at minimum. > > Sorry for being slow here, this thread got buried. > > I've been trying to work with a handful of folks at the RISC-V > foundation to try and get a subset of the various in-development > specifications (some simple CMOs, something about non-caching in the > page tables, and some way to prevent speculative accesse from generating > coherence traffic that will break non-coherent systems). I'm not sure > we can get this together quickly, but I'd prefer to at least try before > we jump to taking vendor-specificed behavior here. It's obviously an > up-hill battle to try and get specifications through the process and I'm > certainly not going to promise it will work, but I'm hoping that the > impending need to avoid forking the ISA will be sufficient to get people > behind producing some specifications in a timely fashion. > > I wasn't aware than this chip had non-coherent devices until I saw this > thread, so we'd been mostly focused on the Beagle V chip. That was in a > sense an easier problem because the SiFive IP in it was never designed > to have non-coherent devices so we'd have to make anything work via a > series of slow workarounds, which would make emulating the eventually > standardized behavior reasonable in terms of performance (ie, everything > would be super slow so who really cares). > > I don't think relying on some sort of SBI call for the CMOs whould be > such a performance hit that it would prevent these systems from being > viable, but assuming you have reasonable performance on your non-cached > accesses then that's probably not going to be viable to trap and > emulate. At that point it really just becomes silly to pretend that > we're still making things work by emulating the eventually ratified > behavior, as anyone who actually tries to use this thing to do IO would > need out of tree patches. I'm not sure exactly what the plan is for the > page table bits in the specification right now, but if you can give me a > pointer to some documentation then I'm happy to try and push for > something compatible. > > If we can't make the process work at the foundation then I'd be strongly > in favor of just biting the bullet and starting to take vendor-specific > code that's been implemented in hardware and is necessarry to make > things work acceptably. That's obviously a sub-optimal solution as > it'll lead to a bunch of ISA fragmentation, but at least we'll be able > to keep the software stack together. > > Can you tell us when these will be in the hands of users? That's pretty > important here, as I don't want to be blocking real users from having > their hardware work. IIRC there were some plans to distribute early > boards, but it looks like the foundation got involved and I guess I lost > the thread at that point. > > Sorry this is all such a headache, but hopefully we can get things > sorted out. I talked with some of the RISC-V foundation folks, we're not going to have an ISA specification for the non-coherent stuff any time soon. I took a look at this code and I definately don't want to take it as is, but I'm not opposed to taking something that makes the hardware work as long as it's a lot cleaner. We've already got two of these non-coherent chips, I'm sure more will come, and I'd rather have the extra headaches than make everyone fork the software stack. After talking to Atish it looks like there's likely to be an SBI extension to handle the CMOs, which should let us avoid the bulk of the vendor-specific behavior in the kernel. I know some people are worried about adding to the SBI surface. I'm worried about that too, but that's way better than sticking a bunch of vendor-specific instructions into the kernel. The SBI extension should make for a straight-forward cache flush implementation in Linux, so let's just plan on that getting through quickly (as has been done before). Unfortunately we've yet to come up with a way to handle the non-cacheable mappings without introducing a degree of vendor-specific behavior or seriously impacting performance (mark them as not valid and deal with them in the trap handler). I'm not really sure it counts as supporting the hardware if it's massively slow, so that really leaves us with vendor-specific mappings as the only option to make these chips work. This implementation, which adds some Kconfig entries that control page table bits, definately isn't suitable for upstream. Allowing users to set arbitrary page table bits will eventually conflict with the standard, and is just going to be a mess. It'll also lead to kernels that are only compatible with specific designs, which we're trying very hard to avoid. At a bare minimum we'll need some way to detect systems with these page table bits before setting them, and some description of what the bits actually do so we can reason about them.