Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4418871yba; Mon, 29 Apr 2019 20:30:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzDOg+SFTQfx4OXOwEHxBQDrDvR95BwcO0Dh3sKvABgc/3+LOG/k0P564H7y5EmdhUzdPTB X-Received: by 2002:a63:514f:: with SMTP id r15mr25337801pgl.450.1556595040846; Mon, 29 Apr 2019 20:30:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556595040; cv=none; d=google.com; s=arc-20160816; b=gHioxPVk5so624n97JLPzB3QUnHAydQXKbSjWpiHItP1aNde8INr/i6KKLbI7Aesud sHPIQeBF1y6ZmNnZ6g2ioNYNo5avHkpOe/PnvMz/wNlvDq5u/VaP6jQWG3WNAAIuw2LE rAxutPRyi4eIaaVc/qYvzGSEnJSbSqoVa5qu9GAo6tDsYDvfmj1O/zr1xNvKACTWwslt sMZUT7E71kbftavw2zFazEQszRyHP0EIG0GbH1yUoHZcZW+oyE3xzgR6h1nWIXJ+7aI6 n7N5T+yNrEOHfDtzCkZR5Asn90ThnXjGyTUjpOvosdfJuWBIEcbGUa5GTUjIG9vx9+r/ rtUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=vtNhG1t/gjeCC0By9/f8AdVW7JzOBdqXyIH5aZWIojU=; b=qzkXSd9F1ZFIRQmpIc91QBJOs8hSSHJ4VxQElTEzXiubOse0knr63aUmJ+KGIHo4KE GtLvLVKa3LPjB1toBDj5HTDWMoqILx4B6Rff7Tlv+2pi2yNrMm3fRyN5KFpv0v6vIdFU W1g591nrQzGtZlJdYOo1BSatd+VAPp8kcwhow7zCpTIGoqwlfIEqhdAoKQU3WrTENAmj 3zqc/QeMiNb+YY4QhYEp7C8jsJb8SraLWTp7dBUP2qSBE6oKfStIIRM3l1QcgyPQBTOo RDC7R1vwAAEmEJs1Fuv4MJHRvOjWCOQCYkLg//5B4FEj6TAKsnbylDHbl63Chf4JE0nF 8Y7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=h8nDHK2i; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2si35395774pgh.499.2019.04.29.20.30.22; Mon, 29 Apr 2019 20:30:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=h8nDHK2i; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729994AbfD3D30 (ORCPT + 99 others); Mon, 29 Apr 2019 23:29:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:46862 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729931AbfD3D30 (ORCPT ); Mon, 29 Apr 2019 23:29:26 -0400 Received: from guoren-Inspiron-7460 (23.83.240.247.16clouds.com [23.83.240.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 70D0720835; Tue, 30 Apr 2019 03:29:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556594964; bh=Lx4zhmDpfFLdvDNOmZItK0OkGfHXAn+WVer+CA5yQzs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=h8nDHK2i2XvOB2SbBEiwKEgXePMWpbpMBGK8OHQ0e151AMLXVtjPtpdVr6ZxizTuw ocFwd6hLq6PvJikv0D0081kzLRa+9eju/QpQn1owDqFWq9+Sn8U0rSIabdxdiC8pFV u1gk2/HKfauJGtEqhNJRiVAuJKRMctXrkxlBJjBU= Date: Tue, 30 Apr 2019 11:29:16 +0800 From: Guo Ren To: Palmer Dabbelt Cc: ren_guo@c-sky.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, tech-privileged@lists.riscv.org, Andrew Waterman , anup.patel@wdc.com, Arnd Bergmann , Christoph Hellwig , green.hu@gmail.com, m.szyprowski@samsung.com, rppt@linux.ibm.com, robin.murphy@arm.com, swood@redhat.com, vincentc@andestech.com, xiaoyan_xiang@c-sky.com Subject: Re: [PATCH] riscv: Support non-coherency memory model Message-ID: <20190430032916.GA649@guoren-Inspiron-7460> References: <1555947870-23014-1-git-send-email-guoren@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 29, 2019 at 01:11:43PM -0700, Palmer Dabbelt wrote: > On Mon, 22 Apr 2019 08:44:30 PDT (-0700), guoren@kernel.org wrote: > >From: Guo Ren > > > >The current riscv linux implementation requires SOC system to support > >memory coherence between all I/O devices and CPUs. But some SOC systems > >cannot maintain the coherence and they need support cache clean/invalid > >operations to synchronize data. > > > >Current implementation is no problem with SiFive FU540, because FU540 > >keeps all IO devices and DMA master devices coherence with CPU. But to a > >traditional SOC vendor, it may already have a stable non-coherency SOC > >system, the need is simply to replace the CPU with RV CPU and rebuild > >the whole system with IO-coherency is very expensive. > > > >So we should make riscv linux also support non-coherency memory model. > >Here are the two points that riscv linux needs to be modified: > > > > - Add _PAGE_COHERENCY bit in current page table entry attributes. The bit > > designates a coherence for this page mapping. Software set the bit to > > tell the hardware that the region of the page's memory area must be > > coherent with IOs devices in SOC system by PMA settings. > > If IOs and CPU are already coherent in SOC system, CPU just ignore > > this bit. > > > > PTE format: > > | XLEN-1 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 > > PFN C RSW D A G U X W R V > > ^ > > BIT(9): Coherence attribute bit > > 0: hardware needn't keep the page coherenct and software will > > maintain the coherence with cache clear/invalid operations. > > 1: hardware must keep the page coherenct and software needn't > > maintain the coherence. > > BIT(8): Reserved for software and now it's _PAGE_SPECIAL in linux > > > > Add a new hardware bit in PTE also need to modify Privileged > > Architecture Supervisor-Level ISA: > > https://github.com/riscv/riscv-isa-manual/pull/374 > > This is a RISC-V ISA modification, which isn't really appropriate to suggest on > the kernel mailing lists. The right place to talk about this is at the RISC-V > foundation, which owns the ISA -- we can't change the hardware with a patch to > Linux :). I just want a discussion and a wide discussion is good for all of us :) > > > - Add SBI_FENCE_DMA 9 in riscv-sbi. > > sbi_fence_dma(start, size, dir) could synchronize CPU cache data with > > DMA device in non-coherency memory model. The third param's definition > > is the same with linux's in include/linux/dma-direction.h: > > > > enum dma_data_direction { > > DMA_BIDIRECTIONAL = 0, > > DMA_TO_DEVICE = 1, > > DMA_FROM_DEVICE = 2, > > DMA_NONE = 3, > > }; > > > > The first param:start must be physical address which could be handled > > in M-state. > > > > Here is a pull request to the riscv-sbi-doc: > > https://github.com/riscv/riscv-sbi-doc/pull/15 > > > >We have tested the patch on our fpga SOC system which network controller > >connected to a non-cache-coherency interconnect in and it couldn't work > >without the patch. > > > >There is no side effect for FU540 whose CPU don't care _PAGE_COHERENCY > >in PTE, but FU540's bbl also need to implement a simple sbi_fence_dma > >by directly return. In fact, if you give a correct configuration for > >dev_is_dma_conherent(), linux dma framework wouldn't call sbi_fence_dma > >any more. > > Non-coherent fences also need to be discussed as part of a RISC-V ISA ^^^^^^^^^^^^ ^^^^^^ fences instructions? not page attributes? > extension. > I know people have expressed interest, but I don't know of a > working group that's already been set up. Is that mean current RISC-V ISA forces the SOC to be coherent memory model? Best Regards Guo Ren