Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp25122525rwd; Sun, 2 Jul 2023 10:43:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlFcMtohGC1W0ZhS0AJoQzn4IN9XXE19GpuAAZhuOyLJqVmy1pV3nFLr49fNW/2DiDbGUoJr X-Received: by 2002:a17:90b:4f8d:b0:261:38ca:3c53 with SMTP id qe13-20020a17090b4f8d00b0026138ca3c53mr6660188pjb.13.1688319818960; Sun, 02 Jul 2023 10:43:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688319818; cv=none; d=google.com; s=arc-20160816; b=qegR8sqeXDd3f4J3ZjegVtMe2bDzf3888s1FjqFaXpZoPxNoaFz06ToQ8KXlnf0zNP F4iOCBYvycymwF8kAar7g3swUbuZqVNh5EmfevdjHaUgleslRKxq27Us3K4YzkWfZfuk hFr9eN1q71mPiv1ZHQv19drhekRVUHOm+RPUXlP4rzVGOeuWuGqWB++9H0UeKMLn8Vz4 gCrYh79DrC0t7oZ2lgoOcmIcxBtZyCoA0pizy5np6tCQYem4YsriH4NYt5+1m1KpABTY skCHTGhi397jWeL3yacZLdE+JgwWk2XanPLj19+TzqFJJel+XV0eYN5VAZ500lgUJgc7 M48Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=GpPrZ1mtA1MRvsZEnfwD3moEEPdXqK1lJC3CSRuMiHs=; fh=s1LC4ExJ9zYKSYi7fBX7GQ3j6n7+mYeKq7pwTuqtpsA=; b=VAr0Jq3vfLksGvLXAmUAf71J/YqGNyGov5/D3tCrqGGzWItjIvpLtfQQDfoLormcLL VviIwnHQaljuEGcMM53tdgIwUetOiV037wrSQZc9oaOaJcOHnaDgsdVEgVvLQUM7iJz8 EK/nrA6JuAmXOKFuOR5uhyacjv3MKr7EEdQoluu0DwL9THf+kGfdHlUCyhLBdoGzaa9V Tbcsgt8i4C4GjM/YUv3Fkc2A/S2adihksztDdgOAj3Uw6HN85+slGKTgS1Nx8c3XGeFc bWyVwV5nYRYRcJR7I+XAIM5ffVWzmHgaOqEKQ5G0ZN90cLhfWJG6R07rIIOtTaMrQyOP 0r5g== ARC-Authentication-Results: i=1; mx.google.com; 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 9-20020a17090a19c900b00262c9397b59si16452718pjj.161.2023.07.02.10.43.25; Sun, 02 Jul 2023 10:43:38 -0700 (PDT) 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; 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 S229772AbjGBRRa (ORCPT + 99 others); Sun, 2 Jul 2023 13:17:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229569AbjGBRR3 (ORCPT ); Sun, 2 Jul 2023 13:17:29 -0400 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D5328C3; Sun, 2 Jul 2023 10:17:27 -0700 (PDT) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 362HHF1L016977; Sun, 2 Jul 2023 19:17:15 +0200 Date: Sun, 2 Jul 2023 19:17:15 +0200 From: Willy Tarreau To: Zhangjin Wu Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de, Thomas =?iso-8859-1?Q?Wei=DFschuh?= Subject: Re: [PATCH v5 5/5] selftests/nolibc: riscv: customize makefile for rv32 Message-ID: <20230702171715.GD16233@1wt.eu> References: <2ebfb48c66b18a5fd7d0bd6b7c832a5d8ce6486f.1687176996.git.falcon@tinylab.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2ebfb48c66b18a5fd7d0bd6b7c832a5d8ce6486f.1687176996.git.falcon@tinylab.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, 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 On Mon, Jun 19, 2023 at 08:29:38PM +0800, Zhangjin Wu wrote: > Both riscv64 and riscv32 have: > > * the same arch/riscv source code tree > * the same tools/include/nolibc/arch-riscv.h > * the same ARCH=riscv value passed to top-level kernel Makefile > > The only differences are: > > * riscv64 uses defconfig, riscv32 uses rv32_defconfig > * riscv64 uses qemu-system-riscv64, riscv32 uses qemu-system-riscv32 > * riscv32 has different compiler options (-march= and -mabi=) > > So, riscv32 can share most of the settings with riscv64, add riscv32 > support like the original ARCH=riscv support. > > To align with x86, the default riscv is reserved for riscv64 and a new > riscv64 is also added to allow users pass ARCH=riscv64 directly. > > Since top-level kernel Makefile only accept ARCH=riscv, to make kernel > happy, let's set kernel specific KARCH as riscv for both riscv32 and > riscv64. > > And since they share the same arch-riscv.h, let's set nolibc specific > NARCH as riscv too. > > Usage: > > $ make defconfig ARCH=riscv32 CROSS_COMPILE=riscv64-linux-gnu- ... > $ make run ARCH=riscv32 CROSS_COMPILE=riscv64-linux-gnu- ... I'm hesitating on this one. Till now the ARCH variable taken on input was *exactly* the one used by the kernel. We include some scripts very early and we don't control the possible usage of ARCH. There's also this at the top of the makefile: # when run as make -C tools/ nolibc_ the arch is not set ifeq ($(ARCH),) include $(srctree)/scripts/subarch.include ARCH = $(SUBARCH) endif So as you can see $(ARCH) is still very intimate with the kernel's. For x86 it's no big deal because the i386 and x86_64 names are real valid archs. The difficulty we're having with riscv is that 32 and 64 are two distinct archs for all tools but not for the kernel, and it looks like the only difference is in the config itself. Given that we call all tools explicitly and that the kernel does a lot of implicit things with $(ARCH), I'm wondering if it wouldn't be more robust for the long term to instead add a "VARIANT" variable for the test only that would enforce "riscv32" or "riscv64" where needed (note that I'm not sold on this variable's name, it's to illustrate). Because if you look closely, you'll note that the nolibc source does not use this difference since its arch is always equal to the kernel's, and only the test requires it. I wouldn't be shocked by having more test options than we have architectures, and I noticed in another series that you were also proposing to extend config options, so I think it goes in the same direction. Then we could have in the test's Makefile a check for this VARIANT being set, which would preset ARCH when defined, and being used to configure Qemu. Maybe it could more or less look like this (for the selftest Makefile I mean) : # maps variants to nominal archs ARCH_VARIANT_riscv32 = riscv ARCH_VARIANT_riscv64 = riscv # default variants for some archs DEF_VARIANT_riscv = riscv64 VARIANT := ARCH ?= $(or $(ARCH_VARIANT_$(VARIANT)),$(VARIANT)) VARIANT ?= $(or $(DEF_VARIANT_$(ARCH)),$(ARCH)) Modulo the possible typos above, you probably get the idea. If ARCH is set, it will be used and automatically set the variant to the default one for the arch. And if VARIANT is set, it will set the correct default ARCH. It's possible to force the two in conflicting ways that will not work but we don't care, it's like for the rest of the variables. But at least we're never passing invalid values into ARCH anymore and I find this much safer. What do you think ? Thanks, Willy