From patchwork Sun Nov 12 06:14:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 164206 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp561949vqg; Sat, 11 Nov 2023 22:18:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IGR6VjUhbRNM+wSIqjogQ1hPD6AErzJwyJVhm2lQcW9mBb/4XUa6gRZ/l4NCSlKgVO2wGVb X-Received: by 2002:a05:6808:199:b0:3a9:bb08:d468 with SMTP id w25-20020a056808019900b003a9bb08d468mr4755420oic.55.1699769910093; Sat, 11 Nov 2023 22:18:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699769910; cv=none; d=google.com; s=arc-20160816; b=z4XYg+cY7bM4sur7DBZubN+Wz60yHPOP1a6dEIXupk4ffbg/7JgiFMxTyfgdWdfYRm CzLqxL9cM4kV2m1YvJNGn5IQm9L8UZGADMQdrwu68Dlay6cqhtklrPSZTNa3YEefPuAA i5FoAHMKaeCOLrXgZoQgWGeykc9thN7HTglTbApgKq+Sz8U3O91B/+YXh78RRsmeZsiv HQNuO3cykv6RH/xhaYQcCG7ZKLD2op0RIfsNGo6Inyv4IMD5GUjDPLPIR0IyEUrs+Gxg tV8TBX9G+iXZZbuMwT4Vr32n3IE5GgpvZZJlJDBrU99F0Wd+igJu5FpdL5HwofPK/SBX 7low== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+E7poaL3WU9jGiKm2R7RnPWvBSQmVAofvYf2kbGpe5s=; fh=ZE/z2dNArDjRCaYXLY1qiMuWjPgjymC0plQjRd9hozE=; b=dOnr9S8ZwrldSghC1ZrwvYhb8016Gk8S3vJc2T53yYJBClcHHYUDJNIKMa0NNPIFpm SKhmLYf3tAqCNpxMhteQ75UdTzHao9J2wsB3BgmzhA0yQc0PjSKPB3hEKk5RTB/K9Ctp /szt84VV7qndTyq9l8bLl9IRXYmb1meNjPKpEfn9lzzY8ZDsfRE6+g4Ck5NH7LfeLQig +mPUikF83nmXbAmsDsQl26VA0/tahEwSMTgC17+rI4d6nFJcRxON8PEN5nq/hLy4mA9s MK1SGEdN0moJslFUb9X6vgawmkRQripfW0hgTCK0tbrMhnqt1bBVQ32vdsjghLNEv+bC 6wYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uXWH+71B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id 28-20020a17090a035c00b00274274bf0ecsi3284831pjf.61.2023.11.11.22.18.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Nov 2023 22:18:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uXWH+71B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 9BE9B8048C06; Sat, 11 Nov 2023 22:18:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231356AbjKLGR4 (ORCPT + 29 others); Sun, 12 Nov 2023 01:17:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230242AbjKLGRl (ORCPT ); Sun, 12 Nov 2023 01:17:41 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A356947B6 for ; Sat, 11 Nov 2023 22:17:17 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2DD9C433D9; Sun, 12 Nov 2023 06:17:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699769837; bh=yJ53jomTLG+j+rzKLDFglTmPOzUq4xATJqhV03Y8NDA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uXWH+71BlkB0gLhz3M2X15BE4B4oEYB9gyycQqZ8+FdLYqMz3funNQkzHc0Dy9XBp 8ObE/BWmXibABF2C3xM83Jafy7ZAcI0Mt/kEddZ5fp3qHw4s8Sm5JNY7WKFOnwlTHF XebaLVFboE5rnhqBdO5/ZdqxwmPOogqsgCllKNUnGJo0WlEBkq4RTDjX8YLafHMWJ5 5PqFLGR5t8hI3HrTmU+l0D0GDKxB0il/JGfS2b455jexb153+6vOha/HJiAAaVRPMD JUj6goF6Ow1Gm47Z17xP/gMVRHN6sFy0NoVDBX0XwqO3xDgrIkSCjn1gSZSqBbhqhi fdcFURboW9taw== From: guoren@kernel.org To: arnd@arndb.de, guoren@kernel.org, palmer@rivosinc.com, tglx@linutronix.de, conor.dooley@microchip.com, heiko@sntech.de, apatel@ventanamicro.com, atishp@atishpatra.org, bjorn@kernel.org, paul.walmsley@sifive.com, anup@brainfault.org, jiawei@iscas.ac.cn, liweiwei@iscas.ac.cn, wefu@redhat.com, U2FsdGVkX1@gmail.com, wangjunqiang@iscas.ac.cn, kito.cheng@sifive.com, andy.chiu@sifive.com, vincent.chen@sifive.com, greentime.hu@sifive.com, wuwei2016@iscas.ac.cn, jrtc27@jrtc27.com, luto@kernel.org, fweimer@redhat.com, catalin.marinas@arm.com, hjl.tools@gmail.com Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Guo Ren Subject: [RFC PATCH V2 18/38] riscv: s64ilp32: Add ebpf jit support Date: Sun, 12 Nov 2023 01:14:54 -0500 Message-Id: <20231112061514.2306187-19-guoren@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20231112061514.2306187-1-guoren@kernel.org> References: <20231112061514.2306187-1-guoren@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sat, 11 Nov 2023 22:18:25 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782337932909617654 X-GMAIL-MSGID: 1782337932909617654 From: Guo Ren The s64ilp32 uses the rv64 ISA instruction set, not the rv32 ISA. So bpf_jit_comp32.c can't be used for s64ilp32, and we use bpf_jit_comp64.c instead. This patch makes s64ilp32 ebpf jit correct and improves the performance because bpf_jit_comp32.c has significant gaps in mapping ebpf 64-bit ISA. Signed-off-by: Guo Ren Signed-off-by: Guo Ren --- arch/riscv/include/asm/extable.h | 2 +- arch/riscv/net/Makefile | 6 +++--- arch/riscv/net/bpf_jit_comp64.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/riscv/include/asm/extable.h b/arch/riscv/include/asm/extable.h index 3eb5c1f7bf34..7e22bb520309 100644 --- a/arch/riscv/include/asm/extable.h +++ b/arch/riscv/include/asm/extable.h @@ -38,7 +38,7 @@ bool fixup_exception(struct pt_regs *regs); static inline bool fixup_exception(struct pt_regs *regs) { return false; } #endif -#if defined(CONFIG_BPF_JIT) && defined(CONFIG_ARCH_RV64I) +#if defined(CONFIG_BPF_JIT) && !defined(CONFIG_ARCH_RV32I) bool ex_handler_bpf(const struct exception_table_entry *ex, struct pt_regs *regs); #else static inline bool diff --git a/arch/riscv/net/Makefile b/arch/riscv/net/Makefile index 9a1e5f0a94e5..907edce21acc 100644 --- a/arch/riscv/net/Makefile +++ b/arch/riscv/net/Makefile @@ -2,8 +2,8 @@ obj-$(CONFIG_BPF_JIT) += bpf_jit_core.o -ifeq ($(CONFIG_ARCH_RV64I),y) - obj-$(CONFIG_BPF_JIT) += bpf_jit_comp64.o -else +ifeq ($(CONFIG_ARCH_RV32I),y) obj-$(CONFIG_BPF_JIT) += bpf_jit_comp32.o +else + obj-$(CONFIG_BPF_JIT) += bpf_jit_comp64.o endif diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c index c648864c8cd1..ec0b7fb6982b 100644 --- a/arch/riscv/net/bpf_jit_comp64.c +++ b/arch/riscv/net/bpf_jit_comp64.c @@ -126,7 +126,7 @@ static u8 rv_tail_call_reg(struct rv_jit_context *ctx) static bool is_32b_int(s64 val) { - return -(1L << 31) <= val && val < (1L << 31); + return -(1LL << 31) <= val && val < (1LL << 31); } static bool in_auipc_jalr_range(s64 val) @@ -135,8 +135,8 @@ static bool in_auipc_jalr_range(s64 val) * auipc+jalr can reach any signed PC-relative offset in the range * [-2^31 - 2^11, 2^31 - 2^11). */ - return (-(1L << 31) - (1L << 11)) <= val && - val < ((1L << 31) - (1L << 11)); + return (-(1LL << 31) - (1LL << 11)) <= val && + val < ((1LL << 31) - (1LL << 11)); } /* Emit fixed-length instructions for address */