Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp216493lqo; Tue, 7 May 2024 18:38:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWnzUqu18WWvJf0b003vvEZBvghOPxPkvXK6gq+xHsgt2boOvjZVaLPzygantyEphkQgtNISNgflVS3NacFVrdkbpKtuWecPjp1dPSYjw== X-Google-Smtp-Source: AGHT+IFWNLwi0RVzBRqm5o7RCYcrFzrICManaEo7nHl5oha+etmh6gCZj5FHd5m2/tulak/OT8e7 X-Received: by 2002:a05:6870:f716:b0:22e:a036:c33a with SMTP id 586e51a60fabf-24097bdc9e3mr1435087fac.6.1715132285960; Tue, 07 May 2024 18:38:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715132285; cv=pass; d=google.com; s=arc-20160816; b=ftMmomz+MCWNx2CMD88yzfJfWDWO3mU+TVGe25fU1g9tB2QFX4FuhUzO9ocu3pgS2i 5919wsy1ZVn74bN5Ak9Swz0Zq6OZBzycvaRIrmFw8gypGmSlmqXtFPW/RSmHBr++ek33 k9qmZvz9CPLiV+A94ivoYKfybjtwLSfrliQXLS5Io4LBD2NwAlv96GJYJdBQ/dKPpFjr 1+TK7u0gOxWM1LjQbXJeG4eRBxCp7eYvyktylILjmY1h49uKwGZUNfLu0GnHLzutR0ao ONULS4/exQXlTbSOD7hR7ET+cbFNZEaFu2mkF2Sre73bdt74p1hIhGE0MjY1pF5Bef6r ax1w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=G63nKFkjY3qHnS0X1QIzt6sf9vbSpbh90Xj2nxjAK3E=; fh=LJksHFPeZyfVM6bYMfPlrEDpx3XvD+5JAhuZ7eTjyLE=; b=cZpJClwWd+oscrwJtTSkLjeuRj7UJ2b9qD8DmTZZg3me4giNqJ+vm7oHVJYdF4Rv/r tUVfVyCKgVD7eoICIQU7Fyo7P8mPZy4IOUnZct8UauwqV6Mv0OTR1bcVNS4vSA2SaEs7 17n8C1uvTX+VOLT/8xbA2q9fvxwjY5oAOhVe00Xnh+P7i9cVTs5qgO+Quqz8twHAc6Vu AfBcB66MfuLVw3H4dDj13TzzAhaXVU/zR7KJEeZBGZbKCKapvSQ0oa63/E6HSguQAe+t quvyJZYrpTi+qJhEH/dn421pIKLtLw7jhsuis9Z4Iz4RnV20o5NxY/GBAl/7xKjkL2UX CDjQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=tapD0THj; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-172604-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172604-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w2-20020aa79a02000000b006f450760ce5si8827335pfj.225.2024.05.07.18.38.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 18:38:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172604-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=tapD0THj; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-172604-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172604-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 89D6A283AA1 for ; Wed, 8 May 2024 01:38:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 05E0B14A98; Wed, 8 May 2024 01:36:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="tapD0THj" Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A76B811CB4 for ; Wed, 8 May 2024 01:36:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715132214; cv=none; b=TGhtX4fWk8y+ab+zhB9mjU/fZIV3yFkeuYEscc2VMx/NqedkU00WYt0AlSrTV2KlciwxoxWP+xcvPogJv1R7jYz/n1cAglml//lm//bP9CsmtHCnxUl/9X8FUqFA1U6tv+yqrC4og7uWki4b/GCyY1tZpEPfImx1lADxUJtskq4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715132214; c=relaxed/simple; bh=mhWqJj1RP0LVjsRT3VtWySRs+UTs7hL4pCht9UF8zQ0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bmjvBWIjxaVcKZ4vzsDiDWXvUK7me6wPW7yw+BY+t73eT/SmYvNNCG9euO/02VIWzdHC+kg3mvg67l/xQGtYMzwngCiuLBJSBH3Oll8CkmmL9tqKerGa1IBE+NzCA2u4nrHHyiQrikPclaR0CVZ9njpNq5Oj4j6KLngdZzHleNg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=tapD0THj; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2ac9b225a91so2707638a91.2 for ; Tue, 07 May 2024 18:36:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715132212; x=1715737012; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=G63nKFkjY3qHnS0X1QIzt6sf9vbSpbh90Xj2nxjAK3E=; b=tapD0THj+sAOFGVZM/hZBlylZnmyshZjORu+OQca3qCaz08VtS40b8BFFqBtFygGb1 dUqMI3LSmXdsA9SmfyJ84V72cbwBGrCZj4LaDBFeL5iS0PBmZnTXLqUTzrIr3cb9qo8F 7YaJi82P/lm5VgoWl5ayeGe7LA990PgNQV2X39Z8G1KNumkbnOuXUoKE4MiDiKZuZLJi u7gNB8F3bqZduw07dj86HZf9RN/KdGmP+laZYuKz6Az4sXfPQOpCoxssL0u+wesw4SwU PE/PAQ4ip+DE5E/OZO1yFu5K8Uc8malwDEilU1GC/97dLFoKmv/5OuOrllUwuLyJKqxU IZ6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715132212; x=1715737012; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G63nKFkjY3qHnS0X1QIzt6sf9vbSpbh90Xj2nxjAK3E=; b=EsgoaBgRqLkApd0alMM7FwTJWzbj3BlMilwAlXW4esVYN1SSWLnzgiDkmZCT7/gnRI uOxrs0vs7G/5zt5X3XCEx2Ge8qJ7LOsPa5y2q36HMTQJAv8RVOUwby1e8Jnuw0u6ssJO x8NbKzKKm1t1epX/2tYa8Xirf/OM4B5mb3F1/YYefzBycnjyaX1ZulviqhPzpzvBJ/rA TTiU9O7yczXkzVLPk9WdWKWpOHFcIuY372gmyGrAxL08qLagOwKqnvcp8c8zSNv/4T4P 4f3pAbMzg9ief62oFJMpn6sidzdtwJFohH7NJxpOR/6UdBr/zRCzlZ7hv2ka59EXLvJG l6qQ== X-Forwarded-Encrypted: i=1; AJvYcCUFW84qqYumgjvSFMMCULgimbOeb+0/CGKVgDjTkhVF/wMncnVR8/tYUh4iDyBegRBgwOR12pRsF+I5e0L9jxL1sQPysUoy3BT4eaUQ X-Gm-Message-State: AOJu0Yx3UBZGfiN1aEjLoNzohyiklOGOZkKefvcuEJ0CxuX995qGUg6F rupuDNzZWBvx1zsoyIWbmK2e/W5UJDlqFqbllXeyVsrICXbxqZywAGeUQkE6Rwg= X-Received: by 2002:a17:90a:5d06:b0:2b2:7c42:bf6e with SMTP id 98e67ed59e1d1-2b6165aa078mr1175508a91.12.1715132211950; Tue, 07 May 2024 18:36:51 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b62863a265sm171994a91.10.2024.05.07.18.36.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 18:36:51 -0700 (PDT) From: Charlie Jenkins Date: Tue, 07 May 2024 18:36:33 -0700 Subject: [PATCH v2 7/8] riscv: Add PLATFORM_SUPPORTS_RISCV_ISA_ZBC Kconfig option Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240507-compile_kernel_with_extensions-v2-7-722c21c328c6@rivosinc.com> References: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> In-Reply-To: <20240507-compile_kernel_with_extensions-v2-0-722c21c328c6@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Song Liu , Xi Wang , =?utf-8?q?Bj=C3=B6rn_T=C3=B6pel?= , =?utf-8?q?Cl=C3=A9ment_L=C3=A9ger?= , Jessica Clarke , Andy Chiu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715132198; l=3248; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=mhWqJj1RP0LVjsRT3VtWySRs+UTs7hL4pCht9UF8zQ0=; b=sOz5JQJkzaPJCxTxqkvkSdeiQG9Ioekkp/cr6I56ZbEo4JJzatL3p2LLjxH4sfk9h/40qVxWB OEQki4PEQ2ECjcdqQ6LE0ponkjrcIiw/2Oy+cAKFQ+URoJ4CqY/pRsA X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= Zbc can optimize kernel instruction sequences. Add a config option PLATFORM_SUPPORTS_RISCV_ISA_ZBC that allows arbitrary Zbc instruction sequences to be emitted by the compiler. The existing "RISCV_ISA_ZBC" option is repurposed to be used to by kernel code to determine if either PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBC or PLATFORM_SUPPORTS_RISCV_ISA_ZBC has been set. Signed-off-by: Charlie Jenkins --- arch/riscv/Kconfig.isa | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ arch/riscv/Makefile | 1 + 2 files changed, 52 insertions(+) diff --git a/arch/riscv/Kconfig.isa b/arch/riscv/Kconfig.isa index e7f28dc44137..b7399f236bba 100644 --- a/arch/riscv/Kconfig.isa +++ b/arch/riscv/Kconfig.isa @@ -289,3 +289,54 @@ config PLATFORM_SUPPORTS_RISCV_ISA_ZBB systems that do not support the Zbb extension. endchoice + +config TOOLCHAIN_HAS_ZBC + bool + default y + depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zbc) + depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbc) + depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900 + depends on AS_HAS_OPTION_ARCH + +config RISCV_ISA_ZBC + bool + +choice + prompt "Zbc extension for bit manipulation instructions support" + default PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBC + help + This selects the level of support for Zbc instructions to be + built into the Linux Kernel. This does not impact whether Zbc + instructions are allowed to be emitted by user-space code. + + The Zbc extension provides instructions to accelerate carry-less + multiplication. + +config PROHIBIT_RISCV_ISA_ZBC + bool "Prohibit Zbc instruction sequences" + depends on NONPORTABLE + help + Regardless of if the platform supports Zbc instructions, + prohibit the kernel from emitting Zbc instructions. + +config PLATFORM_MAY_SUPPORT_RISCV_ISA_ZBC + bool "Allow Zbc instruction sequences if supported" + depends on TOOLCHAIN_HAS_ZBC + depends on RISCV_ALTERNATIVE + select RISCV_ISA_ZBC + help + Add support for enabling optimisations in the kernel when the + Zbc extension is detected at boot. + +config PLATFORM_SUPPORTS_RISCV_ISA_ZBC + bool "Emit Zbc instructions when building Linux" + depends on TOOLCHAIN_HAS_ZBC + depends on NONPORTABLE + select RISCV_ISA_ZBC + help + Adds "zbc" to the ISA subsets that the toolchain is allowed to emit + when building Linux, which results in Zbc instructions in the + Linux binary. This option produces a kernel that will not run on + systems that do not support the Zbc extension. + +endchoice diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index c8ec38b9880a..57457d15e9a4 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -68,6 +68,7 @@ riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_C) := $(riscv-march-y)c riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBA) := $(riscv-march-y)_zba riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBB) := $(riscv-march-y)_zbb +riscv-march-$(CONFIG_PLATFORM_SUPPORTS_RISCV_ISA_ZBC) := $(riscv-march-y)_zbc ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC KBUILD_CFLAGS += -Wa,-misa-spec=2.2 -- 2.44.0