1caab277bSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 29732cafdSJiang Liu /* 39732cafdSJiang Liu * Copyright (C) 2013 Huawei Ltd. 49732cafdSJiang Liu * Author: Jiang Liu <liuj97@gmail.com> 59732cafdSJiang Liu * 69732cafdSJiang Liu * Based on arch/arm/include/asm/jump_label.h 79732cafdSJiang Liu */ 89732cafdSJiang Liu #ifndef __ASM_JUMP_LABEL_H 99732cafdSJiang Liu #define __ASM_JUMP_LABEL_H 1055dd0df7SAnton Blanchard 1155dd0df7SAnton Blanchard #ifndef __ASSEMBLY__ 1255dd0df7SAnton Blanchard 139732cafdSJiang Liu #include <linux/types.h> 149732cafdSJiang Liu #include <asm/insn.h> 159732cafdSJiang Liu 16*cfb00a35SWill Deacon #define HAVE_JUMP_LABEL_BATCH 179732cafdSJiang Liu #define JUMP_LABEL_NOP_SIZE AARCH64_INSN_SIZE 189732cafdSJiang Liu 19588de8c6SGeorge Guo #define JUMP_TABLE_ENTRY(key, label) \ 20588de8c6SGeorge Guo ".pushsection __jump_table, \"aw\"\n\t" \ 21588de8c6SGeorge Guo ".align 3\n\t" \ 22588de8c6SGeorge Guo ".long 1b - ., %l["#label"] - .\n\t" \ 23588de8c6SGeorge Guo ".quad %c0 - .\n\t" \ 24588de8c6SGeorge Guo ".popsection\n\t" \ 25588de8c6SGeorge Guo : : "i"(key) : : label 26588de8c6SGeorge Guo arch_static_branch(struct static_key * const key,const bool branch)27efbc9578SJisheng Zhangstatic __always_inline bool arch_static_branch(struct static_key * const key, 28efbc9578SJisheng Zhang const bool branch) 299732cafdSJiang Liu { 30588de8c6SGeorge Guo char *k = &((char *)key)[branch]; 31588de8c6SGeorge Guo 324356e9f8SLinus Torvalds asm goto( 33c296146cSArd Biesheuvel "1: nop \n\t" 34588de8c6SGeorge Guo JUMP_TABLE_ENTRY(k, l_yes) 35588de8c6SGeorge Guo ); 3611276d53SPeter Zijlstra 3711276d53SPeter Zijlstra return false; 3811276d53SPeter Zijlstra l_yes: 3911276d53SPeter Zijlstra return true; 4011276d53SPeter Zijlstra } 4111276d53SPeter Zijlstra arch_static_branch_jump(struct static_key * const key,const bool branch)42efbc9578SJisheng Zhangstatic __always_inline bool arch_static_branch_jump(struct static_key * const key, 43efbc9578SJisheng Zhang const bool branch) 4411276d53SPeter Zijlstra { 45588de8c6SGeorge Guo char *k = &((char *)key)[branch]; 464356e9f8SLinus Torvalds asm goto( 47c296146cSArd Biesheuvel "1: b %l[l_yes] \n\t" 48588de8c6SGeorge Guo JUMP_TABLE_ENTRY(k, l_yes) 49588de8c6SGeorge Guo ); 509732cafdSJiang Liu return false; 519732cafdSJiang Liu l_yes: 529732cafdSJiang Liu return true; 539732cafdSJiang Liu } 549732cafdSJiang Liu 5555dd0df7SAnton Blanchard #endif /* __ASSEMBLY__ */ 569732cafdSJiang Liu #endif /* __ASM_JUMP_LABEL_H */ 57