Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp811256yba; Fri, 26 Apr 2019 09:07:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqzOcuI4TD/tZiHLpf39AfICofencl5w7qXU0VgkNiaOwqxy33sRKmQ0zKSfJ2nwMSQgwKLy X-Received: by 2002:a17:902:b40a:: with SMTP id x10mr46714590plr.231.1556294846220; Fri, 26 Apr 2019 09:07:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556294846; cv=none; d=google.com; s=arc-20160816; b=Ar/jOaC2lC3B/+Vi0p0TntacY/YPYq76QWLnuX8jHACZ7bd3DMK/b0UI/7naS26jtC kxwDCSN5y9TGgN7QMK3aL5RSaXWvtU8WqC7TaJJN/FxcWXAtBWv5nKc/R5A/UXoyYyW9 2+FKDEGGpyg3vC3VVuLuQVee8SQGhQDXMFxAkgUVcftanYcAc32Oe/wFMO03kJl6rpB7 pk6oSgf7YZiDTlCupNxXSQX2eeZugnhclBg2jycFsDmhYCnfDL8SBKlMWHPVkFOI5CKz Sp7LAWNz9LPGcR+hNoAnIubJN+3ncqqR3HNwv8GFz/LVGM0WFAtIrqcEzy98NoRZ6zUL fEgQ== 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=OyniMiJ8fTZG2/xBPMAvV+iE8w/npczUytdBI2yqkq4=; b=cJY1OYxz46pUPgv3MdcqR/i180xLUVq9lLR0PfuhJMoirqODdfO8jIKwpbkY/Yfyw5 EGe+TvgqLiMSxd2mXZBmgsdGmI7UbNYylLNj2/puTQtV5y2I57XYEACPNa8JjD03T/KZ mFtNlNVbkFC9bl7RnSnkPyJtyiH9DNRFTbv3B4yU8uKGG3EAz7dJ40Sskc68Q8+vZOip EsVNPq48Xc6MjziDTDRvS8gE+Q2BQnIbq8aSfkkj6jLpLBEb8vVGB0SGN+c+yCBdZOt3 X7bDKx+gmVaRsITsKsZNS5EvByOYivvOyhU0rlIVhXGO4dQlc0qWylSaJ/PxmN/nkpZC 6BEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=s1pp8Xn8; 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 m18si25816689pls.18.2019.04.26.09.07.10; Fri, 26 Apr 2019 09:07:26 -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=s1pp8Xn8; 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 S1726302AbfDZQGL (ORCPT + 99 others); Fri, 26 Apr 2019 12:06:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:53656 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725984AbfDZQGL (ORCPT ); Fri, 26 Apr 2019 12:06:11 -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 3C6EC2077B; Fri, 26 Apr 2019 16:06:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556294769; bh=355LDZZF5SsAW/JoaL+5ckFu/tIXsBseyPFco5aHxrM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=s1pp8Xn88ach76ZLeCYA2w9qxm1lphHGjNx7oO7GATQVaoyWuXOvAd/SYTJlD5UoP WatczYj6RKG+1P1kAzs5c0tssr3mfz8HNf4CKc+jaXeTljvTVubWZPB7LQhmolXKUF ewNIp/eT/coCaaNXeplTnWhSwbkEiewrKuZmg95w= Date: Sat, 27 Apr 2019 00:05:58 +0800 From: Guo Ren To: Arnd Bergmann Cc: Christoph Hellwig , Gary Guo , "linux-arch@vger.kernel.org" , Palmer Dabbelt , Andrew Waterman , Anup Patel , Xiang Xiaoyan , "linux-kernel@vger.kernel.org" , Mike Rapoport , Vincent Chen , Greentime Hu , "ren_guo@c-sky.com" , "linux-riscv@lists.infradead.org" , Marek Szyprowski , Robin Murphy , Scott Wood , "tech-privileged@lists.riscv.org" Subject: Re: [PATCH] riscv: Support non-coherency memory model Message-ID: <20190426160558.GA10540@guoren-Inspiron-7460> References: <20190423001348.GA31639@guoren-Inspiron-7460> <20190423055548.GA12365@lst.de> <20190423154642.GA16001@guoren-Inspiron-7460> <20190424020803.GA27332@guoren-Inspiron-7460> <20190424055703.GA3417@guoren-Inspiron-7460> <4e6b0816-3fe9-8c0b-a749-f7f6ef7e5742@garyguo.net> <20190424142306.GB20974@lst.de> 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 Hi Arnd, On Thu, Apr 25, 2019 at 11:50:11AM +0200, Arnd Bergmann wrote: > On Wed, Apr 24, 2019 at 4:23 PM Christoph Hellwig wrote: > > > > On Wed, Apr 24, 2019 at 12:45:56PM +0000, Gary Guo wrote: > > > The RISC-V privileged spec is explicitly designed to allow the > > > techniques described above (this is the sole purpose of MSTATUS.TVM). It > > > might be as high performance as a hardware with H-extension, but is > > > definitely a legit use case. In fact, it is vital for use cases like > > > recursive virtualization. > > > > > > Also, I believe the PTE format of RISC-V is already frozen -- therefore > > > it is impossible now to merge GLOBAL and USER bit, nor to replace RSW > > > bit with another bit. > > > > Yes, I do not think we can just repurpose a bit. Even using a currently > > unused one would require some gymnastics. > > > > That being said IFF we want to support non-coherent DMA (and I think we > > do as people glue together their SOCs using shoestring and paper clips, > > as already demonstrated by Andes and C-SKY in RISC-V space, and most > > arm, mips and ppc SOCs) we need something like this flag. The current > > RISC-V method that only allows M-mode to set up such attributes on > > a small number or PMP regions just doesn't work well with the way how > > Linux and most non-trivial OSes implement DMA memory allocations. > > > > Note that I said well - in theory we can have a firmware provided > > uncached pool - that is what Linux does on most nommu (that is without > > pagetables) ports, but the fixed sized pool really does suck and will > > make users very unhappy. > > You could probably get away with allowing uncached mappings only > for huge pages, and using one or two of the bits the PMD for it. > This should cover most use cases, since in practice coherent allocations > tend to be either small and rare (device descriptors) or very big > (frame buffer etc), and both cases can be handled with hugepages > and gen_pool_alloc, possibly CMA added in since there will likely > not be an IOMMU either on the systems that lack cache coherent DMA. Generally attributs in huge-tlb-entry and leaf-tlb-entry should be the same. Only put _PAGE_CACHE and _PAGE_BUF bits in huge-tlb-entry sounds a bit strange. The gen_pool_alloc only 256KB by default, but a huge tlb entry is 4MB. Hardware couldn't setup vitual-4MB to a phys-256KB range mapping in TLB. > > One downside is that you need a little more care for drivers that > use dma_mmap_coherent() to expose coherent buffers to user space. > > Two other points about the proposal: > - Aside from completely uncached/unbuffered mappings, you typically > want uncached/buffered mappings to cover dma_alloc_wc() that is > typically used for frame buffers etc that need write-combining to get > acceptable performance I agree dma_alloc_wc is necessary, and we need add another more attribute bit in PTE: _PAGE_BUF. Perhaps using _PAGE_BUF + _PAGE_CACHE are better then _PAGE_CONHENCY. > - you need to decide what is supposed to happen when there are > multiple conflicting mappings for the same physical address. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ What's the mulitple confilcing mappings ? Best Regards Guo Ren