Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2707721yba; Mon, 22 Apr 2019 11:29:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqwIfe2RHgobbrbH3IgTktic0y1VPrc7WWNrYoZjUf8CDzuGbQTI/2RlwNwq/Ncp7XexfhtO X-Received: by 2002:a17:902:9a85:: with SMTP id w5mr21609005plp.157.1555957750043; Mon, 22 Apr 2019 11:29:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555957750; cv=none; d=google.com; s=arc-20160816; b=ZAz11sWTjCvEvZ9bb+zPaP6CEwwJeyViHHSSIBr6WvDiU61F1VHwLtlRB0RP+2isAY 15BgyvhNAphBlxce1m6BFJx2nq1+FFy5R4lwEdCDksLEEcEusnYbdVwKqRZ5FGMoK1mt ZhJzltPgH+FGcemnoVcQ6hzdDiflD66y5skSu7sbZrZCm4zrCadUqyemOovxhwJ5QWgd CbPQKfUGRFfgaWBWDYLzOH/+oVi1V4ViJ5ylOMHtjMSHtDSMFqgKzDlAhu6DbJBY+bBC v7SEpQibOms0ioBTqaHaxE6Lv6Sj4dgeCuj6WmnDYYCq9Mow05XuTWKTX+VrgGMq8/cG ZXpA== 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; bh=kjaiJavKqg1ezW90rphZPYnLz6qOa+VVoxYNevAEMa4=; b=nSSimp8A3rskMFMrm3zwQzCQcyjd8fcuRVcN8yXzW61toHXa1mb1ez4NPjby3uEWHE izrwJtzkjIydpUIoS/QhQSjaXcUgFIwY5ItZ+em5ZgtnWZgGfuAmVQE7fC0GRhn0dA3X uidNiVr6L+4CPlgu3W5FwfDLqEzX3ubR+uPZcnLVDLDCeZoJO/8bVYgjRsVaUpdDvP3f t+l3MKn+97Ehjs4LqaWDfIKsZgHkJADU8tNsHbXdZNUHQPdX7JxduMNS0a6TD43UTRIP jr+069+8ecqyg2XkNxhyeHRnopayUYZqTf62a79LeLP65KS+sDupqmL5NdFcTQsDKlxV M6dg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k22si13817722pfo.145.2019.04.22.11.28.54; Mon, 22 Apr 2019 11:29:10 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728086AbfDVQSd (ORCPT + 99 others); Mon, 22 Apr 2019 12:18:33 -0400 Received: from verein.lst.de ([213.95.11.211]:40436 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726098AbfDVQSd (ORCPT ); Mon, 22 Apr 2019 12:18:33 -0400 Received: by newverein.lst.de (Postfix, from userid 2407) id 0C73668AFE; Mon, 22 Apr 2019 18:18:15 +0200 (CEST) Date: Mon, 22 Apr 2019 18:18:14 +0200 From: Christoph Hellwig To: guoren@kernel.org 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 , Arnd Bergmann , Christoph Hellwig , Greentime Hu , Marek Szyprowski , Mike Rapoport , Palmer Dabbelt , Robin Murphy , Scott Wood , Vincent Chen , Xiang Xiaoyan Subject: Re: [PATCH] riscv: Support non-coherency memory model Message-ID: <20190422161814.GA30694@lst.de> 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: <1555947870-23014-1-git-send-email-guoren@kernel.org> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 22, 2019 at 11:44:30PM +0800, guoren@kernel.org wrote: > - 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 > > - 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: Please don't make this an SBI call. We need a proper instruction for cache flushing and invalidation. We'll also need that for pmem support for example. I heard at least one other vendor already had an instruction, and we really need to get this into the privileged spec ASAP (yesterday in fact). If you have your own instructions already we can probably binary patch those in using the Linux alternatives mechanism once we have a standardized way in the privileged spec. We should probably start a working group for this ASAP unless we can get another working group to help taking care of it. > +#define pgprot_noncached pgprot_noncached > +static inline pgprot_t pgprot_noncached(pgprot_t _prot) > +{ > + unsigned long prot = pgprot_val(_prot); > + > + prot |= _PAGE_COHERENCY; > + > + return __pgprot(prot); Nitpick: this can be shortened to return __pgprot(pgprot_val(prot) | _PAGE_COHERENCY)); Also is this really a coherent flag, or an 'uncached' flag like in many other architectures? > +++ b/arch/riscv/mm/dma-mapping.c This should probably be called dma-noncoherent.c It should also have a user visible config option so that we don't have to build it for fully coherent systems. > +void arch_dma_prep_coherent(struct page *page, size_t size) > +{ > + memset(page_address(page), 0, size); No need for this memset, the caller takes care of it. > diff --git a/arch/riscv/mm/ioremap.c b/arch/riscv/mm/ioremap.c > index bd2f2db..f6aaf1e 100644 > --- a/arch/riscv/mm/ioremap.c > +++ b/arch/riscv/mm/ioremap.c > @@ -73,7 +73,7 @@ static void __iomem *__ioremap_caller(phys_addr_t addr, size_t size, > */ > void __iomem *ioremap(phys_addr_t offset, unsigned long size) > { > - return __ioremap_caller(offset, size, PAGE_KERNEL, > + return __ioremap_caller(offset, size, PAGE_KERNEL_COHERENCY, > __builtin_return_address(0)); > } > EXPORT_SYMBOL(ioremap); I think ioremap is a different story, and should be a separate patch.