Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2177675lqo; Mon, 13 May 2024 09:53:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVTbieRcPgfV2ygN5l7LO/uYe5/vBvKwt8b/LPdpI6vw+EY8GjOMC/2jOl7/mg8CPZoEDBljLGGwTwXUfecob2iOIn69XPo8kRwM+Q5Vw== X-Google-Smtp-Source: AGHT+IHuUQ35uEJLdlR62JVIpLD2g+ILqQrz6CavSYJA9l5ClwB/qiksXDINjZSCNnZQDrY5aVRI X-Received: by 2002:a05:6a20:9782:b0:1a9:4055:6dce with SMTP id adf61e73a8af0-1afde1c5d3fmr7696040637.58.1715619230828; Mon, 13 May 2024 09:53:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715619230; cv=pass; d=google.com; s=arc-20160816; b=dqQ7rX5aCQn7vrWkQcY2i/DYdCMhkEFagZJwgS5F9es1SISMZLbRqKR883z3720ljT iRVYyEBGBuHe9tknED0KmtmgBXxFqTu5DYVBgfQX/BzISJdnJheLSDZvBRMAqOEVbkig jAJB3oNviAmWV54m0qRlMoiuPyxNkOFJonzWRNFUs9W8WVKaGHhyfvggwaANnjKzg7sP 4NzGI5H2HQr3MAbTgDB73zCrY/+GD0QaXR0eYjw1ptfA1wGm8ZLkfxWFOKzYqlnyvWIR yOWI7umHar+2s//sOsBIKUJZBQ4RnfqNsLcDDOigKy8+Me9+Y3UOE1QLvuNwzpKI1zVL 38Sw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=1oBPAF2w8fZVPm8NSdnQib33iYXIwPTD6vxiqg/Fetg=; fh=K6o0KyJAhrP94oeuSmmro4/hvsF13bXLZ1cW1KPeYT8=; b=ze9+nZYRtENLSRZn1pZt/IGS6fVZcb2SdlFvceO86tp8KaZbQlT0fFyPrusO2h/PVz EVNfka0fLhr1bQ29owbyO/C99ZKwEpiAzkS7WvVnF9RKNYQSyS+j2YITcr5j0fbFDxDh zsggjtB7/RMEo0IazMaAlabAXNgZ4uF/VvVg3m1wy8y2KhB5vfrswZQ7IziiJBQNV76k CtuS094s+qt4E6np1WvpxrMnymaMuGLEYeUypUiHXwd7Mg5ohwA2A97wbloq64v7UowM xx0BTHkSSk+QlPpwa7KoGKQQ+BX97cTN07mOTv9ytMQaxB3ulG5Fi6SPCAqHaC1Qtsjn xrXQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=SNNKkRaY; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-177856-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177856-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-63409e82660si9494808a12.1.2024.05.13.09.53.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 09:53:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177856-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=SNNKkRaY; arc=pass (i=1 spf=pass spfdomain=ventanamicro.com dkim=pass dkdomain=ventanamicro.com); spf=pass (google.com: domain of linux-kernel+bounces-177856-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177856-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 8EA08B20A61 for ; Mon, 13 May 2024 16:53:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B70AD18E2A; Mon, 13 May 2024 16:53:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="SNNKkRaY" Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 247DE1BF2A for ; Mon, 13 May 2024 16:53:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715619211; cv=none; b=k6QfrlTGSLpbLBvMGZFEmihKCzb4HM+EE8WXjhkeTym7m/eZKTxsUvdboTDkdluE2ttQbvp7cHcHt4Ib0WW6TOgU9IDE1JIwFfHCmsQI/3SimzqPktU4b8926Qg0VRF0I/tS6gIJl7vt1++rpmMmc+P4CS0OIhX8oYdQ0dilDbY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715619211; c=relaxed/simple; bh=tYn3826eEKH6f1tndWzHmG2prJ0t5GbyHtUGkIAnuMI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AvO/Hd5FPutv9oNVdcyFd3igCOYWs32y/RY0WXO3/sXickVGEuRgSAaHJqD7qUifoGm3Bi6wkvfb5LtFOQexCLif+RbvEfwadgNbeN62/UMfl0tSBOHdoGWO7NfUiKCpvLnrRuHGW4hJWnQEL+swlJe6wKsjFHp6S8nOIdgCD0Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=SNNKkRaY; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a59ad344f7dso943397566b.0 for ; Mon, 13 May 2024 09:53:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1715619208; x=1716224008; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=1oBPAF2w8fZVPm8NSdnQib33iYXIwPTD6vxiqg/Fetg=; b=SNNKkRaYQuij4To8x+gJc4DMrcnqbzUS7gXbORoJyHuIp8AWlISFOmdRlKYqFA60mF c8yZkPhgmsLykqJBnl/znaz7/5H9gxteZrHY46xIJHhwj5jUjzAKU02HTmrJxRs3UQFO mnllTA2n/pZ7bzdfysfyuNg8UwwX5JlbKoX63FPM+kXbU+6r+TJ98S9cdwfVz/6br1SO dy7VIx5cbUDlRWDMM8HoVKL+0GExvFa4LE6XoqNS0MPpk29MyFSIf8V6EtDKn/Obcp44 qjJdbGb7o3zMK9Q9t2Sdw0WXcS6ju2QcuH9OrltssXJcSiZjVHVHaIMvdptVJ1lfaCgE sWhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715619208; x=1716224008; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=1oBPAF2w8fZVPm8NSdnQib33iYXIwPTD6vxiqg/Fetg=; b=hxehmvyRpadLyvS+7aQhJ6A7CGRhf/Xvsx6DhBY7jmGtTGf2MtabUu+TatTIosJasB NIHp/CDbrGuLoYvkh2PDus8k0kCiNlGKKHl17poa8v6TtMnrAx1W4XsRuYbuU90d9P/O OU3CQ9rJuwfa7gr598uaT07Yyw/5PAMPyQ6R8X+VX2eTnvfT73T052kY4uz+kPS/UQaJ wzSKJyhHj9ktBSfpkOj6lcuRDI2Dpg8NIKfvpufVH5iMuB0NqiH93JYuG2rbLlyGhx90 XANOpULQcdr+syymM72rn3/AzoIqqcWmm/iAHVDkbNmfv4F+9gkbFdjvxANSwkDvBVbh 3t1Q== X-Forwarded-Encrypted: i=1; AJvYcCXYD5mjxYFhE9xrb3dS4F6kZ146icavFaXbKTMZa7vd0k7M/uQYwPYs2SciIDIQ1Dk1ScM4JJSnj3kr91vQO4Ury1t1Ya4l6/DaZAWd X-Gm-Message-State: AOJu0Yx7oSfQCrjCNrsiZWu7K4UpYmxszW0lwNidaNeaIbqXN4WSGwVX RkLSLno+SA64FOI85MGDN3wLaNCPFUxWw+ChMw0rSfkl+UJwUNSflRkesSHFAK4= X-Received: by 2002:a50:d596:0:b0:572:d4fc:cc3 with SMTP id 4fb4d7f45d1cf-5734d5974d0mr7375118a12.2.1715619208429; Mon, 13 May 2024 09:53:28 -0700 (PDT) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5733c2c7d79sm6427800a12.59.2024.05.13.09.53.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 09:53:27 -0700 (PDT) Date: Mon, 13 May 2024 18:53:26 +0200 From: Andrew Jones To: Xiao Wang Cc: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, luke.r.nels@gmail.com, xi.wang@gmail.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, pulehui@huawei.com, haicheng.li@intel.com, conor@kernel.org Subject: Re: [PATCH v2] riscv, bpf: Optimize zextw insn with Zba extension Message-ID: <20240513-5c6f04fb4a29963c63d09aa2@orel> References: <20240511023436.3282285-1-xiao.w.wang@intel.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20240511023436.3282285-1-xiao.w.wang@intel.com> On Sat, May 11, 2024 at 10:34:36AM GMT, Xiao Wang wrote: > The Zba extension provides add.uw insn which can be used to implement > zext.w with rs2 set as ZERO. > > Signed-off-by: Xiao Wang > --- > v2: > * Add Zba description in the Kconfig. (Lehui) > * Reword the Kconfig help message to make it clearer. (Conor) > --- > arch/riscv/Kconfig | 22 ++++++++++++++++++++++ > arch/riscv/net/bpf_jit.h | 18 ++++++++++++++++++ > 2 files changed, 40 insertions(+) > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > index 6bec1bce6586..e262a8668b41 100644 > --- a/arch/riscv/Kconfig > +++ b/arch/riscv/Kconfig > @@ -586,6 +586,14 @@ config RISCV_ISA_V_PREEMPTIVE > preemption. Enabling this config will result in higher memory > consumption due to the allocation of per-task's kernel Vector context. > > +config TOOLCHAIN_HAS_ZBA > + bool > + default y > + depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zba) > + depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zba) > + depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900 > + depends on AS_HAS_OPTION_ARCH > + > config TOOLCHAIN_HAS_ZBB > bool > default y > @@ -601,6 +609,20 @@ config TOOLCHAIN_HAS_VECTOR_CRYPTO > def_bool $(as-instr, .option arch$(comma) +v$(comma) +zvkb) > depends on AS_HAS_OPTION_ARCH > > +config RISCV_ISA_ZBA > + bool "Zba extension support for bit manipulation instructions" > + depends on TOOLCHAIN_HAS_ZBA We handcraft the instruction, so why do we need toolchain support? > + depends on RISCV_ALTERNATIVE Also, while riscv_has_extension_likely() will be accelerated with RISCV_ALTERNATIVE, it's not required. > + default y > + help > + Add support for enabling optimisations in the kernel when the Zba > + extension is detected at boot. > + > + The Zba extension provides instructions to accelerate the generation > + of addresses that index into arrays of basic data types. > + > + If you don't know what to do here, say Y. > + > config RISCV_ISA_ZBB > bool "Zbb extension support for bit manipulation instructions" > depends on TOOLCHAIN_HAS_ZBB > diff --git a/arch/riscv/net/bpf_jit.h b/arch/riscv/net/bpf_jit.h > index f4b6b3b9edda..18a7885ba95e 100644 > --- a/arch/riscv/net/bpf_jit.h > +++ b/arch/riscv/net/bpf_jit.h > @@ -18,6 +18,11 @@ static inline bool rvc_enabled(void) > return IS_ENABLED(CONFIG_RISCV_ISA_C); > } > > +static inline bool rvzba_enabled(void) > +{ > + return IS_ENABLED(CONFIG_RISCV_ISA_ZBA) && riscv_has_extension_likely(RISCV_ISA_EXT_ZBA); > +} > + > static inline bool rvzbb_enabled(void) > { > return IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && riscv_has_extension_likely(RISCV_ISA_EXT_ZBB); > @@ -937,6 +942,14 @@ static inline u16 rvc_sdsp(u32 imm9, u8 rs2) > return rv_css_insn(0x7, imm, rs2, 0x2); > } > > +/* RV64-only ZBA instructions. */ > + > +static inline u32 rvzba_zextw(u8 rd, u8 rs1) > +{ > + /* add.uw rd, rs1, ZERO */ > + return rv_r_insn(0x04, RV_REG_ZERO, rs1, 0, rd, 0x3b); > +} > + > #endif /* __riscv_xlen == 64 */ > > /* Helper functions that emit RVC instructions when possible. */ > @@ -1159,6 +1172,11 @@ static inline void emit_zexth(u8 rd, u8 rs, struct rv_jit_context *ctx) > > static inline void emit_zextw(u8 rd, u8 rs, struct rv_jit_context *ctx) > { > + if (rvzba_enabled()) { > + emit(rvzba_zextw(rd, rs), ctx); > + return; > + } > + > emit_slli(rd, rs, 32, ctx); > emit_srli(rd, rd, 32, ctx); > } > -- > 2.25.1 > Thanks, drew