#ifndef _ASM_X86_JUMP_LABEL_H
#define _ASM_X86_JUMP_LABEL_H

#ifdef __KERNEL__

#include <linux/types.h>
#include <asm/nops.h>

#define JUMP_LABEL_NOP_SIZE 5

# define JUMP_LABEL_INITIAL_NOP ".byte 0xe9 \n\t .long 0\n\t"

# define JUMP_LABEL(key, label)					\
	do {							\
		asm goto("1:"					\
			JUMP_LABEL_INITIAL_NOP			\
			".pushsection __jump_table,  \"a\" \n\t"\
			_ASM_PTR "1b, %l[" #label "], %c0 \n\t" \
			".popsection \n\t"			\
			: :  "i" (key) :  : label);		\
	} while (0)

#endif /* __KERNEL__ */

#ifdef CONFIG_X86_64
typedef u64 jump_label_t;
#else
typedef u32 jump_label_t;
#endif

struct jump_entry {
	jump_label_t code;
	jump_label_t target;
	jump_label_t key;
};

#endif

#ifndef _ASM_X86_JUMP_LABEL_H
#define _ASM_X86_JUMP_LABEL_H

#ifdef __KERNEL__

#include <linux/types.h>
#include <asm/nops.h>

#define JUMP_LABEL_NOP_SIZE 5

# define JUMP_LABEL_INITIAL_NOP ".byte 0xe9 \n\t .long 0\n\t"

# define JUMP_LABEL(key, label)					\
	do {							\
		asm goto("1:"					\
			JUMP_LABEL_INITIAL_NOP			\
			".pushsection __jump_table,  \"aw\" \n\t"\
			_ASM_PTR "1b, %l[" #label "], %c0 \n\t" \
			".popsection \n\t"			\
			: :  "i" (key) :  : label);		\
	} while (0)

#endif /* __KERNEL__ */

#ifdef CONFIG_X86_64
typedef u64 jump_label_t;
#else
typedef u32 jump_label_t;
#endif

struct jump_entry {
	jump_label_t code;
	jump_label_t target;
	jump_label_t key;
};

#endif

Fix jump label with RO/NX module protection crash
x86: Fix jump label with RO/NX module protection crash

If we use jump table in module init, there are marked
as removed in __jump_table section after init is done.

But we already applied ro permissions on the module, so
we can't modify a read only section (crash in
remove_jump_label_module_init).

Make the __jump_table section rw.

Signed-off-by: Matthieu CASTET <2b6a54c52e56976a5646892b66a1a13421db0d2c@free.fr>
Cc: Xiaotian Feng <ac8085f9c424e98c8fe0d0e67b1c7a8a00757580@gmail.com>
Cc: Jason Baron <af9bd1db766a43cb09b647251c97dbddcd2e59dc@redhat.com>
Cc: Steven Rostedt <43232e92d70cc7aa53504ad0397085ee47bad87f@goodmis.org>
Cc: Frederic Weisbecker <e8a1bf9163cb25e93cfd6540f223b3872ea7ee55@gmail.com>
Cc: Peter Zijlstra <645ca7d3a8d3d4f60557176cd361ea8351edc32b@chello.nl>
Cc: Arjan van de Ven <9043bf4b08f6c93a2cb55d98c3494b123858348f@linux.intel.com>
Cc: Siarhei Liakh <04848bc4c6728e62385922426cceead13c9e9458@gmail.com>
Cc: Xuxian Jiang <4e7b08952acae50abec9e06cac9ae2c424c73473@cs.ncsu.edu>
Cc: James Morris <10d11de3abc355eabe955bb734f0f8e71da56e16@namei.org>
Cc: Rusty Russell <df9728c9e5104131c08c7adb03af425394842596@rustcorp.com.au>
Cc: Dave Jones <d5ec0d24602845f6f4b6a35ef729998d1fba5507@redhat.com>
Cc: Kees Cook <e9b0cc8b545b1477b7cee8fbfcd6abb9c2d70cb5@canonical.com>
Cc: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>
Cc: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org>
LKML-Reference: <839f467c9c1c781060a2c104d5ccbd3605c01c1a@free.fr>
Signed-off-by: Ingo Molnar <9dbbbf0688fedc85ad4da37637f1a64b8c718ee2@elte.hu>
