Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp218427imu; Sun, 4 Nov 2018 22:59:34 -0800 (PST) X-Google-Smtp-Source: AJdET5e+QRQzSfbJ2R6MvYt8W7ZLweNY+brBnwEgtLw8Oh4R/igGH1Avk/p1FO8rvgsSWhBP95L3 X-Received: by 2002:a63:a401:: with SMTP id c1mr19092849pgf.403.1541401174316; Sun, 04 Nov 2018 22:59:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541401174; cv=none; d=google.com; s=arc-20160816; b=y8kGjREwamQJBijAYAIpnHRSVMYk8l9w/D0hZ0TwkE645nuzLazbQ5mQhQbd05vWe8 cSD+4gbie9hSH6OScMxuwE0dOj1o9/mK7Sk+rmnakuzKXmiZZi0WvZ79iZlY0SJODYAB k8LLJfxNZouT+oCtYurkIXzRXQJkqd1a67bfBFPqlrnL6BaG+nIdXki/3z7xCNbGndjq Oo9dmjQH9QEis1T2ObAfztVAlCMH/E3CxiZO3OG+VAK8fA9RBXer8xhJFFl87TiL4oE3 f4gm3XeB1beBGHOdHP1lBcs/8FcX96+IVXvPGlGGA381jqyix0bQqE0/Mvt0rWYTzcxZ L0ig== 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=p38Od5zcMcXOvnmSfjUwW9bk2bOSjWpmqofIi3dyBxY=; b=bWFpPj7qBdHf5L1vVcJhg8j2B/CXy9gXvfVLvWFK3FJzSEPZHPtDyeTZ3Z29vJBLDd BPjpKySDCOupfaN6IdxYWli5ZAj3zvAjD9FK0csl1GYoGknNea0AvTkjBPOJNj6ihldN eiyZnbA65bFnjrc98GPVQ4JXuWVGl8ruCCNgS8dn4+/aymLgecuyxfXDaB542L8H3RLk 9lZKATQDGyZRNep2DqjWw3qNAwG4K4igXix60nyR9YDuoJla2MHdUcMP/g2WyW8IraFU miCyG7TeD2gudjq/aPeGJaXEOpM6nS2aEEe27rhS4oNkYy1zJaGeYWs5BAfcDnZmt6Tu gF2g== 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 y17-v6si43958525pfb.196.2018.11.04.22.59.19; Sun, 04 Nov 2018 22:59:34 -0800 (PST) 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 S1729449AbeKEQRE (ORCPT + 99 others); Mon, 5 Nov 2018 11:17:04 -0500 Received: from 59-120-53-16.HINET-IP.hinet.net ([59.120.53.16]:62692 "EHLO ATCSQR.andestech.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728955AbeKEQRE (ORCPT ); Mon, 5 Nov 2018 11:17:04 -0500 Received: from mail.andestech.com (atcpcs16.andestech.com [10.0.1.222]) by ATCSQR.andestech.com with ESMTP id wA56webu007013; Mon, 5 Nov 2018 14:58:40 +0800 (GMT-8) (envelope-from vincentc@andestech.com) Received: from andestech.com (10.0.15.65) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.123.3; Mon, 5 Nov 2018 14:58:10 +0800 Date: Mon, 5 Nov 2018 14:58:07 +0800 From: Vincent Chen To: , CC: , , , , , , , , Subject: Re: [RFC 0/2] RISC-V: A proposal to add vendor-specific code Message-ID: <20181105065807.GA1286@andestech.com> References: <20181101174857.du2zu4vnrhpu5asf@excalibur.cnev.de> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20181101174857.du2zu4vnrhpu5asf@excalibur.cnev.de> User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [10.0.15.65] X-DNSRBL: X-MAIL: ATCSQR.andestech.com wA56webu007013 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 02, 2018 at 01:48:57AM +0800, Karsten Merker wrote: > On Wed, Oct 31, 2018 at 10:27:05AM -0700, Palmer Dabbelt wrote: > > On Wed, 31 Oct 2018 04:16:10 PDT (-0700), anup@brainfault.org wrote: > > > On Wed, Oct 31, 2018 at 4:06 PM Vincent Chen wrote: > > > > > > > > RISC-V permits each vendor to develop respective extension ISA based > > > > on RISC-V standard ISA. This means that these vendor-specific features > > > > may be compatible to their compiler and CPU. Therefore, each vendor may > > > > be considered a sub-architecture of RISC-V. Currently, vendors do not > > > > have the appropriate examples to add these specific features to the > > > > kernel. In this RFC set, we propose an infrastructure that vendor can > > > > easily hook their specific features into kernel. The first commit is > > > > the main body of this infrastructure. In the second commit, we provide > > > > a solution that allows dma_map_ops() to work without cache coherent > > > > agent support. Cache coherent agent is unsupported for low-end CPUs in > > > > the AndeStar RISC-V series. In order for Linux to run on these CPUs, we > > > > need this solution to overcome the limitation of cache coherent agent > > > > support. Hence, it also can be used as an example for the first commit. > > > > > > > > I am glad to discuss any ideas, so if you have any idea, please give > > > > me some feedback. > > > > > > > I agree that we need a place for vendor-specific ISA extensions and > > > having vendor-specific directories is also good. > > > > > > What I don't support is the approach of having compile time selection > > > of vendor-specific ISA extension. > > > > > > We should have runtime probing for compatible vendor-specific ISA > > > extension. Also, it should be possible to link multiple vendor-specific > > > SA extensions to same kernel image. This way we can have a single > > > kernel image (along with various vendor-specific ISA extensions) which > > > works on variety of targets/hosts. > > > > > > As an example or runtime probing you can look at how IRQCHIP or > > > CLOCKSOURCE drivers are probed. The vendor-specific ISA extension > > > hooks should called in similar fashion. > > > > Yes, I agree. My biggest concern here is that we ensure that > > one kernel can boot on implementations from all vendors. I > > haven't had a chance to look at the patches yet, but it should > > be possible to: > > > > * Build a kernel that has vendor-specific code from multiple vendors. > > * Detect the implementation an run time and select the correct extra > > code. > > From a distro point of view we definitely want to have one kernel > image that is bootable everywhere. Debian won't support any > platform that requires a per-platform or per-vendor kernel, and I > assume that the same will be true for Fedora and Suse. > > One thing that I have stumbled upon while looking at the patches > is that they seem to assume that X-type ISA extensions are > strictly per vendor. Although that is probably true in the > majority of cases, it doesn't necessarily have to be - I could > e.g. imagine that the DSP extensions from the PULP cores might > be used by multiple vendors. If such an extension would have > state that needs to be saved on context switch, it would need > corresponding kernel support. Using "PULP" (or any other > open-source project) as the vendor in such a case leads to > another potential issue: the patches base everything on a JEDEC > vendor ID that is compared to the contents of the mvendorid CSR, > but such a JEDEC vendor ID usually doesn't exist for open-source > implementations; the majority of those have mvendorid set to > zero. > Many thanks for kinds of comments. I quickly synthesize the comments and list them as below. 1. The kernel image shall include all vendor-specific code. 2. This kernel image can only enable particular vendor-specific features based on the CPU vendor in the running platform. - The runtime probing mechanism can refer to arm32/arm64, powerpc, IRQCHIP driver or CLOCKSOURCE driver - For some cases, such as open-source projects, using CSR $mvendorid to identify the compatibility is not appropriate. I think the above requirements are reasonable, but I have questions about the first requirement in practice. As far as I know, vendors are allowed to add specific instructions and CSRs which are incompatible with other vendors to their own ISA extensions. If I understand the first requirement correctly, it implies that we need a "super" RISC-V toolchain. This "super" RISC-V toolchain should recognize all kinds of vendor-specific instructions and CSRs, so that it can compile vendor sources into objects successfully; then it should recognize all kinds of vendor-specific relocations, so that it can link the objects successfully. Each of them is not trivial at the time of this proposal and in foreseeable future. If it will take a long time to complete this "super" toolchain, I suppose the infrastructure in this RFC might be a temporary solution before it is ready. This scheme does not suffer the compilation problems caused by the lack of the super toolchain because the selection of vendor-specific ISA extension is determined at compile time. In addition, the mechanism for checking compatibility at runtime ensures that the kernel with vendor-specific feature runs on CPUs of other vendors just like pure RISC-V kernel. In other words, this scheme, to some extent, satisfies the requirements that one kernel image is bootable everywhere. Regards, Vincent