From patchwork Tue Feb 28 11:33:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13154801 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 257B1C7EE32 for ; Tue, 28 Feb 2023 11:33:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231523AbjB1Lda (ORCPT ); Tue, 28 Feb 2023 06:33:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231613AbjB1Ld2 (ORCPT ); Tue, 28 Feb 2023 06:33:28 -0500 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04246113F6; Tue, 28 Feb 2023 03:33:28 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 701A25C0271; Tue, 28 Feb 2023 06:33:27 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 28 Feb 2023 06:33:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1677584007; x=1677670407; bh=L9 nai6+cQcojdRxjq91COMK8Hap2EIINX0BDdi7jny8=; b=BJn8Jm/nPC8mXLQ2PJ zmZWfy2T4G8MrRbpWUXVcRjyKepXczKJOUuGqX81Z0c9r1K0WTWTV96nYH2Po4Wl LLvVLGCjMGYd/g6ykkOJgBmk52apHA/k4gY37TB5il2JkbeZ06awBTdQY9IB2/od JZuBcuc4AUZ6+A74qt+CSgpFQZURdTaBBDZwQaeYxW05E69SxzGKUN/WIEB+7TRi QSdMWOaEcI1pGiXXj+8xUg1GOLsK+P5PMJMTp/0rPhMU7TiU+7HaYAcBJWjlfG9O faKnywzfHeciYk7tBYFEMYPMk9Ol1mBjW2a5J+oVvVSpUN57vdJqJiV5Pi20fsEN DGaw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1677584007; x=1677670407; bh=L9nai6+cQcojd Rxjq91COMK8Hap2EIINX0BDdi7jny8=; b=oLSQzi6bDpi62vN0jJ+VQBmr6WOeQ D8Waj3XxgwyzcNiguNgt9YIub0vfFYIIw9zvmm4TIXY+kyTIlxXWfJDC+XA7NfHk DEpyB6aSp9CaMaL4ruLslLQYQ1sG4Yni/weBZWLrcwJMpcfoFXKOp6tUoG77L6qw PjVxHA7AUtSFN+6ZR6qn+7epKQOGzuK20KHqSeE6nvLbCmvpeKK6XobApWDO7B0u 930eP0CwIiM49RvrtjOkjM9JlApfAvpWjs6X6rpNrbGFwqrnfTvLGoW3XMSWkPsJ /4VwyFjMy7bdtMq5Y246oJRCaqqVJ8zmvirrwKF/N961sv8DSIdiEG+yA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudelvddgvdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpeflihgrgihunhcujggrnhhguceojhhirgiguhhnrdihrghn ghesfhhlhihgohgrthdrtghomheqnecuggftrfgrthhtvghrnhepfeeludefheegvdeuvd dvgeekgfdvtdettdelieeihfegtedugeekhfdvhfejfedtnecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomhepjhhirgiguhhnrdihrghnghesfhhlhi hgohgrthdrtghomh X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 28 Feb 2023 06:33:25 -0500 (EST) From: Jiaxun Yang To: linux-mips@vger.kernel.org Cc: linux-kernel@vger.kernel.org, tsbogend@alpha.franken.de, johan.almbladh@anyfinetworks.com, paulburton@kernel.org, bpf@vger.kernel.org, Jiaxun Yang Subject: [PATCH v2 1/2] MIPS: ebpf jit: Implement DADDI workarounds Date: Tue, 28 Feb 2023 11:33:04 +0000 Message-Id: <20230228113305.83751-2-jiaxun.yang@flygoat.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230228113305.83751-1-jiaxun.yang@flygoat.com> References: <20230228113305.83751-1-jiaxun.yang@flygoat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org For DADDI errata we just workaround by disable immediate operation for BPF_ADD / BPF_SUB to avoid generation of DADDIU. All other use cases in JIT won't cause overflow thus they are all safe. Signed-off-by: Jiaxun Yang Reviewed-by: Philippe Mathieu-Daudé Acked-by: Johan Almbladh --- v2: Drop 64BIT ifdef --- arch/mips/Kconfig | 1 - arch/mips/net/bpf_jit_comp.c | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index 37072e15b263..df0910e3895c 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -64,7 +64,6 @@ config MIPS select HAVE_DMA_CONTIGUOUS select HAVE_DYNAMIC_FTRACE select HAVE_EBPF_JIT if !CPU_MICROMIPS && \ - !CPU_DADDI_WORKAROUNDS && \ !CPU_R4000_WORKAROUNDS && \ !CPU_R4400_WORKAROUNDS select HAVE_EXIT_THREAD diff --git a/arch/mips/net/bpf_jit_comp.c b/arch/mips/net/bpf_jit_comp.c index b17130d510d4..a40d926b6513 100644 --- a/arch/mips/net/bpf_jit_comp.c +++ b/arch/mips/net/bpf_jit_comp.c @@ -218,9 +218,13 @@ bool valid_alu_i(u8 op, s32 imm) /* All legal eBPF values are valid */ return true; case BPF_ADD: + if (IS_ENABLED(CONFIG_CPU_DADDI_WORKAROUNDS)) + return false; /* imm must be 16 bits */ return imm >= -0x8000 && imm <= 0x7fff; case BPF_SUB: + if (IS_ENABLED(CONFIG_CPU_DADDI_WORKAROUNDS)) + return false; /* -imm must be 16 bits */ return imm >= -0x7fff && imm <= 0x8000; case BPF_AND: From patchwork Tue Feb 28 11:33:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13154802 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CF0DC7EE2E for ; Tue, 28 Feb 2023 11:33:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231506AbjB1Ldb (ORCPT ); Tue, 28 Feb 2023 06:33:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231655AbjB1Lda (ORCPT ); Tue, 28 Feb 2023 06:33:30 -0500 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A38D71258C; Tue, 28 Feb 2023 03:33:29 -0800 (PST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 1C5C45C025F; Tue, 28 Feb 2023 06:33:29 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Tue, 28 Feb 2023 06:33:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1677584009; x= 1677670409; bh=s1U2xDkTTCN+09FeGuSytsW4DsGUYbTluserdVVYkL0=; b=J S7YjqqjMr5YgOe7UtXy8AYNH+zm89iNhMdF6uPFa8c9rIKZlr6D/skWvcihdrqMe MVhN0N2QaLOBXxH4KT4QjJj8LNWhiVG+uDDcywbamrTEqWDYBWXMtIN8ePVfrKBJ RxD+ongbdhHsSZGVyoOqUWGN0lQE43KBSMKmVfOnKb3hJxnfEUa8gF0/EvhGqytW gtoC64rbAF/wJS1Q0KEHke8P1/I47xOmDnPYFV27B/ojaLYNqgHioIOGObIIdK4G kglckQXTexicuD0XWW7l2h3+4Uhvir00s3eAwfRHEIcpuYhlhJNz85UzGcQcfJ8e 263Et7WkJFqxuPpF5AZOA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1677584009; x= 1677670409; bh=s1U2xDkTTCN+09FeGuSytsW4DsGUYbTluserdVVYkL0=; b=O hBAtIle8nroeuEsPTrbLwMP8z3HG5ocOzwb2qZplI+Lynz5MvQfpXC/jHw4OdEi/ 2Nmf1GtIZ355lGVOjJiVOMNIh6aNCwDKwkejQrUw+VL2bAyOlFPFI+S4YYKtMKDJ sT0K5bLHUBIcW6I2UgAs2D7OiWbvLzwWw/Zj9cJ5Bgoh2BQ9ZoUQyPu7ZGOYRKgz qp3dpWGBKeJND9dbwp0KYSs+ug5IvOZxUIEu9Q1HIZKdrG8WxkhzkX1Asstmf6UP twtDilJzeFO6Mm0cGvZyySQ9Jniu+cuaKW8tylBFtBz9J0Fbi4KUOm1Ro3S/yDNs Sszeqsvwca9U303gLFX/g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudelvddgvdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhggtgfgsehtkeertdertdejnecuhfhrohhmpeflihgr gihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomheqne cuggftrfgrthhtvghrnhepveeftdffkeejfeffjedtuddvudejfedvjeeluedtueefffef tdeuvedvudevjeffnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepjhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomh X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 28 Feb 2023 06:33:27 -0500 (EST) From: Jiaxun Yang To: linux-mips@vger.kernel.org Cc: linux-kernel@vger.kernel.org, tsbogend@alpha.franken.de, johan.almbladh@anyfinetworks.com, paulburton@kernel.org, bpf@vger.kernel.org, Jiaxun Yang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PATCH v2 2/2] MIPS: ebpf jit: Implement R4000 workarounds Date: Tue, 28 Feb 2023 11:33:05 +0000 Message-Id: <20230228113305.83751-3-jiaxun.yang@flygoat.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20230228113305.83751-1-jiaxun.yang@flygoat.com> References: <20230228113305.83751-1-jiaxun.yang@flygoat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org For R4000 erratas around multiplication and division instructions, as our use of those instructions are always followed by mflo/mfhi instructions, the only issue we need care is "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0" Errata 28: "A double-word or a variable shift may give an incorrect result if executed while an integer multiplication is in progress." We just emit a mfhi $0 to ensure the operation is completed after every multiplication instruction according to workaround suggestion in the document. Signed-off-by: Jiaxun Yang Reviewed-by: Philippe Mathieu-Daudé Acked-by: Johan Almbladh --- v2: Drop 32bit part --- arch/mips/Kconfig | 4 +--- arch/mips/net/bpf_jit_comp64.c | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index df0910e3895c..5ea07c833c5b 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -63,9 +63,7 @@ config MIPS select HAVE_DEBUG_STACKOVERFLOW select HAVE_DMA_CONTIGUOUS select HAVE_DYNAMIC_FTRACE - select HAVE_EBPF_JIT if !CPU_MICROMIPS && \ - !CPU_R4000_WORKAROUNDS && \ - !CPU_R4400_WORKAROUNDS + select HAVE_EBPF_JIT if !CPU_MICROMIPS select HAVE_EXIT_THREAD select HAVE_FAST_GUP select HAVE_FTRACE_MCOUNT_RECORD diff --git a/arch/mips/net/bpf_jit_comp64.c b/arch/mips/net/bpf_jit_comp64.c index 0e7c1bdcf914..fa7e9aa37f49 100644 --- a/arch/mips/net/bpf_jit_comp64.c +++ b/arch/mips/net/bpf_jit_comp64.c @@ -228,6 +228,9 @@ static void emit_alu_r64(struct jit_context *ctx, u8 dst, u8 src, u8 op) } else { emit(ctx, dmultu, dst, src); emit(ctx, mflo, dst); + /* Ensure multiplication is completed */ + if (IS_ENABLED(CONFIG_CPU_R4000_WORKAROUNDS)) + emit(ctx, mfhi, MIPS_R_ZERO); } break; /* dst = dst / src */