Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp12120964rwl; Tue, 3 Jan 2023 09:16:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXtrpCUDX6Zwkl8Z1noHREUZY+OcuXDds15j/IBekGWH06TCwW8Pm+2Il4zmcqGCU2b286N3 X-Received: by 2002:a05:6a20:ba88:b0:ad:eaea:e08 with SMTP id fb8-20020a056a20ba8800b000adeaea0e08mr61214623pzb.25.1672766181068; Tue, 03 Jan 2023 09:16:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672766181; cv=none; d=google.com; s=arc-20160816; b=JkVwvwEhkKm9Uo3xGnHVrmTAhd8D0b8zQxkfW/iQw6Yi/+Q5sLdG5wNxmpPvjgJeGT +UtNfPPEDbkDBCAzUMJwF2Z0qVd4UqP+DMY7PdTJ7cHM9OTbQ4sze/+EhqaIWTVRTsZa oX3BtVEKtMNgx183gPJN8Pezi9lX7NW7htV7U5ly5Zy/jp1/6DnSN4g9sVkqEHxI4il9 6wFwsFogo8HnLUORLpU4QvMx70qeZcoBFGKS0aWquBCTymBSDvLTgvSxWq03aZIA8Dqz q/pG4g1igMy2naW+FyYrhax7LFlnwZoi2qhOrgN2VrUNTIBx4GXBbqf6F+sjhlRdJiZi iYPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature:dkim-filter:secumail-id:dkim-signature; bh=hWWBuzrsrdpx+ArnbnA4/8hkOh+3mFOPx0Kp8+Hw1MU=; b=fuUxsno0IOEJ3PYfd4eUeOVLNV+gjxHWh6zJt+mX+4lrrvVpsfCiqNhT1Fw/qPv7j7 +Oo9Xk4lTZyrOMlsqEHrH0Bub+9ZxV2DGXewLQzDVjneLlY1NdfE94c8vkRCmMgFfCQK 2sC0W264sZVTM6ywilae/VFc35VqzrSNPjepkqxAnTcAZhV2TxwCjxRhisgAUBHpLFkh vuZS25WYy7T9X1aux0tN4LQNLDtwy4YWvJdhGTahvE41PIlaXTSQ9L+7GQ/nTD6H4UQg CZH3hNf4Iau3IKmHmE/QKr8Z9adTzzl7Asm+FULzv034yUv4fI72xm5kEdv+ugKBfO+Q r/Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kalray.eu header.s=sec-sig-email header.b=pJPxLA3f; dkim=neutral (body hash did not verify) header.i=@kalray.eu header.s=32AE1B44-9502-11E5-BA35-3734643DEF29 header.b=N9W8Z0br; 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; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=kalray.eu Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s21-20020a056a00195500b005770e7ca31asi35303023pfk.239.2023.01.03.09.16.12; Tue, 03 Jan 2023 09:16:21 -0800 (PST) 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; dkim=fail header.i=@kalray.eu header.s=sec-sig-email header.b=pJPxLA3f; dkim=neutral (body hash did not verify) header.i=@kalray.eu header.s=32AE1B44-9502-11E5-BA35-3734643DEF29 header.b=N9W8Z0br; 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; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=kalray.eu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238374AbjACRB3 (ORCPT + 60 others); Tue, 3 Jan 2023 12:01:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238251AbjACRAN (ORCPT ); Tue, 3 Jan 2023 12:00:13 -0500 Received: from fx409.security-mail.net (smtpout253.security-mail.net [46.30.205.253]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB2C513D00 for ; Tue, 3 Jan 2023 09:00:06 -0800 (PST) Received: from localhost (fx409.security-mail.net [127.0.0.1]) by fx409.security-mail.net (Postfix) with ESMTP id 6EE36349896 for ; Tue, 3 Jan 2023 17:44:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kalray.eu; s=sec-sig-email; t=1672764274; bh=8Dq9fCIb191loq5TcL6Z1DnQkdWisKkldvRiZGy7tJI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pJPxLA3fM56WG4jDk7E1oLAGSLu9P8CFtA0sNiW1cEXWmnp9mMC0BpYEQIHn7a1So Wovz7Sqe8KoqR0LuPusXjDcqLQDmBszj1q0K5HpcHTUtRkD7p3AC3E9nlNDFzQOD1P xa6cFDSO+57Q5c0baInUgFEc/mzcyRj5y/Qt2pCY= Received: from fx409 (fx409.security-mail.net [127.0.0.1]) by fx409.security-mail.net (Postfix) with ESMTP id 547483498BE; Tue, 3 Jan 2023 17:44:34 +0100 (CET) Received: from zimbra2.kalray.eu (unknown [217.181.231.53]) by fx409.security-mail.net (Postfix) with ESMTPS id 9B40834989B; Tue, 3 Jan 2023 17:44:33 +0100 (CET) Received: from zimbra2.kalray.eu (localhost [127.0.0.1]) by zimbra2.kalray.eu (Postfix) with ESMTPS id 6EDEC27E0402; Tue, 3 Jan 2023 17:44:33 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra2.kalray.eu (Postfix) with ESMTP id 4A19027E03FE; Tue, 3 Jan 2023 17:44:33 +0100 (CET) Received: from zimbra2.kalray.eu ([127.0.0.1]) by localhost (zimbra2.kalray.eu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id WktLtvcDHRf3; Tue, 3 Jan 2023 17:44:33 +0100 (CET) Received: from junon.lin.mbt.kalray.eu (unknown [192.168.37.161]) by zimbra2.kalray.eu (Postfix) with ESMTPSA id 0D88E27E0402; Tue, 3 Jan 2023 17:44:33 +0100 (CET) X-Virus-Scanned: E-securemail Secumail-id: <436b.63b45b71.99905.0> DKIM-Filter: OpenDKIM Filter v2.10.3 zimbra2.kalray.eu 4A19027E03FE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kalray.eu; s=32AE1B44-9502-11E5-BA35-3734643DEF29; t=1672764273; bh=kyynoyCXVrgI1RVIOYOEcIIB8J/4uvzZLXgkFOo6ftM=; h=From:To:Date:Message-Id:MIME-Version; b=N9W8Z0brjAqY8XmtqLIPQmWzyJHMZoWVaX/jLwpvEV0MLJNFFkPY1swABD6sF3eaT vRq8anLByKAy/T82xmvP+9STV9+3Z0XW4bOM1iWFG5DgYULkwrUhGCQoMNQJmoNAb3 KPxm/6HiRSt2ldLShLiVtR1bgf09rGVrZ7ZvxZRU= From: Yann Sionneau Cc: Yann Sionneau , Peter Zijlstra , Josh Poimboeuf , Jason Baron , Steven Rostedt , Ard Biesheuvel , linux-kernel@vger.kernel.org, Clement Leger , Julian Vetter Subject: [RFC PATCH 22/25] kvx: Add support for jump labels Date: Tue, 3 Jan 2023 17:43:56 +0100 Message-ID: <20230103164359.24347-23-ysionneau@kalray.eu> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230103164359.24347-1-ysionneau@kalray.eu> References: <20230103164359.24347-1-ysionneau@kalray.eu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf-8 X-ALTERMIMEV2_out: done X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for jump labels to kvx arch. CC: Peter Zijlstra CC: Josh Poimboeuf CC: Jason Baron CC: Steven Rostedt CC: Ard Biesheuvel CC: linux-kernel@vger.kernel.org Co-developed-by: Clement Leger Signed-off-by: Clement Leger Co-developed-by: Julian Vetter Signed-off-by: Julian Vetter Co-developed-by: Yann Sionneau Signed-off-by: Yann Sionneau --- arch/kvx/include/asm/jump_label.h | 59 +++++++++++++++++++++++++++++++ arch/kvx/kernel/jump_label.c | 34 ++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 arch/kvx/include/asm/jump_label.h create mode 100644 arch/kvx/kernel/jump_label.c diff --git a/arch/kvx/include/asm/jump_label.h b/arch/kvx/include/asm/jump_label.h new file mode 100644 index 000000000000..5becccaad20c --- /dev/null +++ b/arch/kvx/include/asm/jump_label.h @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2017-2023 Kalray Inc. + * Author(s): Clement Leger + */ + +#ifndef _ASM_KVX_JUMP_LABEL_H +#define _ASM_KVX_JUMP_LABEL_H + +#ifndef __ASSEMBLY__ + +#include + +#include + +#define JUMP_LABEL_NOP_SIZE (KVX_INSN_NOP_SIZE * KVX_INSN_SYLLABLE_WIDTH) + +static __always_inline bool arch_static_branch(struct static_key *key, + bool branch) +{ + asm_volatile_goto("1:\n\t" + "nop\n\t" + ";;\n\t" + ".pushsection __jump_table, \"aw\"\n\t" + ".dword 1b, %l[l_yes], %c0\n\t" + ".popsection\n\t" + : : "i" (&((char *)key)[branch]) : : l_yes); + + return false; +l_yes: + return true; +} + +static __always_inline bool arch_static_branch_jump(struct static_key *key, + bool branch) +{ + asm_volatile_goto("1:\n\t" + "goto %l[l_yes]\n\t" + ";;\n\t" + ".pushsection __jump_table, \"aw\"\n\t" + ".dword 1b, %l[l_yes], %c0\n\t" + ".popsection\n\t" + : : "i" (&((char *)key)[branch]) : : l_yes); + + return false; +l_yes: + return true; +} + +typedef u64 jump_label_t; + +struct jump_entry { + jump_label_t code; + jump_label_t target; + jump_label_t key; +}; + +#endif /* __ASSEMBLY__ */ +#endif diff --git a/arch/kvx/kernel/jump_label.c b/arch/kvx/kernel/jump_label.c new file mode 100644 index 000000000000..5a602dbdede0 --- /dev/null +++ b/arch/kvx/kernel/jump_label.c @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2017-2023 Kalray Inc. + * Author(s): Clement Leger + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +void arch_jump_label_transform(struct jump_entry *e, + enum jump_label_type type) +{ + s32 off = (jump_entry_target(e) - jump_entry_code(e)); + u32 insn_code; + u32 *insn_addr = (u32 *) jump_entry_code(e); + + if (type == JUMP_LABEL_JMP) { + BUG_ON(KVX_INSN_GOTO_PCREL27_CHECK(off)); + + KVX_INSN_GOTO(&insn_code, KVX_INSN_PARALLEL_EOB, off); + } else { + KVX_INSN_NOP(&insn_code, KVX_INSN_PARALLEL_EOB); + } + + kvx_insns_write(&insn_code, JUMP_LABEL_NOP_SIZE, insn_addr); +} -- 2.37.2