Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1502050pxp; Thu, 10 Mar 2022 06:44:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJysic3szb4tllZXiqnZpmdL6+9hi6CYNv35062TmvLF/+ghc+2wF6To1HrHNvnuL/Cl2R4O X-Received: by 2002:a05:6a00:15c6:b0:4f0:fc4d:35d1 with SMTP id o6-20020a056a0015c600b004f0fc4d35d1mr4961889pfu.23.1646923446014; Thu, 10 Mar 2022 06:44:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646923446; cv=none; d=google.com; s=arc-20160816; b=DzV+1RnTNVQ8+NQDCl6BJus1xryoUmDyxKvvaP3f13LaUTSpkANIK6XF/aKiBOm2yl FzytvtswLE5YJLJUjZCe9r6XtMfFEBgNBY76sgsRdoJi08o4huEljUKt01RGLV/iH0xh blCye5OQsvpsQLP7mrZUYZYPV3PbHxp6Erefz/NWmaYsfYGEqEXnTvc1LexSs5doiHrX lEBq+JBny4NlzONBLRSF6VfVRS3KF3Lbgr7tqXsic/0YZb5Ddps2UgTLZJPoP2w3DlJy 4J4HhJWbX9nAN/WHruHFwUIH/P/M5ylsQW51QypwJUpP6Fn6AMcd36YBDuLlHtdn/Nv3 9U/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:sender:dkim-signature; bh=t+4GBSdTIkEMdBL0QpKFacwJHhXFt5RhqlKal5bFBiE=; b=S/bowrMlNUJglgvpBRMZXHvgbw+SBxLwKxEpvZbfDC7y9End9WzKkctnS8yACwp4RL okZ4SM7Ps6D2p2TvysL0M8Uj5MGNL0v0PN+ASN4E9xqErWCjpkEmqQ3Lm62RgPjR7buR PtS8HAJxqjslx57uL0dED/56QF9oi7w4Pw2/P921EGPfgWeiAkEXjtXvkr6M7Vu88ZcP 1g1ZcsWIo8mrtpir9wuAZOJfTfG6TPjORkP2adqSmC7YxnjrUVsSRNaMGwK3sMOQ6aKt rDqiMbyuKW3e1n3pvmZqAG+KAtjpVeDD62kZDqWm01Wnbou4Dytn/PxB+HvnXm9d12Ou YQIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@michaelkloos.com header.s=k1 header.b=mzoV1Ib7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d30-20020a631d1e000000b00340c78427e0si5004567pgd.389.2022.03.10.06.43.49; Thu, 10 Mar 2022 06:44:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@michaelkloos.com header.s=k1 header.b=mzoV1Ib7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240820AbiCJJcO (ORCPT + 99 others); Thu, 10 Mar 2022 04:32:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232156AbiCJJcN (ORCPT ); Thu, 10 Mar 2022 04:32:13 -0500 Received: from m228-4.mailgun.net (m228-4.mailgun.net [159.135.228.4]) by lindbergh.monkeyblade.net (Postfix) with UTF8SMTPS id 1DA62139CEB for ; Thu, 10 Mar 2022 01:31:10 -0800 (PST) DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=michaelkloos.com; q=dns/txt; s=k1; t=1646904672; h=Content-Transfer-Encoding: Content-Type: In-Reply-To: From: From: References: Cc: To: To: Subject: Subject: MIME-Version: Date: Message-ID: Sender: Sender; bh=t+4GBSdTIkEMdBL0QpKFacwJHhXFt5RhqlKal5bFBiE=; b=mzoV1Ib7gmIs3lXvXWi3O33ALd+7sKKvQjXd0tESVVeCEXcUlSW2dzYfh+AMWnfz+k7Z9dIZ 4reW/r9EVi6+7FJPHt+QPa22iNT6qrvo7W2kIdLBSMIPRv1nPbn++zXvI9ezBiUb6wWeou+o MVpFpJYcw3IrP4GOjG0/JYtxkhE= X-Mailgun-Sending-Ip: 159.135.228.4 X-Mailgun-Sid: WyI5NjYzNiIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgIjQ4Y2MwIl0= Received: from drop1.michaelkloos.com (drop1.michaelkloos.com [67.205.190.89]) by smtp-out-n07.prod.us-east-1.postgun.com with SMTP id 6229c5572f1b1e8f79a3d165 (version=TLS1.3, cipher=TLS_AES_128_GCM_SHA256); Thu, 10 Mar 2022 09:31:03 GMT Sender: Michael@michaelkloos.com Received: from [192.168.0.103] (cpe-173-88-115-50.columbus.res.rr.com [173.88.115.50]) by drop1.michaelkloos.com (Postfix) with ESMTPSA id 3A6F540176; Thu, 10 Mar 2022 09:31:03 +0000 (UTC) Message-ID: <8f06a08e-c1b3-066f-bd9e-1f2d686492fa@MichaelKloos.com> Date: Thu, 10 Mar 2022 04:31:02 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH] riscv: Work to remove kernel dependence on the M-extension Content-Language: en-US To: Palmer Dabbelt , Christoph Hellwig , Arnd Bergmann Cc: Paul Walmsley , aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org References: From: "Michael T. Kloos" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As far as I can tell, it's simply a compiler flag to enable or disable it. The only complicating issue that I found was the BPF JIT. That is a special case amounting to a compiler within the kernel itself and can be patched or set to depend on M. There is still the BPF interpreter. The kernel doesn't depend on the C-extension. I have grepped through the source code where that symbol is referenced, the checking of instruction alignment constraints, and various checks used to make that work are much more extensive than I expected, yet that is supported. To quote the commentary from the beginning of chapter 2 (Base-I) of the RISC-V spec: > "RV32I was designed to be sufficient to form a compiler target and to > support modern operating system environments. The ISA was also designed > to reduce the hardware required in a minimal implementation. RV32I > contains 40 unique instructions, though a simple implementation might > cover the ECALL/EBREAK instructions with a single SYSTEM hardware > instruction that always traps and might be able to implement the FENCE > instruction as a NOP, reducing base instruction count to 38 total. > RV32I can emulate almost any other ISA extension (except the A extension, > which requires additional hardware support for atomicity). > > In practice, a hardware implementation including the machine-mode > privileged architecture will also require the 6 CSR instructions. > > Subsets of the base integer ISA might be useful for pedagogical purposes, > but the base has been defined such that there should be little incentive > to subset a real hardware implementation beyond omitting support for > misaligned memory accesses and treating all SYSTEM instructions > as a single trap." This is all a noble goal of RISC-V, to create a minimal, yet robust ISA. I'm not arguing to support no-A, as stated in the commentary, atomic can not be emulated (I mean, maybe you could by taking over sscratch) and the atomic properties of the CSR instructions. But that does seem hacky.) and everything else is handled in the Base-I (Not including Zicsr). The kernel supports rv(32/64)ima so to draw the line in the sand that rv(32/64)ia is unacceptable seems silly. One of my concerns here is that if support is not added, that people may start writing assembly that uses M instructions and other non-portable stuff. This will make a future port more difficult. I do not have real hardware like this but I do have an emulator that implements rv32iasu. Eventually I want to build a HART implementation out of real hardware logic chips. Adding M, adds hardware complexity and I think that it is better to do in software for such a minimal case. Sure it will be slower than having native hardware M support. Firmware emulation will be even slower than that. I'd much rather have the option in the kernel to switch this on or off. I am not trying to argue that the kernel should bend over to support my pet projects, but it seems quite strange and arbitrary to draw the line here over such a beautifully modular and minimal ISA. > there's an infinite amount of > allowable RISC-V implementations, we'll all go crazy chasing them > around. 2 points on that: 1) Then it would seem logical to have the kernel target the most minimal implementation to get the widest support. 2) I actually don't think this is entirely true, or at least not in the sense that it is relevant to the kernel. Atomics are needed for a modern system. The kernel needs to know about the floating-point support because it needs to handle the clean-up and context-switching of the additional floating point registers. The kernel needs to know about the C extension because of the ramifications to alignment. Everything else is just gravy. If sometime in the future the L-extension or the B-extension are finished and implemented in future hardware, unless they make some very strange decisions, I don't see why a kernel built today couldn't run on that hardware with userspace software taking advantage of those native features. Sure, in that situation, the kernel binary wouldn't be taking advantage of them. But then wouldn't you want to add CONFIG_RISCV_ISA_L and CONFIG_RISCV_ISA_B in said future kernel so that the compiler is passed an -march value such that the kernel can take advantage of these new native hardware features? It seems to me that this is the grand vision in the modularity of both the RISC-V ISA and the C programming language. We aren't writing everything in assembly for a reason. I don't think it makes sense to stop one extension away from what the RISC-V spec documents themselves state is the intended minimal system capable of running a full modern operating system. I think it is an arbitrary limit to the portability of the kernel. Michael On 3/10/2022 2:34 AM, Palmer Dabbelt wrote: > On Wed, 09 Mar 2022 23:06:22 PST (-0800), Christoph Hellwig wrote: >> Why? > I have no idea, but this has come up a few times before. > IIRC the original port had a no-M flavor (don't remember if it even made > it to the original patch submission, but it was around for a bit).  We > decided to drop this under the theory that nobody would use it: > essentially, if you can afford the handful of MiB of memory required to > run Linux then you've probably got a multiplier. > If someone has hardware that lacks M and users care about running Linux > on that then I'm happy to support it.  I'll still point out the > silliness of that decision, but if it's too late to change things then > I'd rather support the hardware.  If it's one of these "fill out every > possible allowed ISA flavor, even if nobody has one that runs Linux" > then I don't see a reason to bother -- there's an infinite amount of > allowable RISC-V implementations, we'll all go crazy chasing them > around. > FWIW: to a first order, that applies to the no-A stuff as well (though > that got dropped because the Arm folks pointed out a way to support that > was way better than ours).